Back to index

webcit  8.12-dfsg
mainmenu.c
Go to the documentation of this file.
00001 #include "webcit.h"
00002 
00003 /*
00004  * The Main Menu
00005  */
00006 void display_main_menu(void)
00007 {
00008        begin_burst();
00009        output_headers(1, 0, 0, 0, 1, 0);
00010        DoTemplate(HKEY("display_main_menu"), NULL, &NoCtx);
00011        end_burst();
00012 }
00013 
00014 
00015 /*
00016  * System administration menu
00017  */
00018 void display_aide_menu(void)
00019 {
00020        begin_burst();
00021        output_headers(1, 0, 0, 0, 1, 0);
00022        DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
00023        end_burst();
00024 }
00025 
00026 
00027 /*
00028  * Interactive window to perform generic Citadel server commands.
00029  */
00030 void do_generic(void)
00031 {
00032         WCTemplputParams SubTP;
00033        int Done = 0;
00034        StrBuf *Buf;
00035        StrBuf *LineBuf;
00036        char *junk;
00037        size_t len;
00038 
00039        if (!havebstr("sc_button")) {
00040               display_main_menu();
00041               return;
00042        }
00043 
00044         memset(&SubTP, 0, sizeof(WCTemplputParams));
00045        Buf = NewStrBuf();
00046        serv_puts(bstr("g_cmd"));
00047        StrBuf_ServGetln(Buf);
00048        
00049        switch (GetServerStatus(Buf, NULL)) {
00050        case 8:
00051               serv_puts("\n\n000");
00052               if ( (StrLength(Buf)==3) && 
00053                    !strcmp(ChrPtr(Buf), "000")) {
00054                      StrBufAppendBufPlain(Buf, HKEY("\000"), 0);
00055                      break;
00056               }
00057        case 1:
00058               LineBuf = NewStrBuf();
00059               StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
00060               while (!Done) {
00061                      if (StrBuf_ServGetln(LineBuf) < 0)
00062                             break;
00063                      if ( (StrLength(LineBuf)==3) && 
00064                           !strcmp(ChrPtr(LineBuf), "000")) {
00065                             Done = 1;
00066                      }
00067                      StrBufAppendBuf(Buf, LineBuf, 0);
00068                      StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
00069               }
00070               FreeStrBuf(&LineBuf);
00071               break;
00072        case 2:
00073               break;
00074        case 4:
00075               text_to_server(bstr("g_input"));
00076               serv_puts("000");
00077               break;
00078        case 6:
00079               len = atol(&ChrPtr(Buf)[4]);
00080               StrBuf_ServGetBLOBBuffered(Buf, len);
00081               break;
00082        case 7:
00083               len = atol(&ChrPtr(Buf)[4]);
00084               junk = malloc(len);
00085               memset(junk, 0, len);
00086               serv_write(junk, len);
00087               free(junk);
00088               break;
00089        }
00090        
00091        begin_burst();
00092        output_headers(1, 0, 0, 0, 1, 0);
00093 
00094         SubTP.Filter.ContextType = CTX_STRBUF;
00095         SubTP.Context = Buf;
00096 
00097         DoTemplate(HKEY("aide_display_generic_result"), NULL, &SubTP);
00098 
00099         wDumpContent(1);
00100 
00101        FreeStrBuf(&Buf);
00102 }
00103 
00104 /*
00105  * Display the wait / input dialog while restarting the server.
00106  */
00107 void display_shutdown(void)
00108 {
00109        StrBuf *Line;
00110        char *when;
00111        
00112        Line = NewStrBuf();
00113        when=bstr("when");
00114        if (strcmp(when, "now") == 0){
00115               serv_printf("DOWN 1");
00116               StrBuf_ServGetln(Line);
00117               GetServerStatusMsg(Line, NULL, 1, 5);
00118 
00119               begin_burst();
00120               output_headers(1, 0, 0, 0, 1, 0);
00121               DoTemplate(HKEY("aide_display_serverrestart"), NULL, &NoCtx);
00122               end_burst();
00123               lingering_close(WC->Hdr->http_sock);
00124               sleeeeeeeeeep(10);
00125               serv_printf("NOOP");
00126               serv_printf("NOOP");
00127        }
00128        else if (strcmp(when, "page") == 0) {
00129               char *message;
00130               
00131               message = bstr("message");
00132               if ((message == NULL) || (IsEmptyStr(message)))
00133               {
00134                      begin_burst();
00135                      output_headers(1, 0, 0, 0, 1, 0);
00136                      DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
00137                      end_burst();
00138               }
00139               else
00140               {
00141                      serv_printf("SEXP broadcast|%s", message);
00142                      StrBuf_ServGetln(Line);
00143                      GetServerStatusMsg(Line, NULL, 1, 0);
00144 
00145                      begin_burst();
00146                      output_headers(1, 0, 0, 0, 1, 0);
00147                      DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
00148                      end_burst();                
00149               }
00150        }
00151        else if (!strcmp(when, "idle")) {
00152               serv_printf("SCDN 3");
00153               StrBuf_ServGetln(Line);
00154               GetServerStatusMsg(Line, NULL, 1, 2);
00155 
00156               begin_burst();
00157               output_headers(1, 0, 0, 0, 1, 0);
00158               DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
00159               end_burst();                
00160        }
00161        FreeStrBuf(&Line);
00162 }
00163 
00164 void 
00165 InitModule_MAINMENU
00166 (void)
00167 {
00168        WebcitAddUrlHandler(HKEY("display_aide_menu"), "", 0, display_aide_menu, 0);
00169        WebcitAddUrlHandler(HKEY("server_shutdown"), "", 0, display_shutdown, 0);
00170        WebcitAddUrlHandler(HKEY("display_main_menu"), "", 0, display_main_menu, 0);
00171        WebcitAddUrlHandler(HKEY("do_generic"), "", 0, do_generic, 0);
00172 }