2 * Lots of different room-related operations.
4 * Copyright (c) 1996-2016 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
18 ConstStr QRFlagList[] = {
19 {HKEY(strof(QR_PERMANENT))},
20 {HKEY(strof(QR_INUSE))},
21 {HKEY(strof(QR_PRIVATE))},
22 {HKEY(strof(QR_PASSWORDED))},
23 {HKEY(strof(QR_GUESSNAME))},
24 {HKEY(strof(QR_DIRECTORY))},
25 {HKEY(strof(QR_UPLOAD))},
26 {HKEY(strof(QR_DOWNLOAD))},
27 {HKEY(strof(QR_VISDIR))},
28 {HKEY(strof(QR_ANONONLY))},
29 {HKEY(strof(QR_ANONOPT))},
30 {HKEY(strof(QR_NETWORK))},
31 {HKEY(strof(QR_PREFONLY))},
32 {HKEY(strof(QR_READONLY))},
33 {HKEY(strof(QR_MAILBOX))}
35 ConstStr QR2FlagList[] = {
36 {HKEY(strof(QR2_SYSTEM))},
37 {HKEY(strof(QR2_SELFLIST))},
38 {HKEY(strof(QR2_COLLABDEL))},
39 {HKEY(strof(QR2_SUBJECTREQ))},
40 {HKEY(strof(QR2_SMTP_PUBLIC))},
41 {HKEY(strof(QR2_MODERATED))},
42 {HKEY(strof(QR2_NOUPLMSG))},
59 QRVec = NewStrBufPlain(NULL, 256);
63 if (StrLength(QRVec) > 0)
64 StrBufAppendBufPlain(QRVec, HKEY(" | "), 0);
65 StrBufAppendBufPlain(QRVec, CKEY(QRFlagList[j]), 0);
70 syslog(LOG_DEBUG, "DBG: QR-Vec [%ld] [%s]\n", QR, ChrPtr(QRVec));
76 void _DBG_QR2(long QR2)
82 QR2Vec = NewStrBufPlain(NULL, 256);
86 if (StrLength(QR2Vec) > 0)
87 StrBufAppendBufPlain(QR2Vec, HKEY(" | "), 0);
88 StrBufAppendBufPlain(QR2Vec, CKEY(QR2FlagList[j]), 0);
93 syslog(LOG_DEBUG, "DBG: QR2-Vec [%ld] [%s]\n", QR2, ChrPtr(QR2Vec));
107 /*******************************************************************************
108 ***************************** Goto Commands ***********************************
109 ******************************************************************************/
112 smart_goto(sbstr("room"));
116 if (!havebstr("room")) {
117 readloop(readnew, eUseDefault);
120 if (WC->CurRoom.view != VIEW_MAILBOX) {
121 /* dotgoto acts like dotskip when we're in a mailbox view */
124 smart_goto(sbstr("room"));
130 void smart_goto(const StrBuf *next_room) {
131 if (gotoroom(next_room) / 100 == 2)
132 readloop(readnew, eUseDefault);
138 * goto a private room
140 void goto_private(void)
144 const StrBuf *gr_name;
147 if (!havebstr("ok_button")) {
151 gr_name = sbstr("gr_name");
153 strcpy(hold_rm, ChrPtr(WC->CurRoom.name));
154 serv_printf("GOTO %s|%s",
157 StrBuf_ServGetln(Buf);
158 if (GetServerStatus(Buf, &err) == 2) {
165 DoTemplate(HKEY("room_display_private"), NULL, &NoCtx);
169 StrBufCutLeft(Buf, 4);
170 AppendImportantMessage (SKEY(Buf));
171 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
178 * back end routine to take the session to a new room
180 long gotoroom(const StrBuf *gname)
184 static long ls = (-1L);
186 int room_name_supplied = 0;
190 /* on fail, should we fallback to _BASEROOM_? */
191 failvisibly = ibstr("failvisibly");
193 /* store ungoto information */
194 if (StrLength(gname) > 0) {
195 room_name_supplied = 1;
197 if (room_name_supplied) {
198 strcpy(WCC->ugname, ChrPtr(WCC->CurRoom.name));
199 if (!strcasecmp(ChrPtr(gname), "_BASEROOM_")) {
206 /* move to the new room */
207 if (room_name_supplied) {
208 serv_printf("GOTO %s", ChrPtr(gname));
211 /* or just refresh the current state... */
212 serv_printf("GOTO 00000000000000000000");
214 StrBuf_ServGetln(Buf);
215 if (GetServerStatus(Buf, &err) != 2) {
220 serv_puts("GOTO _BASEROOM_");
221 StrBuf_ServGetln(Buf);
223 * well, we know that this is the fallback case,
224 * but we're interested that the first command
225 * didn't work out in first place.
227 if (GetServerStatus(Buf, NULL) != 2) {
232 FlushFolder(&WCC->CurRoom);
233 ParseGoto(&WCC->CurRoom, Buf);
235 if (room_name_supplied) {
236 remove_march(WCC->CurRoom.name);
248 void ParseGoto(folder *room, StrBuf *Line)
256 if (StrLength(Line) < 4) {
260 /* ignore the commandstate... */
261 Pos = ChrPtr(Line) + 4;
263 if (room->RoomNameParts != NULL)
266 for (i=0; i < room->nRoomNameParts; i++)
267 FreeStrBuf(&room->RoomNameParts[i]);
268 free(room->RoomNameParts);
269 room->RoomNameParts = NULL;
274 pBuf = NewStrBufPlain(NULL, StrLength(Line));
277 memset(room, 0, sizeof(folder));
280 StrBufExtract_NextToken(room->name, Line, &Pos, '|');
282 room->nNewMessages = StrBufExtractNext_long(Line, &Pos, '|');
283 if (room->nNewMessages > 0)
284 room->RAFlags |= UA_HASNEWMSGS;
286 room->nTotalMessages = StrBufExtractNext_long(Line, &Pos, '|');
288 room->ShowInfo = StrBufExtractNext_long(Line, &Pos, '|');
290 room->QRFlags = StrBufExtractNext_long(Line, &Pos, '|');
292 DBG_QR(room->QRFlags);
294 room->HighestRead = StrBufExtractNext_long(Line, &Pos, '|');
295 room->LastMessageRead = StrBufExtractNext_long(Line, &Pos, '|');
297 room->is_inbox = StrBufExtractNext_long(Line, &Pos, '|');
299 flag = StrBufExtractNext_long(Line, &Pos, '|');
300 if (WCC->is_aide || flag) {
301 room->RAFlags |= UA_ADMINALLOWED;
304 room->UsersNewMAilboxMessages = StrBufExtractNext_long(Line, &Pos, '|');
306 room->floorid = StrBufExtractNext_int(Line, &Pos, '|');
308 room->view = StrBufExtractNext_long(Line, &Pos, '|');
310 room->defview = StrBufExtractNext_long(Line, &Pos, '|');
312 flag = StrBufExtractNext_long(Line, &Pos, '|');
314 room->RAFlags |= UA_ISTRASH;
316 room->QRFlags2 = StrBufExtractNext_long(Line, &Pos, '|');
317 DBG_QR2(room->QRFlags2);
319 /* find out, whether we are in a sub-room */
320 room->nRoomNameParts = StrBufNum_tokens(room->name, '\\');
321 if (room->nRoomNameParts > 1)
326 room->RoomNameParts = malloc(sizeof(StrBuf*) * (room->nRoomNameParts + 1));
327 memset(room->RoomNameParts, 0, sizeof(StrBuf*) * (room->nRoomNameParts + 1));
328 for (i=0; i < room->nRoomNameParts; i++)
330 room->RoomNameParts[i] = NewStrBuf();
331 StrBufExtract_NextToken(room->RoomNameParts[i],
332 room->name, &Pos, '\\');
336 /* Private mailboxes on the main floor get remapped to the personal folder */
337 if ((room->QRFlags & QR_MAILBOX) &&
338 (room->floorid == 0))
340 room->floorid = VIRTUAL_MY_FLOOR;
341 if ((room->nRoomNameParts == 1) &&
342 (StrLength(room->name) == 4) &&
343 (strcmp(ChrPtr(room->name), "Mail") == 0))
349 /* get a pointer to the floor we're on: */
350 if (WCC->Floors == NULL)
351 GetFloorListHash(NULL, NULL);
353 GetHash(WCC->Floors, IKEY(room->floorid), &vFloor);
354 room->Floor = (const Floor*) vFloor;
358 * Delete the current room
360 void delete_room(void)
362 StrBuf *Line = NewStrBuf();
363 const StrBuf *GoBstr;
365 GoBstr = sbstr("go");
369 if (gotoroom(GoBstr) == 200)
372 StrBuf_ServGetln(Line);
373 if (GetServerStatusMsg(Line, NULL, 1, 2) == 2) {
377 Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
395 StrBuf *final_destination;
398 * If the forget-room routine fails for any reason, we fall back
399 * to the current room; otherwise, we go to the Lobby
401 final_destination = NewStrBufDup(WC->CurRoom.name);
403 if (havebstr("ok_button")) {
404 serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
405 serv_getln(buf, sizeof buf);
408 serv_getln(buf, sizeof buf);
410 FlushStrBuf(final_destination);
411 StrBufAppendBufPlain(final_destination, HKEY("_BASEROOM_"), 0);
416 smart_goto(final_destination);
417 FreeStrBuf(&final_destination);
422 * mark all messages in current room as having been read
424 void slrp_highest(void)
428 serv_puts("SLRP HIGHEST");
429 serv_getln(buf, sizeof buf);
445 /*******************************************************************************
446 ***************************** Modify Rooms ************************************
447 ******************************************************************************/
453 void LoadRoomAide(void)
458 if (WCC->CurRoom.RoomAideLoaded)
461 WCC->CurRoom.RoomAideLoaded = 1;
464 StrBuf_ServGetln(Buf);
465 if (GetServerStatus(Buf, NULL) != 2) {
466 FlushStrBuf(WCC->CurRoom.RoomAide);
467 AppendImportantMessage (ChrPtr(Buf) + 4,
472 Pos = ChrPtr(Buf) + 4;
474 FreeStrBuf(&WCC->CurRoom.RoomAide);
475 WCC->CurRoom.RoomAide = NewStrBufPlain (NULL, StrLength (Buf));
477 StrBufExtract_NextToken(WCC->CurRoom.RoomAide, Buf, &Pos, '|');
482 int SaveRoomAide(folder *Room)
486 serv_printf("SETA %s", ChrPtr(Room->RoomAide));
487 StrBuf_ServGetln(Buf);
488 if (GetServerStatus(Buf, NULL) != 2) {
489 StrBufCutLeft(Buf, 4);
490 AppendImportantMessage (SKEY(Buf));
499 int GetCurrentRoomFlags(folder *Room, int CareForStatusMessage)
505 StrBuf_ServGetln(Buf);
506 if (GetServerStatus(Buf, NULL) != 2) {
507 FlushStrBuf(Room->XAPass);
508 FlushStrBuf(Room->Directory);
509 StrBufCutLeft(Buf, 4);
510 if (CareForStatusMessage)
511 AppendImportantMessage (SKEY(Buf));
518 Pos = ChrPtr(Buf) + 4;
520 FreeStrBuf(&Room->XAPass);
521 FreeStrBuf(&Room->Directory);
523 Room->XAPass = NewStrBufPlain (NULL, StrLength (Buf));
524 Room->Directory = NewStrBufPlain (NULL, StrLength (Buf));
526 FreeStrBuf(&Room->name);
527 Room->name = NewStrBufPlain(NULL, StrLength(Buf));
528 StrBufExtract_NextToken(Room->name, Buf, &Pos, '|');
530 StrBufExtract_NextToken(Room->XAPass, Buf, &Pos, '|');
531 StrBufExtract_NextToken(Room->Directory, Buf, &Pos, '|');
533 Room->QRFlags = StrBufExtractNext_long(Buf, &Pos, '|');
534 Room->floorid = StrBufExtractNext_long(Buf, &Pos, '|');
535 Room->Order = StrBufExtractNext_long(Buf, &Pos, '|');
536 Room->defview = StrBufExtractNext_long(Buf, &Pos, '|');
537 Room->QRFlags2 = StrBufExtractNext_long(Buf, &Pos, '|');
545 int SetCurrentRoomFlags(folder *Room)
550 DBG_QR(Room->QRFlags);
551 DBG_QR2(Room->QRFlags2);
553 serv_printf("SETR %s|%s|%s|%ld|%d|%d|%ld|%ld|%ld",
555 ChrPtr(Room->XAPass),
556 ChrPtr(Room->Directory),
564 StrBuf_ServGetln(Buf);
565 if (GetServerStatus(Buf, NULL) != 2) {
566 StrBufCutLeft(Buf, 4);
567 AppendImportantMessage (SKEY(Buf));
576 void LoadRoomXA (void)
580 if (WCC->CurRoom.XALoaded > 0)
583 GetCurrentRoomFlags(&WCC->CurRoom, 0);
587 void LoadXRoomPic(void)
593 if (WCC->CurRoom.XHaveRoomPicLoaded) {
597 WCC->CurRoom.XHaveRoomPicLoaded = 1;
600 StrBuf_ServGetln(Buf);
601 if (GetServerStatus(Buf, NULL) == 6) {
602 StrBufCutLeft(Buf, 4);
603 bytes = StrBufExtract_long(Buf, 0, '|');
604 WCC->CurRoom.XHaveRoomPic = 1;
605 StrBuf_ServGetBLOBBuffered(Buf, bytes); // discard the data
607 WCC->CurRoom.XHaveRoomPic = 0;
613 void LoadXRoomInfoText(void)
619 if (WCC->CurRoom.XHaveInfoTextLoaded) {
623 WCC->CurRoom.XHaveInfoTextLoaded = 1;
628 StrBuf_ServGetln(Buf);
629 if (GetServerStatus(Buf, NULL) == 1) {
630 WCC->CurRoom.XInfoText = NewStrBuf ();
632 while (!Done && StrBuf_ServGetln(Buf)>=0) {
633 if ( (StrLength(Buf)==3) &&
634 !strcmp(ChrPtr(Buf), "000"))
637 StrBufAppendBuf(WCC->CurRoom.XInfoText, Buf, 0);
645 void LoadXRoomXCountFiles(void)
651 if (WCC->CurRoom.XHaveDownloadCount)
654 WCC->CurRoom.XHaveDownloadCount = 1;
658 StrBuf_ServGetln(Buf);
659 if (GetServerStatus(Buf, NULL) == 1) {
661 while (!Done && StrBuf_ServGetln(Buf)>=0) {
662 if ( (StrLength(Buf)==3) &&
663 !strcmp(ChrPtr(Buf), "000"))
666 WCC->CurRoom.XDownloadCount++;
675 * Toggle self-service list subscription
677 void toggle_self_service(void) {
680 if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0)
683 if (yesbstr("QR2_SelfList"))
684 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SELFLIST;
686 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SELFLIST;
688 if (yesbstr("QR2_SMTP_PUBLIC"))
689 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
691 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
693 if (yesbstr("QR2_Moderated"))
694 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_MODERATED;
696 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_MODERATED;
697 if (yesbstr("QR2_SubsOnly"))
698 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 | QR2_SMTP_PUBLIC;
700 WCC->CurRoom.QRFlags2 = WCC->CurRoom.QRFlags2 & ~QR2_SMTP_PUBLIC;
702 SetCurrentRoomFlags (&WCC->CurRoom);
704 output_headers(1, 1, 1, 0, 0, 0);
705 do_template("room_edit");
712 * save new parameters for a room
718 const StrBuf *er_name;
719 const StrBuf *er_password;
720 const StrBuf *er_dirname;
721 const StrBuf *er_roomaide;
725 templ = sbstr("template");
726 if (!havebstr("ok_button")) {
727 putlbstr("success", 0);
728 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
730 output_headers(1, 0, 0, 0, 0, 0);
731 DoTemplate(SKEY(templ), NULL, &NoCtx);
735 output_headers(1, 1, 1, 0, 0, 0);
736 do_template("room_edit");
742 if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0) {
743 putlbstr("success", 0);
745 output_headers(1, 0, 0, 0, 0, 0);
746 DoTemplate(SKEY(templ), NULL, &NoCtx);
750 output_headers(1, 1, 1, 0, 0, 0);
751 do_template("room_edit");
758 WCC->CurRoom.QRFlags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
761 if (!strcmp(ChrPtr(Ptr), "invonly")) {
762 WCC->CurRoom.QRFlags |= (QR_PRIVATE);
764 if (!strcmp(ChrPtr(Ptr), "hidden")) {
765 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_GUESSNAME);
767 if (!strcmp(ChrPtr(Ptr), "passworded")) {
768 WCC->CurRoom.QRFlags |= (QR_PRIVATE | QR_PASSWORDED);
770 if (!strcmp(ChrPtr(Ptr), "personal")) {
771 WCC->CurRoom.QRFlags |= QR_MAILBOX;
773 WCC->CurRoom.QRFlags &= ~QR_MAILBOX;
776 if (yesbstr("prefonly")) {
777 WCC->CurRoom.QRFlags |= QR_PREFONLY;
779 WCC->CurRoom.QRFlags &= ~QR_PREFONLY;
782 if (yesbstr("readonly")) {
783 WCC->CurRoom.QRFlags |= QR_READONLY;
785 WCC->CurRoom.QRFlags &= ~QR_READONLY;
788 if (yesbstr("collabdel")) {
789 WCC->CurRoom.QRFlags2 |= QR2_COLLABDEL;
791 WCC->CurRoom.QRFlags2 &= ~QR2_COLLABDEL;
794 if (yesbstr("permanent")) {
795 WCC->CurRoom.QRFlags |= QR_PERMANENT;
797 WCC->CurRoom.QRFlags &= ~QR_PERMANENT;
800 if (yesbstr("subjectreq")) {
801 WCC->CurRoom.QRFlags2 |= QR2_SUBJECTREQ;
803 WCC->CurRoom.QRFlags2 &= ~QR2_SUBJECTREQ;
806 if (yesbstr("network")) {
807 WCC->CurRoom.QRFlags |= QR_NETWORK;
809 WCC->CurRoom.QRFlags &= ~QR_NETWORK;
812 if (yesbstr("directory")) {
813 WCC->CurRoom.QRFlags |= QR_DIRECTORY;
815 WCC->CurRoom.QRFlags &= ~QR_DIRECTORY;
818 if (yesbstr("ulallowed")) {
819 WCC->CurRoom.QRFlags |= QR_UPLOAD;
821 WCC->CurRoom.QRFlags &= ~QR_UPLOAD;
824 if (yesbstr("dlallowed")) {
825 WCC->CurRoom.QRFlags |= QR_DOWNLOAD;
827 WCC->CurRoom.QRFlags &= ~QR_DOWNLOAD;
830 if (yesbstr("ulmsg")) {
831 WCC->CurRoom.QRFlags2 |= QR2_NOUPLMSG;
833 WCC->CurRoom.QRFlags2 &= ~QR2_NOUPLMSG;
836 if (yesbstr("visdir")) {
837 WCC->CurRoom.QRFlags |= QR_VISDIR;
839 WCC->CurRoom.QRFlags &= ~QR_VISDIR;
844 WCC->CurRoom.QRFlags &= ~(QR_ANONONLY | QR_ANONOPT);
845 if (!strcmp(ChrPtr(Ptr), "anononly"))
846 WCC->CurRoom.QRFlags |= QR_ANONONLY;
847 if (!strcmp(ChrPtr(Ptr), "anon2"))
848 WCC->CurRoom.QRFlags |= QR_ANONOPT;
850 er_name = sbstr("er_name");
851 er_dirname = sbstr("er_dirname");
852 er_roomaide = sbstr("er_roomaide");
853 er_password = sbstr("er_password");
855 FlushStrBuf(WCC->CurRoom.name);
856 StrBufAppendBuf(WCC->CurRoom.name, er_name, 0);
858 FlushStrBuf(WCC->CurRoom.Directory);
859 StrBufAppendBuf(WCC->CurRoom.Directory, er_dirname, 0);
861 FlushStrBuf(WCC->CurRoom.RoomAide);
862 StrBufAppendBuf(WCC->CurRoom.RoomAide, er_roomaide, 0);
864 FlushStrBuf(WCC->CurRoom.XAPass);
865 StrBufAppendBuf(WCC->CurRoom.XAPass, er_password, 0);
867 WCC->CurRoom.BumpUsers = yesbstr("bump");
869 WCC->CurRoom.floorid = ibstr("er_floor");
871 succ1 = SetCurrentRoomFlags(&WCC->CurRoom);
873 succ2 = SaveRoomAide (&WCC->CurRoom);
875 if (succ1 + succ2 == 0) {
876 putlbstr("success", 1);
877 AppendImportantMessage (_("Your changes have been saved."), -1);
880 putlbstr("success", 0);
883 output_headers(1, 0, 0, 0, 0, 0);
884 DoTemplate(SKEY(templ), NULL, &NoCtx);
888 output_headers(1, 1, 1, 0, 0, 0);
889 do_template("room_edit");
898 * Display form for Invite, Kick, and show Who Knows a room
900 void do_invt_kick(void)
903 const StrBuf *UserNames;
908 if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1)
911 UserNames = sbstr("username");
912 Kick = havebstr("kick_button");
913 Invite = havebstr("invite_button");
915 User = NewStrBufPlain(NULL, StrLength(UserNames));
918 Pos = ChrPtr(UserNames);
919 while (Pos != StrBufNOTNULL)
921 StrBufExtract_NextToken(User, UserNames, &Pos, ',');
923 if ((StrLength(User) > 0) && (Kick))
925 serv_printf("KICK %s", ChrPtr(User));
926 if (StrBuf_ServGetln(Buf) < 0)
928 if (GetServerStatus(Buf, NULL) != 2) {
929 StrBufCutLeft(Buf, 4);
930 AppendImportantMessage(SKEY(Buf));
933 _("User '%s' kicked out of room '%s'."),
935 ChrPtr(WCC->CurRoom.name)
937 AppendImportantMessage(SKEY(Buf));
940 else if ((StrLength(User) > 0) && (Invite))
942 serv_printf("INVT %s", ChrPtr(User));
943 if (StrBuf_ServGetln(Buf) < 0)
945 if (GetServerStatus(Buf, NULL) != 2) {
946 StrBufCutLeft(Buf, 4);
947 AppendImportantMessage(SKEY(Buf));
950 _("User '%s' invited to room '%s'."),
952 ChrPtr(WCC->CurRoom.name)
954 AppendImportantMessage(SKEY(Buf));
960 output_headers(1, 1, 1, 0, 0, 0);
961 do_template("room_edit");
972 const StrBuf *er_name;
973 const StrBuf *er_type;
974 const StrBuf *er_password;
975 const StrBuf *template;
981 template = sbstr("template");
982 if ((WCC == NULL) || !havebstr("ok_button")) {
983 putlbstr("success", 0);
984 AppendImportantMessage(_("Cancelled. No new room was created."), -1);
985 if (template != NULL) {
986 output_headers(1, 0, 0, 0, 0, 0);
987 DoTemplate(SKEY(template), NULL, &NoCtx);
995 er_name = sbstr("er_name");
996 er_type = sbstr("type");
997 er_password = sbstr("er_password");
998 er_floor = ibstr("er_floor");
999 er_view = ibstr("er_view");
1002 if (!strcmp(ChrPtr(er_type), "hidden"))
1004 else if (!strcmp(ChrPtr(er_type), "passworded"))
1006 else if (!strcmp(ChrPtr(er_type), "invonly"))
1008 else if (!strcmp(ChrPtr(er_type), "personal"))
1011 serv_printf("CRE8 1|%s|%d|%s|%d|%d|%d",
1014 ChrPtr(er_password),
1020 StrBuf_ServGetln(Line);
1021 if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
1022 putlbstr("success", 0);
1024 if (template != NULL) {
1025 output_headers(1, 0, 0, 0, 0, 0);
1026 DoTemplate(SKEY(template), NULL, &NoCtx);
1030 display_main_menu();
1034 /** TODO: Room created, now update the left hand icon bar for this user */
1037 serv_printf("VIEW %d", er_view);
1038 StrBuf_ServGetln(Line);
1039 FreeStrBuf(&Line); /* TODO: should we care about errors? */
1040 WCC->CurRoom.view = er_view;
1042 putlbstr("success", 1);
1043 if (template != NULL) {
1044 output_headers(1, 0, 0, 0, 0, 0);
1045 DoTemplate(SKEY(template), NULL, &NoCtx);
1048 else if ( (WCC->CurRoom.RAFlags & UA_ADMINALLOWED) != 0) {
1049 output_headers(1, 1, 1, 0, 0, 0);
1050 do_template("room_edit");
1053 smart_goto(WCC->CurRoom.name);
1063 * Change the view for this room
1065 void change_view(void) {
1069 newview = lbstr("view");
1070 serv_printf("VIEW %d", newview);
1071 serv_getln(buf, sizeof buf);
1072 WC->CurRoom.view = newview;
1073 smart_goto(WC->CurRoom.name);
1079 * Set the message expire policy for this room and/or floor
1081 void set_room_policy(void) {
1084 if (!havebstr("ok_button")) {
1085 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
1086 output_headers(1, 1, 1, 0, 0, 0);
1087 do_template("room_edit");
1094 serv_printf("SPEX room|%d|%d", ibstr("roompolicy"), ibstr("roomvalue"));
1095 StrBuf_ServGetln(Line);
1096 GetServerStatusMsg(Line, NULL, 1, 0);
1097 if (WC->axlevel >= 6) {
1098 serv_printf("SPEX floor|%d|%d", ibstr("floorpolicy"), ibstr("floorvalue"));
1099 StrBuf_ServGetln(Line);
1100 GetServerStatusMsg(Line, NULL, 1, 0);
1103 ReloadCurrentRoom();
1105 output_headers(1, 1, 1, 0, 0, 0);
1106 do_template("room_edit");
1113 * Perform changes to a room's network configuration
1115 void netedit(void) {
1126 int malias_set_default = 0;
1131 if (havebstr("force_room")) {
1132 gotoroom(sbstr("force_room"));
1134 /*/ TODO: do line dynamic! */
1135 if (havebstr("line_pop3host")) {
1136 strcpy(line, bstr("prefix"));
1137 strcat(line, bstr("line_pop3host"));
1139 strcat(line, bstr("line_pop3user"));
1141 strcat(line, bstr("line_pop3pass"));
1143 strcat(line, ibstr("line_pop3keep") ? "1" : "0" );
1145 sprintf(&line[strlen(line)],"%ld", lbstr("line_pop3int"));
1146 strcat(line, bstr("suffix"));
1148 else if (havebstr("line")) {
1149 strcpy(line, bstr("prefix"));
1150 strcat(line, bstr("line"));
1151 strcat(line, bstr("suffix"));
1153 else if (havebstr("alias")) {
1155 domain = bstr("aliasdomain");
1156 if ((domain == NULL) || IsEmptyStr(domain))
1158 malias_set_default = 1;
1159 strcpy(line, bstr("prefix"));
1160 strcat(line, bstr("default_aliasdomain"));
1166 strcat(line, bstr("prefix"));
1167 if (!IsEmptyStr(domain))
1170 strcat(line, domain);
1173 strcat(line, "room_");
1174 strcat(line, ChrPtr(WC->CurRoom.name));
1178 output_headers(1, 1, 1, 0, 0, 0);
1179 do_template("room_edit");
1185 TmpBuf = NewStrBuf();
1187 serv_puts("GNET "FILE_MAILALIAS);
1190 StrBuf_ServGetln(Line);
1191 if (GetServerStatus(Line, NULL) != 1) {
1192 AppendImportantMessage(SRV_STATUS_MSG(Line));
1194 output_headers(1, 1, 1, 0, 0, 0);
1195 do_template("room_edit");
1200 /** This loop works for add *or* remove. Spiffy, eh? */
1202 extract_token(cmpb0, line, 0, sepchar, sizeof cmpb0);
1203 extract_token(cmpb1, line, 1, sepchar, sizeof cmpb1);
1204 while (!Done && StrBuf_ServGetln(Line)>=0) {
1205 if ( (StrLength(Line)==3) &&
1206 !strcmp(ChrPtr(Line), "000"))
1212 if (StrLength(Line) == 0)
1215 if (malias_set_default)
1217 if (strncasecmp(ChrPtr(Line), HKEY("roommailalias|")) != 0)
1219 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1220 StrBufAppendBuf(TmpBuf, Line, 0);
1225 extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
1226 extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
1227 if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
1229 StrBufAppendBufPlain(Line, HKEY("\n"), 0);
1230 StrBufAppendBuf(TmpBuf, Line, 0);
1237 serv_puts("SNET "FILE_MAILALIAS);
1240 StrBuf_ServGetln(Line);
1241 if (GetServerStatus(Line, NULL) != 4) {
1243 AppendImportantMessage(SRV_STATUS_MSG(Line));
1244 output_headers(1, 1, 1, 0, 0, 0);
1245 do_template("room_edit");
1248 FreeStrBuf(&TmpBuf);
1252 serv_putbuf(TmpBuf);
1253 FreeStrBuf(&TmpBuf);
1255 if (havebstr("add_button")) {
1256 num_addrs = num_tokens(bstr("line"), ',');
1257 if (num_addrs < 2) {
1258 /* just adding one node or address */
1262 /* adding multiple addresses separated by commas */
1263 for (i=0; i<num_addrs; ++i) {
1264 strcpy(line, bstr("prefix"));
1265 extract_token(buf, bstr("line"), i, ',', sizeof buf);
1268 strcat(line, bstr("suffix"));
1276 StrBuf_ServGetln(Line);
1277 if (GetServerStatus(Line, NULL) != 2) { /* WHOOOPS? ERROR? */
1278 AppendImportantMessage(SRV_STATUS_MSG(Line));
1279 StrBuf_ServGetln(Line); /* resync... */
1283 FlushIgnetCfgs(&WC->CurRoom);
1286 output_headers(1, 1, 1, 0, 0, 0);
1287 do_template("room_edit");
1292 * Known rooms list (box style)
1296 DeleteHash(&WC->Rooms);
1297 output_headers(1, 1, 1, 0, 0, 0);
1298 do_template("knrooms");
1319 /*******************************************************************************
1320 ********************** FLOOR Coomands *****************************************
1321 ******************************************************************************/
1326 * delete the actual floor
1328 void delete_floor(void) {
1333 floornum = ibstr("floornum");
1335 serv_printf("KFLR %d|1", floornum);
1337 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1339 if (GetServerStatus(Buf, NULL) == 2) {
1340 StrBufPlain(Buf, _("Floor has been deleted."),-1);
1343 StrBufCutLeft(Buf, 4);
1345 AppendImportantMessage (SKEY(Buf));
1348 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1353 * start creating a new floor
1355 void create_floor(void) {
1360 serv_printf("CFLR %s|1", bstr("floorname"));
1361 StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err);
1363 if (GetServerStatus(Buf, NULL) == 2) {
1364 StrBufPlain(Buf, _("New floor has been created."),-1);
1367 StrBufCutLeft(Buf, 4);
1369 AppendImportantMessage (SKEY(Buf));
1371 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1379 void rename_floor(void) {
1385 serv_printf("EFLR %d|%s", ibstr("floornum"), bstr("floorname"));
1386 StrBuf_ServGetln(Buf);
1388 StrBufCutLeft(Buf, 4);
1389 AppendImportantMessage (SKEY(Buf));
1391 http_transmit_thing(ChrPtr(do_template("floors")), 0);
1397 void jsonRoomFlr(void)
1399 /* Send as our own (application/json) content type */
1400 hprintf("HTTP/1.1 200 OK\r\n");
1401 hprintf("Content-type: application/json; charset=utf-8\r\n");
1402 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1403 hprintf("Connection: close\r\n");
1404 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1406 DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
1410 void _FlushRoomList(wcsession *WCC)
1412 free_march_list(WCC);
1413 DeleteHash(&WCC->Floors);
1414 DeleteHash(&WCC->Rooms);
1415 DeleteHash(&WCC->FloorsByName);
1416 FlushFolder(&WCC->CurRoom);
1419 void ReloadCurrentRoom(void)
1421 wcsession *WCC = WC;
1424 CurRoom = WCC->CurRoom.name;
1425 WCC->CurRoom.name = NULL;
1426 _FlushRoomList(WCC);
1428 FreeStrBuf(&CurRoom);
1431 void FlushRoomlist(void)
1433 wcsession *WCC = WC;
1434 _FlushRoomList(WCC);
1442 RegisterPreference("roomlistview",
1443 _("Room list view"),
1446 RegisterPreference("emptyfloors", _("Show empty floors"), PRF_YESNO, NULL);
1448 WebcitAddUrlHandler(HKEY("json_roomflr"), "", 0, jsonRoomFlr, 0);
1450 WebcitAddUrlHandler(HKEY("delete_floor"), "", 0, delete_floor, 0);
1451 WebcitAddUrlHandler(HKEY("rename_floor"), "", 0, rename_floor, 0);
1452 WebcitAddUrlHandler(HKEY("create_floor"), "", 0, create_floor, 0);
1454 WebcitAddUrlHandler(HKEY("knrooms"), "", 0, knrooms, ANONYMOUS);
1455 WebcitAddUrlHandler(HKEY("dotgoto"), "", 0, dotgoto, NEED_URL);
1456 WebcitAddUrlHandler(HKEY("dotskip"), "", 0, dotskip, NEED_URL);
1458 WebcitAddUrlHandler(HKEY("goto_private"), "", 0, goto_private, NEED_URL);
1459 WebcitAddUrlHandler(HKEY("zap"), "", 0, zap, 0);
1460 WebcitAddUrlHandler(HKEY("entroom"), "", 0, entroom, 0);
1461 WebcitAddUrlHandler(HKEY("do_invt_kick"), "", 0, do_invt_kick, 0);
1463 WebcitAddUrlHandler(HKEY("netedit"), "", 0, netedit, 0);
1464 WebcitAddUrlHandler(HKEY("editroom"), "", 0, editroom, 0);
1465 WebcitAddUrlHandler(HKEY("delete_room"), "", 0, delete_room, 0);
1466 WebcitAddUrlHandler(HKEY("set_room_policy"), "", 0, set_room_policy, 0);
1467 WebcitAddUrlHandler(HKEY("changeview"), "", 0, change_view, 0);
1468 WebcitAddUrlHandler(HKEY("toggle_self_service"), "", 0, toggle_self_service, 0);
1471 REGISTERTokenParamDefine(QR_PERMANENT);
1472 REGISTERTokenParamDefine(QR_INUSE);
1473 REGISTERTokenParamDefine(QR_PRIVATE);
1474 REGISTERTokenParamDefine(QR_PASSWORDED);
1475 REGISTERTokenParamDefine(QR_GUESSNAME);
1476 REGISTERTokenParamDefine(QR_DIRECTORY);
1477 REGISTERTokenParamDefine(QR_UPLOAD);
1478 REGISTERTokenParamDefine(QR_DOWNLOAD);
1479 REGISTERTokenParamDefine(QR_VISDIR);
1480 REGISTERTokenParamDefine(QR_ANONONLY);
1481 REGISTERTokenParamDefine(QR_ANONOPT);
1482 REGISTERTokenParamDefine(QR_NETWORK);
1483 REGISTERTokenParamDefine(QR_PREFONLY);
1484 REGISTERTokenParamDefine(QR_READONLY);
1485 REGISTERTokenParamDefine(QR_MAILBOX);
1486 REGISTERTokenParamDefine(QR2_SYSTEM);
1487 REGISTERTokenParamDefine(QR2_SELFLIST);
1488 REGISTERTokenParamDefine(QR2_COLLABDEL);
1489 REGISTERTokenParamDefine(QR2_SUBJECTREQ);
1490 REGISTERTokenParamDefine(QR2_SMTP_PUBLIC);
1491 REGISTERTokenParamDefine(QR2_MODERATED);
1492 REGISTERTokenParamDefine(QR2_NOUPLMSG);
1494 REGISTERTokenParamDefine(UA_KNOWN);
1495 REGISTERTokenParamDefine(UA_GOTOALLOWED);
1496 REGISTERTokenParamDefine(UA_HASNEWMSGS);
1497 REGISTERTokenParamDefine(UA_ZAPPED);
1498 REGISTERTokenParamDefine(UA_POSTALLOWED);
1499 REGISTERTokenParamDefine(UA_ADMINALLOWED);
1500 REGISTERTokenParamDefine(UA_DELETEALLOWED);
1501 REGISTERTokenParamDefine(UA_REPLYALLOWED);
1502 REGISTERTokenParamDefine(UA_ISTRASH);
1504 REGISTERTokenParamDefine(US_NEEDVALID);
1505 REGISTERTokenParamDefine(US_PERM);
1506 REGISTERTokenParamDefine(US_LASTOLD);
1507 REGISTERTokenParamDefine(US_EXPERT);
1508 REGISTERTokenParamDefine(US_UNLISTED);
1509 REGISTERTokenParamDefine(US_NOPROMPT);
1510 REGISTERTokenParamDefine(US_PROMPTCTL);
1511 REGISTERTokenParamDefine(US_DISAPPEAR);
1512 REGISTERTokenParamDefine(US_REGIS);
1513 REGISTERTokenParamDefine(US_PAGINATOR);
1514 REGISTERTokenParamDefine(US_INTERNET);
1515 REGISTERTokenParamDefine(US_FLOORS);
1516 REGISTERTokenParamDefine(US_COLOR);
1517 REGISTERTokenParamDefine(US_USER_SET);
1519 REGISTERTokenParamDefine(VIEW_BBS);
1520 REGISTERTokenParamDefine(VIEW_MAILBOX);
1521 REGISTERTokenParamDefine(VIEW_ADDRESSBOOK);
1522 REGISTERTokenParamDefine(VIEW_CALENDAR);
1523 REGISTERTokenParamDefine(VIEW_TASKS);
1524 REGISTERTokenParamDefine(VIEW_NOTES);
1525 REGISTERTokenParamDefine(VIEW_WIKI);
1526 REGISTERTokenParamDefine(VIEW_CALBRIEF);
1527 REGISTERTokenParamDefine(VIEW_JOURNAL);
1528 REGISTERTokenParamDefine(VIEW_BLOG);
1529 REGISTERTokenParamDefine(VIEW_QUEUE);
1532 /* server internal, we need to know but ignore them. */
1533 REGISTERTokenParamDefine(subpending);
1534 REGISTERTokenParamDefine(unsubpending);
1535 REGISTERTokenParamDefine(lastsent);
1537 REGISTERTokenParamDefine(ignet_push_share);
1538 { /* these are the parts of an IGNET push config */
1539 REGISTERTokenParamDefine(GNET_IGNET_NODE);
1540 REGISTERTokenParamDefine(GNET_IGNET_ROOM);
1542 REGISTERTokenParamDefine(listrecp);
1543 REGISTERTokenParamDefine(digestrecp);
1544 REGISTERTokenParamDefine(pop3client);
1545 { /* These are the parts of a pop3 client line... */
1546 REGISTERTokenParamDefine(GNET_POP3_HOST);
1547 REGISTERTokenParamDefine(GNET_POP3_USER);
1548 REGISTERTokenParamDefine(GNET_POP3_DONT_DELETE_REMOTE);
1549 REGISTERTokenParamDefine(GNET_POP3_INTERVAL);
1551 REGISTERTokenParamDefine(rssclient);
1552 REGISTERTokenParamDefine(participate);
1553 REGISTERTokenParamDefine(roommailalias);
1561 SessionDestroyModule_ROOMOPS
1564 _FlushRoomList (sess);