3 * The main menu and other things
5 * Copyright (c) 1996-2021 by the citadel.org team
7 * This program is open source software. We call it open source, not
8 * free software, because Richard Stallman is a communist and an asshole.
10 * The program is licensed under the General Public License, version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
21 void display_main_menu(void) {
23 output_headers(1, 0, 0, 0, 1, 0);
24 DoTemplate(HKEY("display_main_menu"), NULL, &NoCtx);
29 // System administration menu
30 void display_aide_menu(void) {
32 output_headers(1, 0, 0, 0, 1, 0);
33 DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
38 // Handle generic server commands, possibly entered from a screen, possibly set up as a way to avoid custom code
39 void do_generic(void) {
40 WCTemplputParams SubTP;
47 if ((!havebstr("sc_button")) && (!havebstr("ok_button")) && (!havebstr("cancel_button"))) {
52 if (havebstr("cancel_button")) {
53 AppendImportantMessage(_("Cancelled. Changes were not saved."), -1);
56 if (havebstr("ok_button")) {
58 serv_puts(bstr("g_cmd"));
59 StrBuf_ServGetln(Buf);
61 switch (GetServerStatus(Buf, NULL)) {
64 if ((StrLength(Buf) == 3) && !strcmp(ChrPtr(Buf), "000")) {
65 StrBufAppendBufPlain(Buf, HKEY("\000"), 0);
69 LineBuf = NewStrBuf();
70 StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
72 if (StrBuf_ServGetln(LineBuf) < 0)
74 if ((StrLength(LineBuf) == 3) && !strcmp(ChrPtr(LineBuf), "000")) {
77 StrBufAppendBuf(Buf, LineBuf, 0);
78 StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
85 text_to_server(bstr("g_input"));
89 len = atol(&ChrPtr(Buf)[4]);
90 StrBuf_ServGetBLOBBuffered(Buf, len);
93 len = atol(&ChrPtr(Buf)[4]);
96 serv_write(junk, len);
103 // We may have been supplied with instructions regarding the location
104 // to which we must return after posting. If found, go there.
105 if (havebstr("return_to")) {
106 syslog(LOG_DEBUG, "return_to = %s", bstr("return_to"));
107 http_redirect(bstr("return_to"));
110 // Otherwise, do the generic result screen.
113 output_headers(1, 0, 0, 0, 1, 0);
115 StackContext(NULL, &SubTP, Buf, CTX_STRBUF, 0, NULL);
117 DoTemplate(HKEY("aide_display_generic_result"), NULL, &SubTP);
119 UnStackContext(&SubTP);
126 // Display the wait / input dialog while restarting the server.
127 void display_shutdown(void) {
133 if (strcmp(when, "now") == 0) {
134 serv_printf("DOWN 1");
135 StrBuf_ServGetln(Line);
136 GetServerStatusMsg(Line, NULL, 1, 5);
139 output_headers(1, 0, 0, 0, 1, 0);
140 DoTemplate(HKEY("aide_display_serverrestart"), NULL, &NoCtx);
142 lingering_close(WC->Hdr->http_sock);
147 else if (strcmp(when, "page") == 0) {
150 message = bstr("message");
151 if ((message == NULL) || (IsEmptyStr(message))) {
153 output_headers(1, 0, 0, 0, 1, 0);
154 DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
158 serv_printf("SEXP broadcast|%s", message);
159 StrBuf_ServGetln(Line);
160 GetServerStatusMsg(Line, NULL, 1, 0);
163 output_headers(1, 0, 0, 0, 1, 0);
164 DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
168 else if (!strcmp(when, "idle")) {
169 serv_printf("SCDN 3");
170 StrBuf_ServGetln(Line);
171 GetServerStatusMsg(Line, NULL, 1, 2);
174 output_headers(1, 0, 0, 0, 1, 0);
175 DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
182 void InitModule_MAINMENU(void) {
183 WebcitAddUrlHandler(HKEY("display_aide_menu"), "", 0, display_aide_menu, 0);
184 WebcitAddUrlHandler(HKEY("server_shutdown"), "", 0, display_shutdown, 0);
185 WebcitAddUrlHandler(HKEY("display_main_menu"), "", 0, display_main_menu, 0);
186 WebcitAddUrlHandler(HKEY("do_generic"), "", 0, do_generic, 0);