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)
369 // TODO: Implement reply quoting
370 // options := transaction.GetField(hotline.fieldOptions)
376 NewField(fieldData, msg.Data),
377 NewField(fieldUserName, cc.UserName),
378 NewField(fieldUserID, *cc.ID),
379 NewField(fieldOptions, []byte{0, 1}),
382 id, _ := byteToInt(ID.Data)
384 otherClient := cc.Server.Clients[uint16(id)]
385 if otherClient == nil {
386 return res, errors.New("ohno")
389 // Respond with auto reply if other client has it enabled
390 if len(otherClient.AutoReply) > 0 {
395 NewField(fieldData, otherClient.AutoReply),
396 NewField(fieldUserName, otherClient.UserName),
397 NewField(fieldUserID, *otherClient.ID),
398 NewField(fieldOptions, []byte{0, 1}),
403 res = append(res, cc.NewReply(t))
408 func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
409 fileName := t.GetField(fieldFileName).Data
410 filePath := t.GetField(fieldFilePath).Data
412 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName)
417 res = append(res, cc.NewReply(t,
418 NewField(fieldFileName, fileName),
419 NewField(fieldFileTypeString, ffo.FlatFileInformationFork.TypeSignature),
420 NewField(fieldFileCreatorString, ffo.FlatFileInformationFork.CreatorSignature),
421 NewField(fieldFileComment, ffo.FlatFileInformationFork.Comment),
422 NewField(fieldFileType, ffo.FlatFileInformationFork.TypeSignature),
423 NewField(fieldFileCreateDate, ffo.FlatFileInformationFork.CreateDate),
424 NewField(fieldFileModifyDate, ffo.FlatFileInformationFork.ModifyDate),
425 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
430 // HandleSetFileInfo updates a file or folder name and/or comment from the Get Info window
431 // TODO: Implement support for comments
432 // Fields used in the request:
434 // * 202 File path Optional
435 // * 211 File new name Optional
436 // * 210 File comment Optional
437 // Fields used in the reply: None
438 func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
439 fileName := t.GetField(fieldFileName).Data
440 filePath := t.GetField(fieldFilePath).Data
442 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
447 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, t.GetField(fieldFileNewName).Data)
452 // fileComment := t.GetField(fieldFileComment).Data
453 fileNewName := t.GetField(fieldFileNewName).Data
455 if fileNewName != nil {
456 fi, err := FS.Stat(fullFilePath)
460 switch mode := fi.Mode(); {
462 if !authorize(cc.Account.Access, accessRenameFolder) {
463 res = append(res, cc.NewErrReply(t, "You are not allowed to rename folders."))
466 case mode.IsRegular():
467 if !authorize(cc.Account.Access, accessRenameFile) {
468 res = append(res, cc.NewErrReply(t, "You are not allowed to rename files."))
473 err = os.Rename(fullFilePath, fullNewFilePath)
474 if os.IsNotExist(err) {
475 res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
480 res = append(res, cc.NewReply(t))
484 // HandleDeleteFile deletes a file or folder
485 // Fields used in the request:
488 // Fields used in the reply: none
489 func HandleDeleteFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
490 fileName := t.GetField(fieldFileName).Data
491 filePath := t.GetField(fieldFilePath).Data
493 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
498 cc.Server.Logger.Debugw("Delete file", "src", fullFilePath)
500 fi, err := os.Stat(fullFilePath)
502 res = append(res, cc.NewErrReply(t, "Cannot delete file "+string(fileName)+" because it does not exist or cannot be found."))
505 switch mode := fi.Mode(); {
507 if !authorize(cc.Account.Access, accessDeleteFolder) {
508 res = append(res, cc.NewErrReply(t, "You are not allowed to delete folders."))
511 case mode.IsRegular():
512 if !authorize(cc.Account.Access, accessDeleteFile) {
513 res = append(res, cc.NewErrReply(t, "You are not allowed to delete files."))
518 if err := os.RemoveAll(fullFilePath); err != nil {
522 res = append(res, cc.NewReply(t))
526 // HandleMoveFile moves files or folders. Note: seemingly not documented
527 func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
528 fileName := string(t.GetField(fieldFileName).Data)
529 filePath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFilePath).Data)
530 fileNewPath := cc.Server.Config.FileRoot + ReadFilePath(t.GetField(fieldFileNewPath).Data)
532 cc.Server.Logger.Debugw("Move file", "src", filePath+"/"+fileName, "dst", fileNewPath+"/"+fileName)
534 fp := filePath + "/" + fileName
535 fi, err := os.Stat(fp)
539 switch mode := fi.Mode(); {
541 if !authorize(cc.Account.Access, accessMoveFolder) {
542 res = append(res, cc.NewErrReply(t, "You are not allowed to move folders."))
545 case mode.IsRegular():
546 if !authorize(cc.Account.Access, accessMoveFile) {
547 res = append(res, cc.NewErrReply(t, "You are not allowed to move files."))
552 err = os.Rename(filePath+"/"+fileName, fileNewPath+"/"+fileName)
553 if os.IsNotExist(err) {
554 res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
558 return []Transaction{}, err
560 // TODO: handle other possible errors; e.g. file delete fails due to file permission issue
562 res = append(res, cc.NewReply(t))
566 func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
567 newFolderPath := cc.Server.Config.FileRoot
568 folderName := string(t.GetField(fieldFileName).Data)
570 folderName = path.Join("/", folderName)
572 // fieldFilePath is only present for nested paths
573 if t.GetField(fieldFilePath).Data != nil {
575 err := newFp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
579 newFolderPath += newFp.String()
581 newFolderPath = path.Join(newFolderPath, folderName)
583 // TODO: check path and folder name lengths
585 if _, err := FS.Stat(newFolderPath); !os.IsNotExist(err) {
586 msg := fmt.Sprintf("Cannot create folder \"%s\" because there is already a file or folder with that name.", folderName)
587 return []Transaction{cc.NewErrReply(t, msg)}, nil
590 // TODO: check for disallowed characters to maintain compatibility for original client
592 if err := FS.Mkdir(newFolderPath, 0777); err != nil {
593 msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
594 return []Transaction{cc.NewErrReply(t, msg)}, nil
597 res = append(res, cc.NewReply(t))
601 func HandleSetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
602 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
603 userName := string(t.GetField(fieldUserName).Data)
605 newAccessLvl := t.GetField(fieldUserAccess).Data
607 account := cc.Server.Accounts[login]
608 account.Access = &newAccessLvl
609 account.Name = userName
611 // If the password field is cleared in the Hotline edit user UI, the SetUser transaction does
612 // not include fieldUserPassword
613 if t.GetField(fieldUserPassword).Data == nil {
614 account.Password = hashAndSalt([]byte(""))
616 if len(t.GetField(fieldUserPassword).Data) > 1 {
617 account.Password = hashAndSalt(t.GetField(fieldUserPassword).Data)
620 file := cc.Server.ConfigDir + "Users/" + login + ".yaml"
621 out, err := yaml.Marshal(&account)
625 if err := ioutil.WriteFile(file, out, 0666); err != nil {
629 // Notify connected clients logged in as the user of the new access level
630 for _, c := range cc.Server.Clients {
631 if c.Account.Login == login {
632 // Note: comment out these two lines to test server-side deny messages
633 newT := NewTransaction(tranUserAccess, c.ID, NewField(fieldUserAccess, newAccessLvl))
634 res = append(res, *newT)
636 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
637 if authorize(c.Account.Access, accessDisconUser) {
638 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 1)
640 flagBitmap.SetBit(flagBitmap, userFlagAdmin, 0)
642 binary.BigEndian.PutUint16(*c.Flags, uint16(flagBitmap.Int64()))
644 c.Account.Access = account.Access
647 tranNotifyChangeUser,
648 NewField(fieldUserID, *c.ID),
649 NewField(fieldUserFlags, *c.Flags),
650 NewField(fieldUserName, c.UserName),
651 NewField(fieldUserIconID, *c.Icon),
656 res = append(res, cc.NewReply(t))
660 func HandleGetUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
661 if !authorize(cc.Account.Access, accessOpenUser) {
662 res = append(res, cc.NewErrReply(t, "You are not allowed to view accounts."))
666 account := cc.Server.Accounts[string(t.GetField(fieldUserLogin).Data)]
668 errorT := cc.NewErrReply(t, "Account does not exist.")
669 res = append(res, errorT)
673 res = append(res, cc.NewReply(t,
674 NewField(fieldUserName, []byte(account.Name)),
675 NewField(fieldUserLogin, negateString(t.GetField(fieldUserLogin).Data)),
676 NewField(fieldUserPassword, []byte(account.Password)),
677 NewField(fieldUserAccess, *account.Access),
682 func HandleListUsers(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
683 var userFields []Field
684 // TODO: make order deterministic
685 for _, acc := range cc.Server.Accounts {
686 userField := acc.MarshalBinary()
687 userFields = append(userFields, NewField(fieldData, userField))
690 res = append(res, cc.NewReply(t, userFields...))
694 // HandleNewUser creates a new user account
695 func HandleNewUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
696 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
698 // If the account already exists, reply with an error
699 // TODO: make order deterministic
700 if _, ok := cc.Server.Accounts[login]; ok {
701 res = append(res, cc.NewErrReply(t, "Cannot create account "+login+" because there is already an account with that login."))
705 if err := cc.Server.NewUser(
707 string(t.GetField(fieldUserName).Data),
708 string(t.GetField(fieldUserPassword).Data),
709 t.GetField(fieldUserAccess).Data,
711 return []Transaction{}, err
714 res = append(res, cc.NewReply(t))
718 func HandleDeleteUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
719 if !authorize(cc.Account.Access, accessDeleteUser) {
720 res = append(res, cc.NewErrReply(t, "You are not allowed to delete accounts."))
724 // TODO: Handle case where account doesn't exist; e.g. delete race condition
725 login := DecodeUserString(t.GetField(fieldUserLogin).Data)
727 if err := cc.Server.DeleteUser(login); err != nil {
731 res = append(res, cc.NewReply(t))
735 // HandleUserBroadcast sends an Administrator Message to all connected clients of the server
736 func HandleUserBroadcast(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
739 NewField(fieldData, t.GetField(tranGetMsgs).Data),
740 NewField(fieldChatOptions, []byte{0}),
743 res = append(res, cc.NewReply(t))
747 func byteToInt(bytes []byte) (int, error) {
750 return int(binary.BigEndian.Uint16(bytes)), nil
752 return int(binary.BigEndian.Uint32(bytes)), nil
755 return 0, errors.New("unknown byte length")
758 func HandleGetClientConnInfoText(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
759 clientID, _ := byteToInt(t.GetField(fieldUserID).Data)
761 clientConn := cc.Server.Clients[uint16(clientID)]
762 if clientConn == nil {
763 return res, errors.New("invalid client")
766 // TODO: Implement non-hardcoded values
767 template := `Nickname: %s
772 -------- File Downloads ---------
776 ------- Folder Downloads --------
780 --------- File Uploads ----------
784 -------- Folder Uploads ---------
788 ------- Waiting Downloads -------
794 activeDownloads := clientConn.Transfers[FileDownload]
795 activeDownloadList := "None."
796 for _, dl := range activeDownloads {
797 activeDownloadList += dl.String() + "\n"
800 template = fmt.Sprintf(
803 clientConn.Account.Name,
804 clientConn.Account.Login,
805 clientConn.Connection.RemoteAddr().String(),
808 template = strings.Replace(template, "\n", "\r", -1)
810 res = append(res, cc.NewReply(t,
811 NewField(fieldData, []byte(template)),
812 NewField(fieldUserName, clientConn.UserName),
817 func HandleGetUserNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
818 res = append(res, cc.NewReply(t, cc.Server.connectedUsers()...))
823 func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
825 cc.UserName = t.GetField(fieldUserName).Data
826 *cc.Icon = t.GetField(fieldUserIconID).Data
828 options := t.GetField(fieldOptions).Data
829 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
831 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
833 // Check refuse private PM option
834 if optBitmap.Bit(refusePM) == 1 {
835 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, 1)
836 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
839 // Check refuse private chat option
840 if optBitmap.Bit(refuseChat) == 1 {
841 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, 1)
842 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
845 // Check auto response
846 if optBitmap.Bit(autoResponse) == 1 {
847 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
849 cc.AutoReply = []byte{}
854 tranNotifyChangeUser, nil,
855 NewField(fieldUserName, cc.UserName),
856 NewField(fieldUserID, *cc.ID),
857 NewField(fieldUserIconID, *cc.Icon),
858 NewField(fieldUserFlags, *cc.Flags),
862 res = append(res, cc.NewReply(t))
867 const defaultNewsDateFormat = "Jan02 15:04" // Jun23 20:49
868 // "Mon, 02 Jan 2006 15:04:05 MST"
870 const defaultNewsTemplate = `From %s (%s):
874 __________________________________________________________`
876 // HandleTranOldPostNews updates the flat news
877 // Fields used in this request:
879 func HandleTranOldPostNews(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
880 cc.Server.flatNewsMux.Lock()
881 defer cc.Server.flatNewsMux.Unlock()
883 newsDateTemplate := defaultNewsDateFormat
884 if cc.Server.Config.NewsDateFormat != "" {
885 newsDateTemplate = cc.Server.Config.NewsDateFormat
888 newsTemplate := defaultNewsTemplate
889 if cc.Server.Config.NewsDelimiter != "" {
890 newsTemplate = cc.Server.Config.NewsDelimiter
893 newsPost := fmt.Sprintf(newsTemplate+"\r", cc.UserName, time.Now().Format(newsDateTemplate), t.GetField(fieldData).Data)
894 newsPost = strings.Replace(newsPost, "\n", "\r", -1)
896 // update news in memory
897 cc.Server.FlatNews = append([]byte(newsPost), cc.Server.FlatNews...)
899 // update news on disk
900 if err := ioutil.WriteFile(cc.Server.ConfigDir+"MessageBoard.txt", cc.Server.FlatNews, 0644); err != nil {
904 // Notify all clients of updated news
907 NewField(fieldData, []byte(newsPost)),
910 res = append(res, cc.NewReply(t))
914 func HandleDisconnectUser(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
915 clientConn := cc.Server.Clients[binary.BigEndian.Uint16(t.GetField(fieldUserID).Data)]
917 if authorize(clientConn.Account.Access, accessCannotBeDiscon) {
918 res = append(res, cc.NewErrReply(t, clientConn.Account.Login+" is not allowed to be disconnected."))
922 if err := clientConn.Connection.Close(); err != nil {
926 res = append(res, cc.NewReply(t))
930 func HandleGetNewsCatNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
931 // Fields used in the request:
932 // 325 News path (Optional)
934 newsPath := t.GetField(fieldNewsPath).Data
935 cc.Server.Logger.Infow("NewsPath: ", "np", string(newsPath))
937 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
938 cats := cc.Server.GetNewsCatByPath(pathStrs)
940 // To store the keys in slice in sorted order
941 keys := make([]string, len(cats))
943 for k := range cats {
949 var fieldData []Field
950 for _, k := range keys {
952 b, _ := cat.MarshalBinary()
953 fieldData = append(fieldData, NewField(
954 fieldNewsCatListData15,
959 res = append(res, cc.NewReply(t, fieldData...))
963 func HandleNewNewsCat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
964 name := string(t.GetField(fieldNewsCatName).Data)
965 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
967 cats := cc.Server.GetNewsCatByPath(pathStrs)
968 cats[name] = NewsCategoryListData15{
971 Articles: map[uint32]*NewsArtData{},
972 SubCats: make(map[string]NewsCategoryListData15),
975 if err := cc.Server.writeThreadedNews(); err != nil {
978 res = append(res, cc.NewReply(t))
982 func HandleNewNewsFldr(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
983 // Fields used in the request:
984 // 322 News category name
986 name := string(t.GetField(fieldFileName).Data)
987 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
989 cc.Server.Logger.Infof("Creating new news folder %s", name)
991 cats := cc.Server.GetNewsCatByPath(pathStrs)
992 cats[name] = NewsCategoryListData15{
995 Articles: map[uint32]*NewsArtData{},
996 SubCats: make(map[string]NewsCategoryListData15),
998 if err := cc.Server.writeThreadedNews(); err != nil {
1001 res = append(res, cc.NewReply(t))
1005 // Fields used in the request:
1006 // 325 News path Optional
1009 // 321 News article list data Optional
1010 func HandleGetNewsArtNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1011 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1013 var cat NewsCategoryListData15
1014 cats := cc.Server.ThreadedNews.Categories
1016 for _, fp := range pathStrs {
1018 cats = cats[fp].SubCats
1021 nald := cat.GetNewsArtListData()
1023 res = append(res, cc.NewReply(t, NewField(fieldNewsArtListData, nald.Payload())))
1027 func HandleGetNewsArtData(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1030 // 326 News article ID
1031 // 327 News article data flavor
1033 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1035 var cat NewsCategoryListData15
1036 cats := cc.Server.ThreadedNews.Categories
1038 for _, fp := range pathStrs {
1040 cats = cats[fp].SubCats
1042 newsArtID := t.GetField(fieldNewsArtID).Data
1044 convertedArtID := binary.BigEndian.Uint16(newsArtID)
1046 art := cat.Articles[uint32(convertedArtID)]
1048 res = append(res, cc.NewReply(t))
1053 // 328 News article title
1054 // 329 News article poster
1055 // 330 News article date
1056 // 331 Previous article ID
1057 // 332 Next article ID
1058 // 335 Parent article ID
1059 // 336 First child article ID
1060 // 327 News article data flavor "Should be “text/plain”
1061 // 333 News article data Optional (if data flavor is “text/plain”)
1063 res = append(res, cc.NewReply(t,
1064 NewField(fieldNewsArtTitle, []byte(art.Title)),
1065 NewField(fieldNewsArtPoster, []byte(art.Poster)),
1066 NewField(fieldNewsArtDate, art.Date),
1067 NewField(fieldNewsArtPrevArt, art.PrevArt),
1068 NewField(fieldNewsArtNextArt, art.NextArt),
1069 NewField(fieldNewsArtParentArt, art.ParentArt),
1070 NewField(fieldNewsArt1stChildArt, art.FirstChildArt),
1071 NewField(fieldNewsArtDataFlav, []byte("text/plain")),
1072 NewField(fieldNewsArtData, []byte(art.Data)),
1077 func HandleDelNewsItem(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1078 // Access: News Delete Folder (37) or News Delete Category (35)
1080 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1082 // TODO: determine if path is a Folder (Bundle) or Category and check for permission
1084 cc.Server.Logger.Infof("DelNewsItem %v", pathStrs)
1086 cats := cc.Server.ThreadedNews.Categories
1088 delName := pathStrs[len(pathStrs)-1]
1089 if len(pathStrs) > 1 {
1090 for _, fp := range pathStrs[0 : len(pathStrs)-1] {
1091 cats = cats[fp].SubCats
1095 delete(cats, delName)
1097 err = cc.Server.writeThreadedNews()
1102 // Reply params: none
1103 res = append(res, cc.NewReply(t))
1108 func HandleDelNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1111 // 326 News article ID
1112 // 337 News article – recursive delete Delete child articles (1) or not (0)
1113 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1114 ID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1116 // TODO: Delete recursive
1117 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1119 catName := pathStrs[len(pathStrs)-1]
1120 cat := cats[catName]
1122 delete(cat.Articles, uint32(ID))
1125 if err := cc.Server.writeThreadedNews(); err != nil {
1129 res = append(res, cc.NewReply(t))
1133 func HandlePostNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1136 // 326 News article ID ID of the parent article?
1137 // 328 News article title
1138 // 334 News article flags
1139 // 327 News article data flavor Currently “text/plain”
1140 // 333 News article data
1142 pathStrs := ReadNewsPath(t.GetField(fieldNewsPath).Data)
1143 cats := cc.Server.GetNewsCatByPath(pathStrs[:len(pathStrs)-1])
1145 catName := pathStrs[len(pathStrs)-1]
1146 cat := cats[catName]
1148 newArt := NewsArtData{
1149 Title: string(t.GetField(fieldNewsArtTitle).Data),
1150 Poster: string(cc.UserName),
1151 Date: toHotlineTime(time.Now()),
1152 PrevArt: []byte{0, 0, 0, 0},
1153 NextArt: []byte{0, 0, 0, 0},
1154 ParentArt: append([]byte{0, 0}, t.GetField(fieldNewsArtID).Data...),
1155 FirstChildArt: []byte{0, 0, 0, 0},
1156 DataFlav: []byte("text/plain"),
1157 Data: string(t.GetField(fieldNewsArtData).Data),
1161 for k := range cat.Articles {
1162 keys = append(keys, int(k))
1168 prevID := uint32(keys[len(keys)-1])
1171 binary.BigEndian.PutUint32(newArt.PrevArt, prevID)
1173 // Set next article ID
1174 binary.BigEndian.PutUint32(cat.Articles[prevID].NextArt, nextID)
1177 // Update parent article with first child reply
1178 parentID := binary.BigEndian.Uint16(t.GetField(fieldNewsArtID).Data)
1180 parentArt := cat.Articles[uint32(parentID)]
1182 if bytes.Equal(parentArt.FirstChildArt, []byte{0, 0, 0, 0}) {
1183 binary.BigEndian.PutUint32(parentArt.FirstChildArt, nextID)
1187 cat.Articles[nextID] = &newArt
1190 if err := cc.Server.writeThreadedNews(); err != nil {
1194 res = append(res, cc.NewReply(t))
1198 // HandleGetMsgs returns the flat news data
1199 func HandleGetMsgs(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1200 res = append(res, cc.NewReply(t, NewField(fieldData, cc.Server.FlatNews)))
1205 func HandleDownloadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1206 fileName := t.GetField(fieldFileName).Data
1207 filePath := t.GetField(fieldFilePath).Data
1210 err = fp.UnmarshalBinary(filePath)
1215 ffo, err := NewFlattenedFileObject(cc.Server.Config.FileRoot, filePath, fileName)
1220 transactionRef := cc.Server.NewTransactionRef()
1221 data := binary.BigEndian.Uint32(transactionRef)
1223 ft := &FileTransfer{
1226 ReferenceNumber: transactionRef,
1230 cc.Server.FileTransfers[data] = ft
1231 cc.Transfers[FileDownload] = append(cc.Transfers[FileDownload], ft)
1233 res = append(res, cc.NewReply(t,
1234 NewField(fieldRefNum, transactionRef),
1235 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1236 NewField(fieldTransferSize, ffo.TransferSize()),
1237 NewField(fieldFileSize, ffo.FlatFileDataForkHeader.DataSize[:]),
1243 // Download all files from the specified folder and sub-folders
1256 // 00 6c // transfer size
1260 // 00 dc // field Folder item count
1264 // 00 6b // ref number
1267 func HandleDownloadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1268 transactionRef := cc.Server.NewTransactionRef()
1269 data := binary.BigEndian.Uint32(transactionRef)
1271 fileTransfer := &FileTransfer{
1272 FileName: t.GetField(fieldFileName).Data,
1273 FilePath: t.GetField(fieldFilePath).Data,
1274 ReferenceNumber: transactionRef,
1275 Type: FolderDownload,
1277 cc.Server.FileTransfers[data] = fileTransfer
1278 cc.Transfers[FolderDownload] = append(cc.Transfers[FolderDownload], fileTransfer)
1281 err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data)
1286 fullFilePath, err := readPath(cc.Server.Config.FileRoot, t.GetField(fieldFilePath).Data, t.GetField(fieldFileName).Data)
1291 transferSize, err := CalcTotalSize(fullFilePath)
1295 itemCount, err := CalcItemCount(fullFilePath)
1299 res = append(res, cc.NewReply(t,
1300 NewField(fieldRefNum, transactionRef),
1301 NewField(fieldTransferSize, transferSize),
1302 NewField(fieldFolderItemCount, itemCount),
1303 NewField(fieldWaitingCount, []byte{0x00, 0x00}), // TODO: Implement waiting count
1308 // Upload all files from the local folder and its subfolders to the specified path on the server
1309 // Fields used in the request
1312 // 108 transfer size Total size of all items in the folder
1313 // 220 Folder item count
1314 // 204 File transfer options "Optional Currently set to 1" (TODO: ??)
1315 func HandleUploadFolder(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1316 transactionRef := cc.Server.NewTransactionRef()
1317 data := binary.BigEndian.Uint32(transactionRef)
1320 if t.GetField(fieldFilePath).Data != nil {
1321 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1326 // Handle special cases for Upload and Drop Box folders
1327 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1328 if !fp.IsUploadDir() && !fp.IsDropbox() {
1329 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))))
1334 fileTransfer := &FileTransfer{
1335 FileName: t.GetField(fieldFileName).Data,
1336 FilePath: t.GetField(fieldFilePath).Data,
1337 ReferenceNumber: transactionRef,
1339 FolderItemCount: t.GetField(fieldFolderItemCount).Data,
1340 TransferSize: t.GetField(fieldTransferSize).Data,
1342 cc.Server.FileTransfers[data] = fileTransfer
1344 res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
1350 // * If the target directory contains "uploads" (case insensitive)
1351 func HandleUploadFile(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1352 if !authorize(cc.Account.Access, accessUploadFile) {
1353 res = append(res, cc.NewErrReply(t, "You are not allowed to upload files."))
1357 fileName := t.GetField(fieldFileName).Data
1358 filePath := t.GetField(fieldFilePath).Data
1361 if filePath != nil {
1362 if err = fp.UnmarshalBinary(filePath); err != nil {
1367 // Handle special cases for Upload and Drop Box folders
1368 if !authorize(cc.Account.Access, accessUploadAnywhere) {
1369 if !fp.IsUploadDir() && !fp.IsDropbox() {
1370 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))))
1375 transactionRef := cc.Server.NewTransactionRef()
1376 data := binary.BigEndian.Uint32(transactionRef)
1378 cc.Server.FileTransfers[data] = &FileTransfer{
1381 ReferenceNumber: transactionRef,
1385 res = append(res, cc.NewReply(t, NewField(fieldRefNum, transactionRef)))
1389 func HandleSetClientUserInfo(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1391 if len(t.GetField(fieldUserIconID).Data) == 4 {
1392 icon = t.GetField(fieldUserIconID).Data[2:]
1394 icon = t.GetField(fieldUserIconID).Data
1397 cc.UserName = t.GetField(fieldUserName).Data
1399 // the options field is only passed by the client versions > 1.2.3.
1400 options := t.GetField(fieldOptions).Data
1403 optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
1404 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*cc.Flags)))
1406 flagBitmap.SetBit(flagBitmap, userFlagRefusePM, optBitmap.Bit(refusePM))
1407 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1409 flagBitmap.SetBit(flagBitmap, userFLagRefusePChat, optBitmap.Bit(refuseChat))
1410 binary.BigEndian.PutUint16(*cc.Flags, uint16(flagBitmap.Int64()))
1412 // Check auto response
1413 if optBitmap.Bit(autoResponse) == 1 {
1414 cc.AutoReply = t.GetField(fieldAutomaticResponse).Data
1416 cc.AutoReply = []byte{}
1420 // Notify all clients of updated user info
1422 tranNotifyChangeUser,
1423 NewField(fieldUserID, *cc.ID),
1424 NewField(fieldUserIconID, *cc.Icon),
1425 NewField(fieldUserFlags, *cc.Flags),
1426 NewField(fieldUserName, cc.UserName),
1432 // HandleKeepAlive responds to keepalive transactions with an empty reply
1433 // * HL 1.9.2 Client sends keepalive msg every 3 minutes
1434 // * HL 1.2.3 Client doesn't send keepalives
1435 func HandleKeepAlive(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1436 res = append(res, cc.NewReply(t))
1441 func HandleGetFileNameList(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1442 fullPath, err := readPath(
1443 cc.Server.Config.FileRoot,
1444 t.GetField(fieldFilePath).Data,
1452 if t.GetField(fieldFilePath).Data != nil {
1453 if err = fp.UnmarshalBinary(t.GetField(fieldFilePath).Data); err != nil {
1458 // Handle special case for drop box folders
1459 if fp.IsDropbox() && !authorize(cc.Account.Access, accessViewDropBoxes) {
1460 res = append(res, cc.NewReply(t))
1464 fileNames, err := getFileNameList(fullPath)
1469 res = append(res, cc.NewReply(t, fileNames...))
1474 // =================================
1475 // Hotline private chat flow
1476 // =================================
1477 // 1. ClientA sends tranInviteNewChat to server with user ID to invite
1478 // 2. Server creates new ChatID
1479 // 3. Server sends tranInviteToChat to invitee
1480 // 4. Server replies to ClientA with new Chat ID
1482 // A dialog box pops up in the invitee client with options to accept or decline the invitation.
1483 // If Accepted is clicked:
1484 // 1. ClientB sends tranJoinChat with fieldChatID
1486 // HandleInviteNewChat invites users to new private chat
1487 func HandleInviteNewChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1489 targetID := t.GetField(fieldUserID).Data
1490 newChatID := cc.Server.NewPrivateChat(cc)
1496 NewField(fieldChatID, newChatID),
1497 NewField(fieldUserName, cc.UserName),
1498 NewField(fieldUserID, *cc.ID),
1504 NewField(fieldChatID, newChatID),
1505 NewField(fieldUserName, cc.UserName),
1506 NewField(fieldUserID, *cc.ID),
1507 NewField(fieldUserIconID, *cc.Icon),
1508 NewField(fieldUserFlags, *cc.Flags),
1515 func HandleInviteToChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1517 targetID := t.GetField(fieldUserID).Data
1518 chatID := t.GetField(fieldChatID).Data
1524 NewField(fieldChatID, chatID),
1525 NewField(fieldUserName, cc.UserName),
1526 NewField(fieldUserID, *cc.ID),
1532 NewField(fieldChatID, chatID),
1533 NewField(fieldUserName, cc.UserName),
1534 NewField(fieldUserID, *cc.ID),
1535 NewField(fieldUserIconID, *cc.Icon),
1536 NewField(fieldUserFlags, *cc.Flags),
1543 func HandleRejectChatInvite(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1544 chatID := t.GetField(fieldChatID).Data
1545 chatInt := binary.BigEndian.Uint32(chatID)
1547 privChat := cc.Server.PrivateChats[chatInt]
1549 resMsg := append(cc.UserName, []byte(" declined invitation to chat")...)
1551 for _, c := range sortedClients(privChat.ClientConn) {
1556 NewField(fieldChatID, chatID),
1557 NewField(fieldData, resMsg),
1565 // HandleJoinChat is sent from a v1.8+ Hotline client when the joins a private chat
1566 // Fields used in the reply:
1567 // * 115 Chat subject
1568 // * 300 User name with info (Optional)
1569 // * 300 (more user names with info)
1570 func HandleJoinChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1571 chatID := t.GetField(fieldChatID).Data
1572 chatInt := binary.BigEndian.Uint32(chatID)
1574 privChat := cc.Server.PrivateChats[chatInt]
1576 // Send tranNotifyChatChangeUser to current members of the chat to inform of new user
1577 for _, c := range sortedClients(privChat.ClientConn) {
1580 tranNotifyChatChangeUser,
1582 NewField(fieldChatID, chatID),
1583 NewField(fieldUserName, cc.UserName),
1584 NewField(fieldUserID, *cc.ID),
1585 NewField(fieldUserIconID, *cc.Icon),
1586 NewField(fieldUserFlags, *cc.Flags),
1591 privChat.ClientConn[cc.uint16ID()] = cc
1593 replyFields := []Field{NewField(fieldChatSubject, []byte(privChat.Subject))}
1594 for _, c := range sortedClients(privChat.ClientConn) {
1599 Name: string(c.UserName),
1602 replyFields = append(replyFields, NewField(fieldUsernameWithInfo, user.Payload()))
1605 res = append(res, cc.NewReply(t, replyFields...))
1609 // HandleLeaveChat is sent from a v1.8+ Hotline client when the user exits a private chat
1610 // Fields used in the request:
1611 // * 114 fieldChatID
1612 // Reply is not expected.
1613 func HandleLeaveChat(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1614 chatID := t.GetField(fieldChatID).Data
1615 chatInt := binary.BigEndian.Uint32(chatID)
1617 privChat := cc.Server.PrivateChats[chatInt]
1619 delete(privChat.ClientConn, cc.uint16ID())
1621 // Notify members of the private chat that the user has left
1622 for _, c := range sortedClients(privChat.ClientConn) {
1625 tranNotifyChatDeleteUser,
1627 NewField(fieldChatID, chatID),
1628 NewField(fieldUserID, *cc.ID),
1636 // HandleSetChatSubject is sent from a v1.8+ Hotline client when the user sets a private chat subject
1637 // Fields used in the request:
1639 // * 115 Chat subject Chat subject string
1640 // Reply is not expected.
1641 func HandleSetChatSubject(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1642 chatID := t.GetField(fieldChatID).Data
1643 chatInt := binary.BigEndian.Uint32(chatID)
1645 privChat := cc.Server.PrivateChats[chatInt]
1646 privChat.Subject = string(t.GetField(fieldChatSubject).Data)
1648 for _, c := range sortedClients(privChat.ClientConn) {
1651 tranNotifyChatSubject,
1653 NewField(fieldChatID, chatID),
1654 NewField(fieldChatSubject, t.GetField(fieldChatSubject).Data),
1662 // HandleMakeAlias makes a file alias using the specified path.
1663 // Fields used in the request:
1666 // 212 File new path Destination path
1668 // Fields used in the reply:
1670 func HandleMakeAlias(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
1671 if !authorize(cc.Account.Access, accessMakeAlias) {
1672 res = append(res, cc.NewErrReply(t, "You are not allowed to make aliases."))
1675 fileName := t.GetField(fieldFileName).Data
1676 filePath := t.GetField(fieldFilePath).Data
1677 fileNewPath := t.GetField(fieldFileNewPath).Data
1679 fullFilePath, err := readPath(cc.Server.Config.FileRoot, filePath, fileName)
1684 fullNewFilePath, err := readPath(cc.Server.Config.FileRoot, fileNewPath, fileName)
1689 cc.Server.Logger.Debugw("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
1691 if err := FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
1692 res = append(res, cc.NewErrReply(t, "Error creating alias"))
1696 res = append(res, cc.NewReply(t))