18 type TransactionType struct {
19 Access int // Specifies access privilege required to perform the transaction
20 DenyMsg string // The error reply message when user does not have access
21 Handler func(*ClientConn, *Transaction) ([]Transaction, error) // function for handling the transaction type
22 Name string // Name of transaction as it will appear in logging
23 RequiredFields []requiredField
26 var TransactionHandlers = map[uint16]TransactionType{
32 tranNotifyChangeUser: {
33 Name: "tranNotifyChangeUser",
39 Name: "tranShowAgreement",
42 Name: "tranUserAccess",
44 tranNotifyDeleteUser: {
45 Name: "tranNotifyDeleteUser",
48 Access: accessAlwaysAllow,
50 Handler: HandleTranAgreed,
53 Access: accessSendChat,
54 DenyMsg: "You are not allowed to participate in chat.",
55 Handler: HandleChatSend,
57 RequiredFields: []requiredField{
65 Access: accessNewsDeleteArt,
66 DenyMsg: "You are not allowed to delete news articles.",
67 Name: "tranDelNewsArt",
68 Handler: HandleDelNewsArt,
71 Access: accessAlwaysAllow, // Granular access enforced inside the handler
72 // Has multiple access flags: News Delete Folder (37) or News Delete Category (35)
73 // TODO: Implement inside the handler
74 Name: "tranDelNewsItem",
75 Handler: HandleDelNewsItem,
78 Access: accessAlwaysAllow, // Granular access enforced inside the handler
79 Name: "tranDeleteFile",
80 Handler: HandleDeleteFile,
83 Access: accessDeleteUser,
84 DenyMsg: "You are not allowed to delete accounts.",
85 Name: "tranDeleteUser",
86 Handler: HandleDeleteUser,
89 Access: accessDisconUser,
90 DenyMsg: "You are not allowed to disconnect users.",
91 Name: "tranDisconnectUser",
92 Handler: HandleDisconnectUser,
95 Access: accessDownloadFile,
96 DenyMsg: "You are not allowed to download files.",
97 Name: "tranDownloadFile",
98 Handler: HandleDownloadFile,
101 Access: accessDownloadFile, // There is no specific access flag for folder vs file download
102 DenyMsg: "You are not allowed to download files.",
103 Name: "tranDownloadFldr",
104 Handler: HandleDownloadFolder,
106 tranGetClientInfoText: {
107 Access: accessGetClientInfo,
108 DenyMsg: "You are not allowed to get client info",
109 Name: "tranGetClientInfoText",
110 Handler: HandleGetClientConnInfoText,
113 Access: accessAlwaysAllow,
114 Name: "tranGetFileInfo",
115 Handler: HandleGetFileInfo,
117 tranGetFileNameList: {
118 Access: accessAlwaysAllow,
119 Name: "tranGetFileNameList",
120 Handler: HandleGetFileNameList,
123 Access: accessNewsReadArt,
124 DenyMsg: "You are not allowed to read news.",
126 Handler: HandleGetMsgs,
128 tranGetNewsArtData: {
129 Access: accessNewsReadArt,
130 DenyMsg: "You are not allowed to read news.",
131 Name: "tranGetNewsArtData",
132 Handler: HandleGetNewsArtData,
134 tranGetNewsArtNameList: {
135 Access: accessNewsReadArt,
136 DenyMsg: "You are not allowed to read news.",
137 Name: "tranGetNewsArtNameList",
138 Handler: HandleGetNewsArtNameList,
140 tranGetNewsCatNameList: {
141 Access: accessNewsReadArt,
142 DenyMsg: "You are not allowed to read news.",
143 Name: "tranGetNewsCatNameList",
144 Handler: HandleGetNewsCatNameList,
147 Access: accessOpenUser,
148 DenyMsg: "You are not allowed to view accounts.",
150 Handler: HandleGetUser,
152 tranGetUserNameList: {
153 Access: accessAlwaysAllow,
154 Name: "tranHandleGetUserNameList",
155 Handler: HandleGetUserNameList,
158 Access: accessOpenChat,
159 DenyMsg: "You are not allowed to request private chat.",
160 Name: "tranInviteNewChat",
161 Handler: HandleInviteNewChat,
164 Access: accessOpenChat,
165 DenyMsg: "You are not allowed to request private chat.",
166 Name: "tranInviteToChat",
167 Handler: HandleInviteToChat,
170 Access: accessAlwaysAllow,
171 Name: "tranJoinChat",
172 Handler: HandleJoinChat,
175 Access: accessAlwaysAllow,
176 Name: "tranKeepAlive",
177 Handler: HandleKeepAlive,
180 Access: accessAlwaysAllow,
181 Name: "tranJoinChat",
182 Handler: HandleLeaveChat,
186 Access: accessOpenUser,
187 DenyMsg: "You are not allowed to view accounts.",
188 Name: "tranListUsers",
189 Handler: HandleListUsers,
192 Access: accessMoveFile,
193 DenyMsg: "You are not allowed to move files.",
194 Name: "tranMoveFile",
195 Handler: HandleMoveFile,
198 Access: accessCreateFolder,
199 DenyMsg: "You are not allow to create folders.",
200 Name: "tranNewFolder",
201 Handler: HandleNewFolder,
204 Access: accessNewsCreateCat,
205 DenyMsg: "You are not allowed to create news categories.",
206 Name: "tranNewNewsCat",
207 Handler: HandleNewNewsCat,
210 Access: accessNewsCreateFldr,
211 DenyMsg: "You are not allowed to create news folders.",
212 Name: "tranNewNewsFldr",
213 Handler: HandleNewNewsFldr,
216 Access: accessCreateUser,
217 DenyMsg: "You are not allowed to create new accounts.",
219 Handler: HandleNewUser,
222 Access: accessNewsPostArt,
223 DenyMsg: "You are not allowed to post news.",
224 Name: "tranOldPostNews",
225 Handler: HandleTranOldPostNews,
228 Access: accessNewsPostArt,
229 DenyMsg: "You are not allowed to post news articles.",
230 Name: "tranPostNewsArt",
231 Handler: HandlePostNewsArt,
233 tranRejectChatInvite: {
234 Access: accessAlwaysAllow,
235 Name: "tranRejectChatInvite",
236 Handler: HandleRejectChatInvite,
238 tranSendInstantMsg: {
239 Access: accessAlwaysAllow,
240 // Access: accessSendPrivMsg,
241 // DenyMsg: "You are not allowed to send private messages",
242 Name: "tranSendInstantMsg",
243 Handler: HandleSendInstantMsg,
244 RequiredFields: []requiredField{
254 tranSetChatSubject: {
255 Access: accessAlwaysAllow,
256 Name: "tranSetChatSubject",
257 Handler: HandleSetChatSubject,
260 Access: accessAlwaysAllow,
261 Name: "tranMakeFileAlias",
262 Handler: HandleMakeAlias,
263 RequiredFields: []requiredField{
264 {ID: fieldFileName, minLen: 1},
265 {ID: fieldFilePath, minLen: 1},
266 {ID: fieldFileNewPath, minLen: 1},
269 tranSetClientUserInfo: {
270 Access: accessAlwaysAllow,
271 Name: "tranSetClientUserInfo",
272 Handler: HandleSetClientUserInfo,
275 Access: accessAlwaysAllow,
276 Name: "tranSetFileInfo",
277 Handler: HandleSetFileInfo,
280 Access: accessModifyUser,
281 DenyMsg: "You are not allowed to modify accounts.",
283 Handler: HandleSetUser,
286 Access: accessAlwaysAllow,
287 Name: "tranUploadFile",
288 Handler: HandleUploadFile,
291 Access: accessAlwaysAllow,
292 Name: "tranUploadFldr",
293 Handler: HandleUploadFolder,
296 Access: accessBroadcast,
297 DenyMsg: "You are not allowed to send broadcast messages.",
298 Name: "tranUserBroadcast",
299 Handler: HandleUserBroadcast,
303 func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
304 if !authorize(cc.Account.Access, accessSendChat) {
305 res = append(res, cc.NewErrReply(t, "You are not allowed to participate in chat."))
309 // Truncate long usernames
310 trunc := fmt.Sprintf("%13s", cc.UserName)
311 formattedMsg := fmt.Sprintf("\r%.14s: %s", trunc, t.GetField(fieldData).Data)
313 // By holding the option key, Hotline chat allows users to send /me formatted messages like:
314 // *** Halcyon does stuff
315 // This is indicated by the presence of the optional field fieldChatOptions in the transaction payload
316 if t.GetField(fieldChatOptions).Data != nil {
317 formattedMsg = fmt.Sprintf("\r*** %s %s", cc.UserName, t.GetField(fieldData).Data)
320 if bytes.Equal(t.GetField(fieldData).Data, []byte("/stats")) {
321 formattedMsg = strings.Replace(cc.Server.Stats.String(), "\n", "\r", -1)
324 chatID := t.GetField(fieldChatID).Data
325 // a non-nil chatID indicates the message belongs to a private chat
327 chatInt := binary.BigEndian.Uint32(chatID)
328 privChat := cc.Server.PrivateChats[chatInt]
330 // send the message to all connected clients of the private chat
331 for _, c := range privChat.ClientConn {
332 res = append(res, *NewTransaction(
335 NewField(fieldChatID, chatID),
336 NewField(fieldData, []byte(formattedMsg)),
342 for _, c := range sortedClients(cc.Server.Clients) {
343 // Filter out clients that do not have the read chat permission
344 if authorize(c.Account.Access, accessReadChat) {
345 res = append(res, *NewTransaction(tranChatMsg, c.ID, NewField(fieldData, []byte(formattedMsg))))
352 // HandleSendInstantMsg sends instant message to the user on the current server.
353 // Fields used in the request:
356 // One of the following values:
357 // - User message (myOpt_UserMessage = 1)
358 // - Refuse message (myOpt_RefuseMessage = 2)
359 // - Refuse chat (myOpt_RefuseChat = 3)
360 // - Automatic response (myOpt_AutomaticResponse = 4)"
362 // 214 Quoting message Optional
364 // Fields used in the reply:
366 func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
367 msg := t.GetField(fieldData)
368 ID := t.GetField(fieldUserID)
370 reply := *NewTransaction(
373 NewField(fieldData, msg.Data),
374 NewField(fieldUserName, cc.UserName),
375 NewField(fieldUserID, *cc.ID),
376 NewField(fieldOptions, []byte{0, 1}),
379 // Later versions of Hotline include the original message in the fieldQuotingMsg field so
380 // the receiving client can display both the received message and what it is in reply to
381 if t.GetField(fieldQuotingMsg).Data != nil {
382 reply.Fields = append(reply.Fields, NewField(fieldQuotingMsg, t.GetField(fieldQuotingMsg).Data))
385 res = append(res, reply)
387 id, _ := byteToInt(ID.Data)
388 otherClient := cc.Server.Clients[uint16(id)]
389 if otherClient == nil {
390 return res, errors.New("ohno")
393 // Respond with auto reply if other client has it enabled
394 if len(otherClient.AutoReply) > 0 {
399 NewField(fieldData, otherClient.AutoReply),
400 NewField(fieldUserName, otherClient.UserName),
401 NewField(fieldUserID, *otherClient.ID),
402 NewField(fieldOptions, []byte{0, 1}),
407 res = append(res, cc.NewReply(t))
412 func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
413 fileName := t.GetField(fieldFileName).Data
414 filePath := t.GetField(fieldFilePath).Data
416 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName)
421 res = append(res, cc.NewReply(t,
422 NewField(fieldFileName, fileName),
423 NewField(fieldFileTypeString, ffo.FlatFileInformationFork.TypeSignature),
424 NewField(fieldFileCreatorString, ffo.FlatFileInformationFork.CreatorSignature),
425 NewField(fieldFileComment, ffo.FlatFileInformationFork.Comment),
426 NewField(fieldFileType, ffo.FlatFileInformationFork.TypeSignature),
427 NewField(fieldFileCreateDate, ffo.FlatFileInformationFork.CreateDate),
428 NewField(fieldFileModifyDate, ffo.FlatFileInformationFork.ModifyDate),
429 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
434 // HandleSetFileInfo updates a file or folder name and/or comment from the Get Info window
435 // TODO: Implement support for comments
436 // Fields used in the request:
438 // * 202 File path Optional
439 // * 211 File new name Optional
440 // * 210 File comment Optional
441 // Fields used in the reply: None
442 func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
443 fileName := t.GetField(fieldFileName).Data
444 filePath := t.GetField(fieldFilePath).Data
446 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
451 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, t.GetField(fieldFileNewName).Data)
456 // fileComment := t.GetField(fieldFileComment).Data
457 fileNewName := t.GetField(fieldFileNewName).Data
459 if fileNewName != nil {
460 fi, err := FS.Stat(fullFilePath)
464 switch mode := fi.Mode(); {
466 if !authorize(cc.Account.Access, accessRenameFolder) {
467 res = append(res, cc.NewErrReply(t, "You are not allowed to rename folders."))
470 case mode.IsRegular():
471 if !authorize(cc.Account.Access, accessRenameFile) {
472 res = append(res, cc.NewErrReply(t, "You are not allowed to rename files."))
477 err = os.Rename(fullFilePath, fullNewFilePath)
478 if os.IsNotExist(err) {
479 res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
484 res = append(res, cc.NewReply(t))
488 // HandleDeleteFile deletes a file or folder
489 // Fields used in the request:
492 // Fields used in the reply: none
493 func HandleDeleteFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
494 fileName := t.GetField(fieldFileName).Data
495 filePath := t.GetField(fieldFilePath).Data
497 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
502 cc.Server.Logger.Debugw("Delete file", "src", fullFilePath)
504 fi, err := os.Stat(fullFilePath)
506 res = append(res, cc.NewErrReply(t, "Cannot delete file "+string(fileName)+" because it does not exist or cannot be found."))
509 switch mode := fi.Mode(); {
511 if !authorize(cc.Account.Access, accessDeleteFolder) {
512 res = append(res, cc.NewErrReply(t, "You are not allowed to delete folders."))
515 case mode.IsRegular():
516 if !authorize(cc.Account.Access, accessDeleteFile) {
517 res = append(res, cc.NewErrReply(t, "You are not allowed to delete files."))
522 if err := os.RemoveAll(fullFilePath); err != nil {
526 res = append(res, cc.NewReply(t))
530 // HandleMoveFile moves files or folders. Note: seemingly not documented
531 func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
532 fileName := string(t.GetField(fieldFileName).Data)
533 filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
534 fileNewPath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFileNewPath).Data)
536 cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName)
538 fp := filePath + "/" + fileName
539 fi, err := os.Stat(fp)
543 switch mode := fi.Mode(); {
545 if !authorize(cc.Account.Access, accessMoveFolder) {
546 res = append(res, cc.NewErrReply(t, "You are not allowed to move folders."))
549 case mode.IsRegular():
550 if !authorize(cc.Account.Access, accessMoveFile) {
551 res = append(res, cc.NewErrReply(t, "You are not allowed to move files."))
556 err = os.Rename(filePath+"/"+fileName, fileNewPath+"/"+fileName)
557 if os.IsNotExist(err) {
558 res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
562 return []Transaction{}, err
564 // TODO: handle other possible errors; e.g. file delete fails due to file permission issue
566 res = append(res, cc.NewReply(t))
570 func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
571 newFolderPath := cc.Server.Config.FileRoot
572 folderName := string(t.GetField(fieldFileName).Data)
574 folderName = path.Join("/", folderName)
576 // fieldFilePath is only present for nested paths
577 if t.GetField(fieldFilePath).Data != nil {
579 err := newFp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
583 newFolderPath += newFp.String()
585 newFolderPath = path.Join(newFolderPath, folderName)
587 // TODO: check path and folder name lengths
589 if _, err := FS.Stat(newFolderPath); !os.IsNotExist(err) {
590 msg := fmt.Sprintf("Cannot create folder \"%s\" because there is already a file or folder with that name.", folderName)
591 return []Transaction{cc.NewErrReply(t, msg)}, nil
594 // TODO: check for disallowed characters to maintain compatibility for original client
596 if err := FS.Mkdir(newFolderPath, 0777); err != nil {
597 msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
598 return []Transaction{cc.NewErrReply(t, msg)}, nil
601 res = append(res, cc.NewReply(t))
605 func HandleSetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
606 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
607 userName := string(t.GetField(fieldUserName).Data)
609 newAccessLvl := t.GetField(fieldUserAccess).Data
611 account := cc.Server.Accounts[login]
612 account.Access = &newAccessLvl
613 account.Name = userName
615 // If the password field is cleared in the Hotline edit user UI, the SetUser transaction does
616 // not include fieldUserPassword
617 if t.GetField(fieldUserPassword).Data == nil {
618 account.Password = hashAndSalt([]byte(""))
620 if len(t.GetField(fieldUserPassword).Data) > 1 {
621 account.Password = hashAndSalt(t.GetField(fieldUserPassword).Data)
624 file := cc.Server.ConfigDir + "Users/" + login + ".yaml"
625 out, err := yaml.Marshal(&account)
629 if err := ioutil.WriteFile(file, out, 0666); err != nil {
633 // Notify connected clients logged in as the user of the new access level
634 for _, c := range cc.Server.Clients {
635 if c.Account.Login == login {
636 // Note: comment out these two lines to test server-side deny messages
637 newT := NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, newAccessLvl))
638 res = append(res, *newT)
640 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
641 if authorize(c.Account.Access, accessDisconUser) {
642 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 1)
644 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 0)
646 binary.BigEndian.PutUint16(*c.Flags, uint16(flagBitmap.Int64()))
648 c.Account.Access = account.Access
651 tranNotifyChangeUser,
652 NewField(fieldUserID, *c.ID),
653 NewField(fieldUserFlags, *c.Flags),
654 NewField(fieldUserName, c.UserName),
655 NewField(fieldUserIconID, *c.Icon),
660 res = append(res, cc.NewReply(t))
664 func HandleGetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
665 if !authorize(cc.Account.Access, accessOpenUser) {
666 res = append(res, cc.NewErrReply(t, "You are not allowed to view accounts."))
670 account := cc.Server.Accounts[string(t.GetField(fieldUserLogin).Data)]
672 errorT := cc.NewErrReply(t, "Account does not exist.")
673 res = append(res, errorT)
677 res = append(res, cc.NewReply(t,
678 NewField(fieldUserName, []byte(account.Name)),
679 NewField(fieldUserLogin, negateString(t.GetField(fieldUserLogin).Data)),
680 NewField(fieldUserPassword, []byte(account.Password)),
681 NewField(fieldUserAccess, *account.Access),
686 func HandleListUsers(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
687 var userFields []Field
688 // TODO: make order deterministic
689 for _, acc := range cc.Server.Accounts {
690 userField := acc.MarshalBinary()
691 userFields = append(userFields, NewField(fieldData, userField))
694 res = append(res, cc.NewReply(t, userFields...))
698 // HandleNewUser creates a new user account
699 func HandleNewUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
700 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
702 // If the account already exists, reply with an error
703 // TODO: make order deterministic
704 if _, ok := cc.Server.Accounts[login]; ok {
705 res = append(res, cc.NewErrReply(t, "Cannot create account "+login+" because there is already an account with that login."))
709 if err := cc.Server.NewUser(
711 string(t.GetField(fieldUserName).Data),
712 string(t.GetField(fieldUserPassword).Data),
713 t.GetField(fieldUserAccess).Data,
715 return []Transaction{}, err
718 res = append(res, cc.NewReply(t))
722 func HandleDeleteUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
723 if !authorize(cc.Account.Access, accessDeleteUser) {
724 res = append(res, cc.NewErrReply(t, "You are not allowed to delete accounts."))
728 // TODO: Handle case where account doesn't exist; e.g. delete race condition
729 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
731 if err := cc.Server.DeleteUser(login); err != nil {
735 res = append(res, cc.NewReply(t))
739 // HandleUserBroadcast sends an Administrator Message to all connected clients of the server
740 func HandleUserBroadcast(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
743 NewField(fieldData, t.GetField(tranGetMsgs).Data),
744 NewField(fieldChatOptions, []byte{0}),
747 res = append(res, cc.NewReply(t))
751 func byteToInt(bytes []byte) (int, error) {
754 return int(binary.BigEndian.Uint16(bytes)), nil
756 return int(binary.BigEndian.Uint32(bytes)), nil
759 return 0, errors.New("unknown byte length")
762 func HandleGetClientConnInfoText(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
763 clientID, _ := byteToInt(t.GetField(fieldUserID).Data)
765 clientConn := cc.Server.Clients[uint16(clientID)]
766 if clientConn == nil {
767 return res, errors.New("invalid client")
770 // TODO: Implement non-hardcoded values
771 template := `Nickname: %s
776 -------- File Downloads ---------
780 ------- Folder Downloads --------
784 --------- File Uploads ----------
788 -------- Folder Uploads ---------
792 ------- Waiting Downloads -------
798 activeDownloads := clientConn.Transfers[FileDownload]
799 activeDownloadList := "None."
800 for _, dl := range activeDownloads {
801 activeDownloadList += dl.String() + "\n"
804 template = fmt.Sprintf(
807 clientConn.Account.Name,
808 clientConn.Account.Login,
809 clientConn.Connection.RemoteAddr().String(),
812 template = strings.Replace(template, "\n", "\r", -1)
814 res = append(res, cc.NewReply(t,
815 NewField(fieldData, []byte(template)),
816 NewField(fieldUserName, clientConn.UserName),
821 func HandleGetUserNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
822 res = append(res, cc.NewReply(t, cc.Server.connectedUsers()...))
827 func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
829 cc.UserName = t.GetField(fieldUserName).Data
830 *cc.Icon = t.GetField(fieldUserIconID).Data
832 options := t.GetField(fieldOptions).Data
833 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
835 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
837 // Check refuse private PM option
838 if optBitmap.Bit(refusePM) == 1 {
839 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, 1)
840 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
843 // Check refuse private chat option
844 if optBitmap.Bit(refuseChat) == 1 {
845 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, 1)
846 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
849 // Check auto response
850 if optBitmap.Bit(autoResponse) == 1 {
851 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
853 cc.AutoReply = []byte{}
858 tranNotifyChangeUser, nil,
859 NewField(fieldUserName, cc.UserName),
860 NewField(fieldUserID, *cc.ID),
861 NewField(fieldUserIconID, *cc.Icon),
862 NewField(fieldUserFlags, *cc.Flags),
866 res = append(res, cc.NewReply(t))
871 const defaultNewsDateFormat = "Jan02 15:04" // Jun23 20:49
872 // "Mon, 02 Jan 2006 15:04:05 MST"
874 const defaultNewsTemplate = `From %s (%s):
878 __________________________________________________________`
880 // HandleTranOldPostNews updates the flat news
881 // Fields used in this request:
883 func HandleTranOldPostNews(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
884 cc.Server.flatNewsMux.Lock()
885 defer cc.Server.flatNewsMux.Unlock()
887 newsDateTemplate := defaultNewsDateFormat
888 if cc.Server.Config.NewsDateFormat != "" {
889 newsDateTemplate = cc.Server.Config.NewsDateFormat
892 newsTemplate := defaultNewsTemplate
893 if cc.Server.Config.NewsDelimiter != "" {
894 newsTemplate = cc.Server.Config.NewsDelimiter
897 newsPost := fmt.Sprintf(newsTemplate+"\r", cc.UserName, time.Now().Format(newsDateTemplate), t.GetField(fieldData).Data)
898 newsPost = strings.Replace(newsPost, "\n", "\r", -1)
900 // update news in memory
901 cc.Server.FlatNews = append([]byte(newsPost), cc.Server.FlatNews...)
903 // update news on disk
904 if err := ioutil.WriteFile(cc.Server.ConfigDir+"MessageBoard.txt", cc.Server.FlatNews, 0644); err != nil {
908 // Notify all clients of updated news
911 NewField(fieldData, []byte(newsPost)),
914 res = append(res, cc.NewReply(t))
918 func HandleDisconnectUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
919 clientConn := cc.Server.Clients[binary.BigEndian.Uint16(t.GetField(fieldUserID).Data)]
921 if authorize(clientConn.Account.Access, accessCannotBeDiscon) {
922 res = append(res, cc.NewErrReply(t, clientConn.Account.Login+" is not allowed to be disconnected."))
926 if err := clientConn.Connection.Close(); err != nil {
930 res = append(res, cc.NewReply(t))
934 func HandleGetNewsCatNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
935 // Fields used in the request:
936 // 325 News path (Optional)
938 newsPath := t.GetField(fieldNewsPath).Data
939 cc.Server.Logger.Infow("NewsPath: ", "np", string(newsPath))
941 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
942 cats := cc.Server.GetNewsCatByPath(pathStrs)
944 // To store the keys in slice in sorted order
945 keys := make([]string, len(cats))
947 for k := range cats {
953 var fieldData []Field
954 for _, k := range keys {
956 b, _ := cat.MarshalBinary()
957 fieldData = append(fieldData, NewField(
958 fieldNewsCatListData15,
963 res = append(res, cc.NewReply(t, fieldData...))
967 func HandleNewNewsCat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
968 name := string(t.GetField(fieldNewsCatName).Data)
969 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
971 cats := cc.Server.GetNewsCatByPath(pathStrs)
972 cats[name] = NewsCategoryListData15{
975 Articles: map[uint32]*NewsArtData{},
976 SubCats: make(map[string]NewsCategoryListData15),
979 if err := cc.Server.writeThreadedNews(); err != nil {
982 res = append(res, cc.NewReply(t))
986 func HandleNewNewsFldr(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
987 // Fields used in the request:
988 // 322 News category name
990 name := string(t.GetField(fieldFileName).Data)
991 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
993 cc.Server.Logger.Infof("Creating new news folder %s", name)
995 cats := cc.Server.GetNewsCatByPath(pathStrs)
996 cats[name] = NewsCategoryListData15{
999 Articles: map[uint32]*NewsArtData{},
1000 SubCats: make(map[string]NewsCategoryListData15),
1002 if err := cc.Server.writeThreadedNews(); err != nil {
1005 res = append(res, cc.NewReply(t))
1009 // Fields used in the request:
1010 // 325 News path Optional
1013 // 321 News article list data Optional
1014 func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1015 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1017 var cat NewsCategoryListData15
1018 cats := cc.Server.ThreadedNews.Categories
1020 for _, fp := range pathStrs {
1022 cats = cats[fp].SubCats
1025 nald := cat.GetNewsArtListData()
1027 res = append(res, cc.NewReply(t, NewField(fieldNewsArtListData, nald.Payload())))
1031 func HandleGetNewsArtData(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1034 // 326 News article ID
1035 // 327 News article data flavor
1037 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1039 var cat NewsCategoryListData15
1040 cats := cc.Server.ThreadedNews.Categories
1042 for _, fp := range pathStrs {
1044 cats = cats[fp].SubCats
1046 newsArtID := t.GetField(fieldNewsArtID).Data
1048 convertedArtID := binary.BigEndian.Uint16(newsArtID)
1050 art := cat.Articles[uint32(convertedArtID)]
1052 res = append(res, cc.NewReply(t))
1057 // 328 News article title
1058 // 329 News article poster
1059 // 330 News article date
1060 // 331 Previous article ID
1061 // 332 Next article ID
1062 // 335 Parent article ID
1063 // 336 First child article ID
1064 // 327 News article data flavor "Should be “text/plain”
1065 // 333 News article data Optional (if data flavor is “text/plain”)
1067 res = append(res, cc.NewReply(t,
1068 NewField(fieldNewsArtTitle, []byte(art.Title)),
1069 NewField(fieldNewsArtPoster, []byte(art.Poster)),
1070 NewField(fieldNewsArtDate, art.Date),
1071 NewField(fieldNewsArtPrevArt, art.PrevArt),
1072 NewField(fieldNewsArtNextArt, art.NextArt),
1073 NewField(fieldNewsArtParentArt, art.ParentArt),
1074 NewField(fieldNewsArt1stChildArt, art.FirstChildArt),
1075 NewField(fieldNewsArtDataFlav, []byte("text/plain")),
1076 NewField(fieldNewsArtData, []byte(art.Data)),
1081 func HandleDelNewsItem(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1082 // Access: News Delete Folder (37) or News Delete Category (35)
1084 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1086 // TODO: determine if path is a Folder (Bundle) or Category and check for permission
1088 cc.Server.Logger.Infof("DelNewsItem %v", pathStrs)
1090 cats := cc.Server.ThreadedNews.Categories
1092 delName := pathStrs[len(pathStrs)-1]
1093 if len(pathStrs) > 1 {
1094 for _, fp := range pathStrs[0 : len(pathStrs)-1] {
1095 cats = cats[fp].SubCats
1099 delete(cats, delName)
1101 err = cc.Server.writeThreadedNews()
1106 // Reply params: none
1107 res = append(res, cc.NewReply(t))
1112 func HandleDelNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1115 // 326 News article ID
1116 // 337 News article – recursive delete Delete child articles (1) or not (0)
1117 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1118 ID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1120 // TODO: Delete recursive
1121 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1123 catName := pathStrs[len(pathStrs)-1]
1124 cat := cats[catName]
1126 delete(cat.Articles, uint32(ID))
1129 if err := cc.Server.writeThreadedNews(); err != nil {
1133 res = append(res, cc.NewReply(t))
1137 func HandlePostNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1140 // 326 News article ID ID of the parent article?
1141 // 328 News article title
1142 // 334 News article flags
1143 // 327 News article data flavor Currently “text/plain”
1144 // 333 News article data
1146 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1147 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1149 catName := pathStrs[len(pathStrs)-1]
1150 cat := cats[catName]
1152 newArt := NewsArtData{
1153 Title: string(t.GetField(fieldNewsArtTitle).Data),
1154 Poster: string(cc.UserName),
1155 Date: toHotlineTime(time.Now()),
1156 PrevArt: []byte{0, 0, 0, 0},
1157 NextArt: []byte{0, 0, 0, 0},
1158 ParentArt: append([]byte{0, 0}, t.GetField(fieldNewsArtID).Data...),
1159 FirstChildArt: []byte{0, 0, 0, 0},
1160 DataFlav: []byte("text/plain"),
1161 Data: string(t.GetField(fieldNewsArtData).Data),
1165 for k := range cat.Articles {
1166 keys = append(keys, int(k))
1172 prevID := uint32(keys[len(keys)-1])
1175 binary.BigEndian.PutUint32(newArt.PrevArt, prevID)
1177 // Set next article ID
1178 binary.BigEndian.PutUint32(cat.Articles[prevID].NextArt, nextID)
1181 // Update parent article with first child reply
1182 parentID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1184 parentArt := cat.Articles[uint32(parentID)]
1186 if bytes.Equal(parentArt.FirstChildArt, []byte{0, 0, 0, 0}) {
1187 binary.BigEndian.PutUint32(parentArt.FirstChildArt, nextID)
1191 cat.Articles[nextID] = &newArt
1194 if err := cc.Server.writeThreadedNews(); err != nil {
1198 res = append(res, cc.NewReply(t))
1202 // HandleGetMsgs returns the flat news data
1203 func HandleGetMsgs(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1204 res = append(res, cc.NewReply(t, NewField(fieldData, cc.Server.FlatNews)))
1209 func HandleDownloadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1210 fileName := t.GetField(fieldFileName).Data
1211 filePath := t.GetField(fieldFilePath).Data
1214 err = fp.UnmarshalBinary(filePath)
1219 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName)
1224 transactionRef := cc.Server.NewTransactionRef()
1225 data := binary.BigEndian.Uint32(transactionRef)
1227 ft := &FileTransfer{
1230 ReferenceNumber: transactionRef,
1234 cc.Server.FileTransfers[data] = ft
1235 cc.Transfers[FileDownload] = append(cc.Transfers[FileDownload], ft)
1237 res = append(res, cc.NewReply(t,
1238 NewField(fieldRefNum, transactionRef),
1239 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1240 NewField(fieldTransferSize, ffo.TransferSize()),
1241 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
1247 // Download all files from the specified folder and sub-folders
1260 // 00 6c // transfer size
1264 // 00 dc // field Folder item count
1268 // 00 6b // ref number
1271 func HandleDownloadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1272 transactionRef := cc.Server.NewTransactionRef()
1273 data := binary.BigEndian.Uint32(transactionRef)
1275 fileTransfer := &FileTransfer{
1276 FileName: t.GetField(fieldFileName).Data,
1277 FilePath: t.GetField(fieldFilePath).Data,
1278 ReferenceNumber: transactionRef,
1279 Type: FolderDownload,
1281 cc.Server.FileTransfers[data] = fileTransfer
1282 cc.Transfers[FolderDownload] = append(cc.Transfers[FolderDownload], fileTransfer)
1285 err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
1290 fullFilePath, err := readPath(cc.Server.Config.FileRoot, t.GetField(fieldFilePath).Data, t.GetField(fieldFileName).Data)
1295 transferSize, err := CalcTotalSize(fullFilePath)
1299 itemCount, err := CalcItemCount(fullFilePath)
1303 res = append(res, cc.NewReply(t,
1304 NewField(fieldRefNum, transactionRef),
1305 NewField(fieldTransferSize, transferSize),
1306 NewField(fieldFolderItemCount, itemCount),
1307 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1312 // Upload all files from the local folder and its subfolders to the specified path on the server
1313 // Fields used in the request
1316 // 108 transfer size Total size of all items in the folder
1317 // 220 Folder item count
1318 // 204 File transfer options "Optional Currently set to 1" (TODO: ??)
1319 func HandleUploadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1320 transactionRef := cc.Server.NewTransactionRef()
1321 data := binary.BigEndian.Uint32(transactionRef)
1324 if t.GetField(fieldFilePath).Data != nil {
1325 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1330 // Handle special cases for Upload and Drop Box folders
1331 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1332 if !fp.IsUploadDir() && !fp.IsDropbox() {
1333 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))))
1338 fileTransfer := &FileTransfer{
1339 FileName: t.GetField(fieldFileName).Data,
1340 FilePath: t.GetField(fieldFilePath).Data,
1341 ReferenceNumber: transactionRef,
1343 FolderItemCount: t.GetField(fieldFolderItemCount).Data,
1344 TransferSize: t.GetField(fieldTransferSize).Data,
1346 cc.Server.FileTransfers[data] = fileTransfer
1348 res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
1354 // * If the target directory contains "uploads" (case insensitive)
1355 func HandleUploadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1356 if !authorize(cc.Account.Access, accessUploadFile) {
1357 res = append(res, cc.NewErrReply(t, "You are not allowed to upload files."))
1361 fileName := t.GetField(fieldFileName).Data
1362 filePath := t.GetField(fieldFilePath).Data
1365 if filePath != nil {
1366 if err = fp.UnmarshalBinary(filePath); err != nil {
1371 // Handle special cases for Upload and Drop Box folders
1372 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1373 if !fp.IsUploadDir() && !fp.IsDropbox() {
1374 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))))
1379 transactionRef := cc.Server.NewTransactionRef()
1380 data := binary.BigEndian.Uint32(transactionRef)
1382 cc.Server.FileTransfers[data] = &FileTransfer{
1385 ReferenceNumber: transactionRef,
1389 res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
1393 func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1395 if len(t.GetField(fieldUserIconID).Data) == 4 {
1396 icon = t.GetField(fieldUserIconID).Data[2:]
1398 icon = t.GetField(fieldUserIconID).Data
1401 cc.UserName = t.GetField(fieldUserName).Data
1403 // the options field is only passed by the client versions > 1.2.3.
1404 options := t.GetField(fieldOptions).Data
1407 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
1408 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
1410 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, optBitmap.Bit(refusePM))
1411 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1413 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, optBitmap.Bit(refuseChat))
1414 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1416 // Check auto response
1417 if optBitmap.Bit(autoResponse) == 1 {
1418 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
1420 cc.AutoReply = []byte{}
1424 // Notify all clients of updated user info
1426 tranNotifyChangeUser,
1427 NewField(fieldUserID, *cc.ID),
1428 NewField(fieldUserIconID, *cc.Icon),
1429 NewField(fieldUserFlags, *cc.Flags),
1430 NewField(fieldUserName, cc.UserName),
1436 // HandleKeepAlive responds to keepalive transactions with an empty reply
1437 // * HL 1.9.2 Client sends keepalive msg every 3 minutes
1438 // * HL 1.2.3 Client doesn't send keepalives
1439 func HandleKeepAlive(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1440 res = append(res, cc.NewReply(t))
1445 func HandleGetFileNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1446 fullPath, err := readPath(
1447 cc.Server.Config.FileRoot,
1448 t.GetField(fieldFilePath).Data,
1456 if t.GetField(fieldFilePath).Data != nil {
1457 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1462 // Handle special case for drop box folders
1463 if fp.IsDropbox() && !authorize(cc.Account.Access, accessViewDropBoxes) {
1464 res = append(res, cc.NewReply(t))
1468 fileNames, err := getFileNameList(fullPath)
1473 res = append(res, cc.NewReply(t, fileNames...))
1478 // =================================
1479 // Hotline private chat flow
1480 // =================================
1481 // 1. ClientA sends tranInviteNewChat to server with user ID to invite
1482 // 2. Server creates new ChatID
1483 // 3. Server sends tranInviteToChat to invitee
1484 // 4. Server replies to ClientA with new Chat ID
1486 // A dialog box pops up in the invitee client with options to accept or decline the invitation.
1487 // If Accepted is clicked:
1488 // 1. ClientB sends tranJoinChat with fieldChatID
1490 // HandleInviteNewChat invites users to new private chat
1491 func HandleInviteNewChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1493 targetID := t.GetField(fieldUserID).Data
1494 newChatID := cc.Server.NewPrivateChat(cc)
1500 NewField(fieldChatID, newChatID),
1501 NewField(fieldUserName, cc.UserName),
1502 NewField(fieldUserID, *cc.ID),
1508 NewField(fieldChatID, newChatID),
1509 NewField(fieldUserName, cc.UserName),
1510 NewField(fieldUserID, *cc.ID),
1511 NewField(fieldUserIconID, *cc.Icon),
1512 NewField(fieldUserFlags, *cc.Flags),
1519 func HandleInviteToChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1521 targetID := t.GetField(fieldUserID).Data
1522 chatID := t.GetField(fieldChatID).Data
1528 NewField(fieldChatID, chatID),
1529 NewField(fieldUserName, cc.UserName),
1530 NewField(fieldUserID, *cc.ID),
1536 NewField(fieldChatID, chatID),
1537 NewField(fieldUserName, cc.UserName),
1538 NewField(fieldUserID, *cc.ID),
1539 NewField(fieldUserIconID, *cc.Icon),
1540 NewField(fieldUserFlags, *cc.Flags),
1547 func HandleRejectChatInvite(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1548 chatID := t.GetField(fieldChatID).Data
1549 chatInt := binary.BigEndian.Uint32(chatID)
1551 privChat := cc.Server.PrivateChats[chatInt]
1553 resMsg := append(cc.UserName, []byte(" declined invitation to chat")...)
1555 for _, c := range sortedClients(privChat.ClientConn) {
1560 NewField(fieldChatID, chatID),
1561 NewField(fieldData, resMsg),
1569 // HandleJoinChat is sent from a v1.8+ Hotline client when the joins a private chat
1570 // Fields used in the reply:
1571 // * 115 Chat subject
1572 // * 300 User name with info (Optional)
1573 // * 300 (more user names with info)
1574 func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1575 chatID := t.GetField(fieldChatID).Data
1576 chatInt := binary.BigEndian.Uint32(chatID)
1578 privChat := cc.Server.PrivateChats[chatInt]
1580 // Send tranNotifyChatChangeUser to current members of the chat to inform of new user
1581 for _, c := range sortedClients(privChat.ClientConn) {
1584 tranNotifyChatChangeUser,
1586 NewField(fieldChatID, chatID),
1587 NewField(fieldUserName, cc.UserName),
1588 NewField(fieldUserID, *cc.ID),
1589 NewField(fieldUserIconID, *cc.Icon),
1590 NewField(fieldUserFlags, *cc.Flags),
1595 privChat.ClientConn[cc.uint16ID()] = cc
1597 replyFields := []Field{NewField(fieldChatSubject, []byte(privChat.Subject))}
1598 for _, c := range sortedClients(privChat.ClientConn) {
1603 Name: string(c.UserName),
1606 replyFields = append(replyFields, NewField(fieldUsernameWithInfo, user.Payload()))
1609 res = append(res, cc.NewReply(t, replyFields...))
1613 // HandleLeaveChat is sent from a v1.8+ Hotline client when the user exits a private chat
1614 // Fields used in the request:
1615 // * 114 fieldChatID
1616 // Reply is not expected.
1617 func HandleLeaveChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1618 chatID := t.GetField(fieldChatID).Data
1619 chatInt := binary.BigEndian.Uint32(chatID)
1621 privChat := cc.Server.PrivateChats[chatInt]
1623 delete(privChat.ClientConn, cc.uint16ID())
1625 // Notify members of the private chat that the user has left
1626 for _, c := range sortedClients(privChat.ClientConn) {
1629 tranNotifyChatDeleteUser,
1631 NewField(fieldChatID, chatID),
1632 NewField(fieldUserID, *cc.ID),
1640 // HandleSetChatSubject is sent from a v1.8+ Hotline client when the user sets a private chat subject
1641 // Fields used in the request:
1643 // * 115 Chat subject Chat subject string
1644 // Reply is not expected.
1645 func HandleSetChatSubject(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1646 chatID := t.GetField(fieldChatID).Data
1647 chatInt := binary.BigEndian.Uint32(chatID)
1649 privChat := cc.Server.PrivateChats[chatInt]
1650 privChat.Subject = string(t.GetField(fieldChatSubject).Data)
1652 for _, c := range sortedClients(privChat.ClientConn) {
1655 tranNotifyChatSubject,
1657 NewField(fieldChatID, chatID),
1658 NewField(fieldChatSubject, t.GetField(fieldChatSubject).Data),
1666 // HandleMakeAlias makes a file alias using the specified path.
1667 // Fields used in the request:
1670 // 212 File new path Destination path
1672 // Fields used in the reply:
1674 func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1675 if !authorize(cc.Account.Access, accessMakeAlias) {
1676 res = append(res, cc.NewErrReply(t, "You are not allowed to make aliases."))
1679 fileName := t.GetField(fieldFileName).Data
1680 filePath := t.GetField(fieldFilePath).Data
1681 fileNewPath := t.GetField(fieldFileNewPath).Data
1683 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
1688 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
1693 cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
1695 if err := FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
1696 res = append(res, cc.NewErrReply(t, "Error creating alias"))
1700 res = append(res, cc.NewReply(t))