LOGGING: add tiny webcit interface to manage log configs
authorWilfried Goesgens <dothebart@citadel.org>
Sat, 5 May 2012 12:08:49 +0000 (14:08 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sat, 5 May 2012 12:08:49 +0000 (14:08 +0200)
webcit/siteconfig.c
webcit/static/t/aide/display_logstatus.html [new file with mode: 0644]
webcit/static/t/aide/display_logstatus_line.html [new file with mode: 0644]
webcit/static/t/aide/global_config.html
webcit/static/wclib.js
webcit/subst.c
webcit/subst.h

index 5cbd56c7d95000168c71ddf52172651ad8c32d1d..91509781466de4b029010cd5852d08e4900f4ac0 100644 (file)
@@ -387,6 +387,73 @@ int ConditionalServCfgCTXStrBuf(StrBuf *Target, WCTemplputParams *TP)
        else return 0;
 }
 
+/*----------------------------------------------------------------------------*
+ *              Displaying Logging                                            *
+ *----------------------------------------------------------------------------*/
+typedef struct __LogStatusStruct {
+       int Enable;
+       StrBuf *Name;
+}LogStatusStruct;
+
+void DeleteLogStatusStruct(void *v)
+{
+       LogStatusStruct *Stat = (LogStatusStruct*)v;
+
+       FreeStrBuf(&Stat->Name);
+       free(Stat);
+}
+
+void tmplput_servcfg_LogName(StrBuf *Target, WCTemplputParams *TP)
+{
+        LogStatusStruct *Stat = (LogStatusStruct*) CTX;
+       StrBufAppendTemplate(Target, TP, Stat->Name, 1);
+}
+
+int ConditionalServCfgThisLogEnabled(StrBuf *Target, WCTemplputParams *TP)
+{
+        LogStatusStruct *Stat = (LogStatusStruct*) CTX;
+       return Stat->Enable;
+}
+
+HashList *iterate_GetSrvLogEnable(StrBuf *Target, WCTemplputParams *TP)
+{
+        HashList *Hash = NULL;
+       StrBuf *Buf;
+       LogStatusStruct *Stat;
+       const char *Pos;
+       int Done = 0;
+       long len;
+       int num_logs = 0;
+
+        serv_puts("LOGP");
+        Buf = NewStrBuf();
+        StrBuf_ServGetln(Buf);
+        if (GetServerStatus(Buf, NULL) == 1) {
+                Hash = NewHash(1, Flathash);
+                while (!Done) {
+                        len = StrBuf_ServGetln(Buf);
+                        if ((len <0) || 
+                            ((len == 3) &&
+                             !strcmp(ChrPtr(Buf), "000")))
+                        {
+                                Done = 1;
+                                break;
+                        }
+                       Stat = (LogStatusStruct*) malloc (sizeof(LogStatusStruct));
+                       Pos = NULL;
+                       Stat->Name = NewStrBufPlain(NULL, len);
+                        StrBufExtract_NextToken(Stat->Name, Buf, &Pos, '|');
+                        Stat->Enable = StrBufExtractNext_int(Buf, &Pos, '|');
+
+                        Put(Hash, IKEY(num_logs), Stat, DeleteLogStatusStruct); 
+                       num_logs++;
+                }
+       }
+       FreeStrBuf(&Buf);
+       return Hash;
+}
+
+
 void 
 InitModule_SITECONFIG
 (void)
@@ -411,6 +478,10 @@ InitModule_SITECONFIG
        RegisterConditional(HKEY("COND:EXPIRE:MODE"), 2, ConditionalExpire, CTX_NONE);
        RegisterNamespace("EXPIRE:VALUE", 1, 2, tmplput_ExpireValue, NULL, CTX_NONE);
        RegisterNamespace("EXPIRE:MODE", 1, 2, tmplput_ExpireMode, NULL, CTX_NONE);
+
+       RegisterConditional(HKEY("COND:SERVCFG:THISLOGENABLE"), 4, ConditionalServCfgThisLogEnabled, CTX_SRVLOG);
+       RegisterIterator("SERVCFG:LOGENABLE", 0, NULL, iterate_GetSrvLogEnable, NULL, DeleteHash, CTX_SRVLOG, CTX_NONE, IT_NOFLAG);
+       RegisterNamespace("SERVCFG:LOGNAME", 0, 1, tmplput_servcfg_LogName, NULL, CTX_SRVLOG);
 }
 
 void 
diff --git a/webcit/static/t/aide/display_logstatus.html b/webcit/static/t/aide/display_logstatus.html
new file mode 100644 (file)
index 0000000..40a88ee
--- /dev/null
@@ -0,0 +1,21 @@
+<?=("head")>
+<div id="banner">
+  <h1>
+    <?_("Temporarily enable debug logging for components")>
+  </h1>
+</div>
+
+<div id="content" class="service">
+    <??("COND:AIDE", 1)>
+    <table border=0 cellspacing="2" cellpadding="2" width=94% class="altern"><tr><td colspan=2>
+
+         <center><?_("This screen allows you to enable debug logging of components of the current citserver process. The setting is non-restart permanent. If you want it to be enabled permanently add it to the CITADEL_LOGDEBUG environment variable in your init script.")><br>
+         </center>
+       </td>
+      </tr>
+           <form method="post" action="do_generic">
+           <?ITERATE("SERVCFG:LOGENABLE", ="aide_display_logstatus_line")>
+           </form>
+    </table>
+    <??("X", 1)>
+<?=("trailing")>
diff --git a/webcit/static/t/aide/display_logstatus_line.html b/webcit/static/t/aide/display_logstatus_line.html
new file mode 100644 (file)
index 0000000..3fbd0cb
--- /dev/null
@@ -0,0 +1,8 @@
+<tr class='<?ITERATE:ODDEVEN>'>
+  <td><?SERVCFG:LOGNAME("X")></td>
+  <td><input type="checkbox" 
+            id="<?SERVCFG:LOGNAME("U")>" 
+            onclick="ToggleLogEnable('<?SERVCFG:LOGNAME("U")>')"
+            <?%("COND:SERVCFG:THISLOGENABLE",  1, 1, 1, "checked", "")> >
+</td>
+</tr>
index fe06f7c4dc0bf0a3a9f5c8fa13724320653720eb..e8019c769f14c55e491f545930658bb789362d64 100644 (file)
@@ -2,5 +2,6 @@
 <li><a href="do_template?template=aide_display_sitewide_config"><?_("Edit site-wide configuration")></a></li>
 <li><a href="do_template?template=aide_display_inetconf"><?_("Domain names and Internet mail configuration")></a></li>
 <li><a href="do_template?template=aide_display_ignetconf"><?_("Configure replication with other Citadel servers")></a></li>
+<li><a href="do_template?template=aide_display_logstatus"><?_("Enable/Disable logging of the server components")></a></li>
 <li><a href="dotskip?room=__CitadelSMTPspoolout__&view=11"><?_("View the outbound SMTP queue")></a></li>
 </ul>
index 3308e56f45b2c22f6275d672f0e6747b411c08c4..c338cb055792c97b83f54a648567f85ed03dcefa 100644 (file)
@@ -54,7 +54,28 @@ function strcmp ( str1, str2 ) {
     return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
 }
 
-
+function CtdlMarkLog($Which, $Status)
+{
+    if ($Status)
+       document.getElementById($Which).checked == false;
+    else
+       document.getElementById($Which).checked == true;
+}
+function ToggleLogEnable($Which)
+{
+    var p;
+    var Status = !document.getElementById($Which).checked;
+    if (Status)
+       p= encodeURI('g_cmd=LOGS ' + $Which + '|0');
+    else
+       p= encodeURI('g_cmd=LOGS ' + $Which + '|1');
+    new Ajax.Request('ajax_servcmd', {
+       method: 'post',
+       parameters: p,
+       onComplete: CtdlMarkLog($Which, Status)
+    });
+}
 
 function ToggleVisibility ($Which)
 {
index 6e5ab6fc690248e63532ddf0408ae3c8bfff4cac..41a352e6878b96373a18fe3b53c1eda7d42b2f04 100644 (file)
@@ -113,6 +113,7 @@ const char *CtxNames[]  = {
        "Context SIEVE Script",
        "Context MailQ-Item",
        "Context MailQ-Recipient",
+       "Context ServLogStatus",
        "Context UNKNOWN"
 };
 
index 3bf4917490473e9e0316606013f4118ad1fc35ec..b44b33a5217061a3a01a8753d3d1a748a46d2070 100644 (file)
@@ -64,8 +64,9 @@ enum {
 #define CTX_SIEVESCRIPT 23
 #define CTX_MAILQITEM 24
 #define CTX_MAILQ_RCPT 25
+#define CTX_SRVLOG 26
 
-#define CTX_UNKNOWN 25
+#define CTX_UNKNOWN 27
 
 
 /**