Handler: HandleSetClientUserInfo,
},
tranSetFileInfo: {
- Access: accessAlwaysAllow, // granular access is in the handler
+ Access: accessAlwaysAllow,
Name: "tranSetFileInfo",
Handler: HandleSetFileInfo,
},
},
tranUploadFile: {
Access: accessAlwaysAllow,
- DenyMsg: "You are not allowed to upload files.",
Name: "tranUploadFile",
Handler: HandleUploadFile,
},
tranUploadFldr: {
- Access: accessAlwaysAllow, // TODO: what should this be?
+ Access: accessAlwaysAllow,
Name: "tranUploadFldr",
Handler: HandleUploadFolder,
},
}
func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
+ if !authorize(cc.Account.Access, accessSendChat) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to participate in chat."))
+ return res, err
+ }
+
// Truncate long usernames
trunc := fmt.Sprintf("%13s", cc.UserName)
formattedMsg := fmt.Sprintf("\r%.14s: %s", trunc, t.GetField(fieldData).Data)
NewField(fieldFileType, ffo.FlatFileInformationFork.TypeSignature),
NewField(fieldFileCreateDate, ffo.FlatFileInformationFork.CreateDate),
NewField(fieldFileModifyDate, ffo.FlatFileInformationFork.ModifyDate),
- NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize),
+ NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
))
return res, err
}
cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName)
- path := filePath + "/" + fileName
- fi, err := os.Stat(path)
+ fp := filePath + "/" + fileName
+ fi, err := os.Stat(fp)
if err != nil {
return res, err
}
}
}
- // TODO: If we have just promoted a connected user to admin, notify
- // connected clients to turn the user red
-
res = append(res, cc.NewReply(t))
return res, err
}
func HandleGetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
- // userLogin := string(t.GetField(fieldUserLogin).Data)
+ if !authorize(cc.Account.Access, accessOpenUser) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to view accounts."))
+ return res, err
+ }
+
account := cc.Server.Accounts[string(t.GetField(fieldUserLogin).Data)]
if account == nil {
errorT := cc.NewErrReply(t, "Account does not exist.")
}
func HandleDeleteUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
+ if !authorize(cc.Account.Access, accessDeleteUser) {
+ res = append(res, cc.NewErrReply(t, "You are not allowed to delete accounts."))
+ return res, err
+ }
+
// TODO: Handle case where account doesn't exist; e.g. delete race condition
login := DecodeUserString(t.GetField(fieldUserLogin).Data)
return res, err
}
-func (cc *ClientConn) notifyNewUserHasJoined() (res []Transaction, err error) {
- // Notify other ccs that a new user has connected
- cc.NotifyOthers(
- *NewTransaction(
- tranNotifyChangeUser, nil,
- NewField(fieldUserName, cc.UserName),
- NewField(fieldUserID, *cc.ID),
- NewField(fieldUserIconID, *cc.Icon),
- NewField(fieldUserFlags, *cc.Flags),
- ),
- )
-
- return res, nil
-}
-
func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
cc.Agreed = true
cc.UserName = t.GetField(fieldUserName).Data
cc.AutoReply = []byte{}
}
- _, _ = cc.notifyNewUserHasJoined()
+ cc.notifyOthers(
+ *NewTransaction(
+ tranNotifyChangeUser, nil,
+ NewField(fieldUserName, cc.UserName),
+ NewField(fieldUserID, *cc.ID),
+ NewField(fieldUserIconID, *cc.Icon),
+ NewField(fieldUserFlags, *cc.Flags),
+ ),
+ )
res = append(res, cc.NewReply(t))
var cat NewsCategoryListData15
cats := cc.Server.ThreadedNews.Categories
- for _, path := range pathStrs {
- cat = cats[path]
- cats = cats[path].SubCats
+ for _, fp := range pathStrs {
+ cat = cats[fp]
+ cats = cats[fp].SubCats
}
nald := cat.GetNewsArtListData()
func HandleGetNewsArtData(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
// Request fields
- // 325 News path
+ // 325 News fp
// 326 News article ID
// 327 News article data flavor
var cat NewsCategoryListData15
cats := cc.Server.ThreadedNews.Categories
- for _, path := range pathStrs {
- cat = cats[path]
- cats = cats[path].SubCats
+ for _, fp := range pathStrs {
+ cat = cats[fp]
+ cats = cats[fp].SubCats
}
newsArtID := t.GetField(fieldNewsArtID).Data
delName := pathStrs[len(pathStrs)-1]
if len(pathStrs) > 1 {
- for _, path := range pathStrs[0 : len(pathStrs)-1] {
- cats = cats[path].SubCats
+ for _, fp := range pathStrs[0 : len(pathStrs)-1] {
+ cats = cats[fp].SubCats
}
}
NewField(fieldRefNum, transactionRef),
NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
NewField(fieldTransferSize, ffo.TransferSize()),
- NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize),
+ NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
))
return res, err
transactionRef := cc.Server.NewTransactionRef()
data := binary.BigEndian.Uint32(transactionRef)
+ var fp FilePath
+ if t.GetField(fieldFilePath).Data != nil {
+ if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
+ return res, err
+ }
+ }
+
+ // Handle special cases for Upload and Drop Box folders
+ if !authorize(cc.Account.Access, accessUploadAnywhere) {
+ if !fp.IsUploadDir() && !fp.IsDropbox() {
+ res = append(res, cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload of the folder \"%v\" because you are only allowed to upload to the \"Uploads\" folder.", string(t.GetField(fieldFileName).Data))))
+ return res, err
+ }
+ }
+
fileTransfer := &FileTransfer{
FileName: t.GetField(fieldFileName).Data,
FilePath: t.GetField(fieldFilePath).Data,
return res, err
}
+// HandleUploadFile
+// Special cases:
+// * If the target directory contains "uploads" (case insensitive)
func HandleUploadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
- // TODO: add permission handing for upload folders and drop boxes
if !authorize(cc.Account.Access, accessUploadFile) {
res = append(res, cc.NewErrReply(t, "You are not allowed to upload files."))
return res, err
fileName := t.GetField(fieldFileName).Data
filePath := t.GetField(fieldFilePath).Data
+ var fp FilePath
+ if filePath != nil {
+ if err = fp.UnmarshalBinary(filePath); err != nil {
+ return res, err
+ }
+ }
+
+ // Handle special cases for Upload and Drop Box folders
+ if !authorize(cc.Account.Access, accessUploadAnywhere) {
+ if !fp.IsUploadDir() && !fp.IsDropbox() {
+ res = append(res, cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload of the file \"%v\" because you are only allowed to upload to the \"Uploads\" folder.", string(fileName))))
+ return res, err
+ }
+ }
+
transactionRef := cc.Server.NewTransactionRef()
data := binary.BigEndian.Uint32(transactionRef)
return res, err
}
-// User options
-const (
- refusePM = 0
- refuseChat = 1
- autoResponse = 2
-)
-
func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
var icon []byte
if len(t.GetField(fieldUserIconID).Data) == 4 {
return res, err
}
+ var fp FilePath
+ if t.GetField(fieldFilePath).Data != nil {
+ if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
+ return res, err
+ }
+ }
+
+ // Handle special case for drop box folders
+ if fp.IsDropbox() && !authorize(cc.Account.Access, accessViewDropBoxes) {
+ res = append(res, cc.NewReply(t))
+ return res, err
+ }
+
fileNames, err := getFileNameList(fullPath)
if err != nil {
return res, err