X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/7cd900d61edbd6d322db3cecb913adf574389320..19dcc94821d1fac803c571b1dc11764213713682:/hotline/transaction_handlers.go diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index c3b8c59..f6fa232 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -10,6 +10,7 @@ import ( "math/big" "os" "path" + "path/filepath" "sort" "strings" "time" @@ -230,6 +231,10 @@ var TransactionHandlers = map[uint16]TransactionType{ Name: "tranUserBroadcast", Handler: HandleUserBroadcast, }, + tranDownloadBanner: { + Name: "tranDownloadBanner", + Handler: HandleDownloadBanner, + }, } func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err error) { @@ -405,7 +410,9 @@ func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e } } - hlFile.ffo.FlatFileInformationFork.setComment(t.GetField(fieldFileComment).Data) + if err := hlFile.ffo.FlatFileInformationFork.setComment(t.GetField(fieldFileComment).Data); err != nil { + return res, err + } w, err := hlFile.infoForkWriter() if err != nil { return res, err @@ -520,9 +527,12 @@ func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err erro return res, err } - cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName) + cc.logger.Infow("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName) hlFile, err := newFileWrapper(cc.Server.FS, filePath, 0) + if err != nil { + return res, err + } fi, err := hlFile.dataFile() if err != nil { @@ -558,11 +568,12 @@ func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err err res = append(res, cc.NewErrReply(t, "You are not allowed to create folders.")) return res, err } - newFolderPath := cc.Server.Config.FileRoot folderName := string(t.GetField(fieldFileName).Data) folderName = path.Join("/", folderName) + var subPath string + // fieldFilePath is only present for nested paths if t.GetField(fieldFilePath).Data != nil { var newFp FilePath @@ -570,9 +581,12 @@ func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err err if err != nil { return nil, err } - newFolderPath += newFp.String() + + for _, pathItem := range newFp.Items { + subPath = filepath.Join("/", subPath, string(pathItem.Name)) + } } - newFolderPath = path.Join(newFolderPath, folderName) + newFolderPath := path.Join(cc.Server.Config.FileRoot, subPath, folderName) // TODO: check path and folder name lengths @@ -710,7 +724,7 @@ func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err er if len(subFields) == 1 { login := DecodeUserString(getField(fieldData, &subFields).Data) - cc.Server.Logger.Infow("DeleteUser", "login", login) + cc.logger.Infow("DeleteUser", "login", login) if !authorize(cc.Account.Access, accessDeleteUser) { res = append(res, cc.NewErrReply(t, "You are not allowed to delete accounts.")) @@ -727,7 +741,7 @@ func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err er // check if the login dataFile; if so, we know we are updating an existing user if acc, ok := cc.Server.Accounts[login]; ok { - cc.Server.Logger.Infow("UpdateUser", "login", login) + cc.logger.Infow("UpdateUser", "login", login) // account dataFile, so this is an update action if !authorize(cc.Account.Access, accessModifyUser) { @@ -757,7 +771,7 @@ func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err er return res, err } } else { - cc.Server.Logger.Infow("CreateUser", "login", login) + cc.logger.Infow("CreateUser", "login", login) if !authorize(cc.Account.Access, accessCreateUser) { res = append(res, cc.NewErrReply(t, "You are not allowed to create new accounts.")) @@ -928,6 +942,8 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er cc.UserName = t.GetField(fieldUserName).Data *cc.Icon = t.GetField(fieldUserIconID).Data + cc.logger = cc.logger.With("name", string(cc.UserName)) + options := t.GetField(fieldOptions).Data optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options))) @@ -952,7 +968,7 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er cc.AutoReply = []byte{} } - cc.notifyOthers( + for _, t := range cc.notifyOthers( *NewTransaction( tranNotifyChangeUser, nil, NewField(fieldUserName, cc.UserName), @@ -960,7 +976,13 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er NewField(fieldUserIconID, *cc.Icon), NewField(fieldUserFlags, *cc.Flags), ), - ) + ) { + cc.Server.outbox <- t + } + + if cc.Server.Config.BannerFile != "" { + cc.Server.outbox <- *NewTransaction(tranServerBanner, cc.ID, NewField(fieldBannerType, []byte("JPEG"))) + } res = append(res, cc.NewReply(t)) @@ -1049,9 +1071,6 @@ func HandleGetNewsCatNameList(cc *ClientConn, t *Transaction) (res []Transaction return res, err } - newsPath := t.GetField(fieldNewsPath).Data - cc.Server.Logger.Infow("NewsPath: ", "np", string(newsPath)) - pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data) cats := cc.Server.GetNewsCatByPath(pathStrs) @@ -1114,7 +1133,7 @@ func HandleNewNewsFldr(cc *ClientConn, t *Transaction) (res []Transaction, err e name := string(t.GetField(fieldFileName).Data) pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data) - cc.Server.Logger.Infof("Creating new news folder %s", name) + cc.logger.Infof("Creating new news folder %s", name) cats := cc.Server.GetNewsCatByPath(pathStrs) cats[name] = NewsCategoryListData15{ @@ -1219,7 +1238,7 @@ func HandleDelNewsItem(cc *ClientConn, t *Transaction) (res []Transaction, err e // TODO: determine if path is a Folder (Bundle) or Category and check for permission - cc.Server.Logger.Infof("DelNewsItem %v", pathStrs) + cc.logger.Infof("DelNewsItem %v", pathStrs) cats := cc.Server.ThreadedNews.Categories @@ -1667,7 +1686,7 @@ func HandleGetFileNameList(cc *ClientConn, t *Transaction) (res []Transaction, e // Handle special case for drop box folders if fp.IsDropbox() && !authorize(cc.Account.Access, accessViewDropBoxes) { - res = append(res, cc.NewReply(t)) + res = append(res, cc.NewErrReply(t, "You are not allowed to view drop boxes.")) return res, err } @@ -1906,7 +1925,7 @@ func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err err return res, err } - cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath) + cc.logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath) if err := cc.Server.FS.Symlink(fullFilePath, fullNewFilePath); err != nil { res = append(res, cc.NewErrReply(t, "Error creating alias")) @@ -1916,3 +1935,32 @@ func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err err res = append(res, cc.NewReply(t)) return res, err } + +func HandleDownloadBanner(cc *ClientConn, t *Transaction) (res []Transaction, err error) { + transactionRef := cc.Server.NewTransactionRef() + data := binary.BigEndian.Uint32(transactionRef) + + ft := &FileTransfer{ + ReferenceNumber: transactionRef, + Type: bannerDownload, + } + + fi, err := cc.Server.FS.Stat(filepath.Join(cc.Server.ConfigDir, cc.Server.Config.BannerFile)) + if err != nil { + return res, err + } + + size := make([]byte, 4) + binary.BigEndian.PutUint32(size, uint32(fi.Size())) + + cc.Server.mux.Lock() + defer cc.Server.mux.Unlock() + cc.Server.FileTransfers[data] = ft + + res = append(res, cc.NewReply(t, + NewField(fieldRefNum, transactionRef), + NewField(fieldTransferSize, size), + )) + + return res, err +}