final touches on dkim test harness
[citadel.git] / webcit / inetconf.c
index f4e59fe682294809a6b997affc10ad5a222eeb87..3b7d82de50a5bf6517c9ac200ab88f1158cc9fe9 100644 (file)
@@ -3,7 +3,7 @@
  */
 
 #include "webcit.h"
-#include "webserver.h"
+
 
 
 typedef enum _e_cfg {
@@ -61,20 +61,22 @@ void load_inetconf(void)
                
        if (GetServerStatus(Buf, NULL) == 1) {
                CfgToken = NewStrBuf();
-               while ((len = StrBuf_ServGetln(Buf),
-                       ((len >= 0) && 
-                        ((len != 3) ||
-                         strcmp(ChrPtr(Buf), "000")))))
+               while ((len = StrBuf_ServGetln(Buf), ((len >= 0) && ((len != 3) || strcmp(ChrPtr(Buf), "000")))))
                {
                        Value = NewStrBuf();
                        StrBufExtract_token(CfgToken, Buf, 1, '|');
+
+                       // VILE SLEAZY HACK: change obsolete "directory" domains to "localhost" domains
+                       if (!strcasecmp(ChrPtr(CfgToken), "directory")) {
+                               FreeStrBuf(&CfgToken);
+                               CfgToken = NewStrBufPlain(HKEY("localhost"));
+                       }
+
                        StrBufExtract_token(Value, Buf, 0, '|');
                        GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
                        Hash = (HashList*) vHash;
                        if (Hash == NULL) {
-                               syslog(1, "ERROR Loading inet config line: [%s]\n", 
-                                       ChrPtr(Buf));
+                               syslog(LOG_WARNING, "ERROR Loading inet config line: [%s]", ChrPtr(Buf));
                                FreeStrBuf(&Value);
                                continue;
                        }
@@ -107,7 +109,7 @@ void new_save_inetconf(void) {
        GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
        Hash = (HashList*) vHash;
        if (Hash == NULL) {
-               StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
+               AppendImportantMessage(_("Invalid Parameter"), -1);
                url_do_template();
                return;
        }
@@ -116,20 +118,21 @@ void new_save_inetconf(void) {
                eNum = sbstr("ename");
                if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
                    (vStr == NULL)) {
-                       StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
+                       AppendImportantMessage(_("Invalid Parameter"), -1);
                        url_do_template();
                        return;
                }
 
                Str = (StrBuf*)vStr;
-               StrBufPrintf(WCC->ImportantMsg, _("%s has been deleted."), ChrPtr(Str));
+               AppendImportantMessage(SKEY(Str));
+               AppendImportantMessage(_(" has been deleted."), -1);
                FlushStrBuf(Str);       
        }
        else if (!strcasecmp(bstr("oper"), "add")) {
                StrBuf *name;
                eName = sbstr("ename");
                if (eName == NULL) {
-                       StrBufPrintf(WCC->ImportantMsg, _("Invalid Parameter"));
+                       AppendImportantMessage(_("Invalid Parameter"), -1);
                        url_do_template();
                        return;
                }
@@ -139,9 +142,8 @@ void new_save_inetconf(void) {
                name = NewStrBufDup(eName);
                StrBufTrim(name);
                Put(Hash, nnn, nUsed, name, HFreeStrBuf); 
-               StrBufPrintf(WCC->ImportantMsg, "%s %s", 
-                            /*<domain> added status message*/ _("added."), 
-                            ChrPtr(eName));
+               AppendImportantMessage(SKEY(eName));
+               AppendImportantMessage( /*<domain> added status message*/ _(" added."), -1); 
        }
 
        Buf = NewStrBuf();
@@ -165,9 +167,7 @@ void new_save_inetconf(void) {
                                while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
                                        Str = (StrBuf*) vStr;
                                        if ((Str!= NULL) && (StrLength(Str) > 0))
-                                               serv_printf("%s|%s", 
-                                                           ChrPtr(Str),
-                                                           CfgNames[i].Key); 
+                                               serv_printf("%s|%s", ChrPtr(Str), CfgNames[i].Key); 
                                }
                                DeleteHashPos(&where);
                        }                       
@@ -179,6 +179,7 @@ void new_save_inetconf(void) {
        url_do_template();
 }
 
+
 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
@@ -201,6 +202,48 @@ HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
        return vHash;
 }
 
+
+HashList *GetValidDomainNames(StrBuf *Target, WCTemplputParams *TP) 
+{
+       StrBuf *Line;
+       HashList *ValidDomainNames = NULL;
+       long State;
+       int gvdnlevel = 0;
+       
+       serv_printf("GVDN %d", gvdnlevel);
+       Line = NewStrBuf();
+       StrBuf_ServGetln(Line);
+       if (GetServerStatus(Line, &State) == 1) 
+       {
+               int Done = 0;
+               int n = 0;
+
+               ValidDomainNames = NewHash(1, NULL);
+               while(!Done && (StrBuf_ServGetln(Line) >= 0))
+                       if ( (StrLength(Line)==3) && 
+                            !strcmp(ChrPtr(Line), "000"))
+                       {
+                               Done = 1;
+                       }
+                       else
+                       {
+                               Put(ValidDomainNames, 
+                                   IKEY(n),
+                                   NewStrBufDup(Line), 
+                                   HFreeStrBuf);
+                               n++; /* #0 is the type... */
+                       }
+       }
+       else if (State == 550)
+               AppendImportantMessage(_("Higher access is required to access this function."), -1);
+
+       FreeStrBuf(&Line);
+
+       return ValidDomainNames;
+}
+
+
+
 void 
 InitModule_INETCONF
 (void)
@@ -208,4 +251,5 @@ InitModule_INETCONF
        WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
        RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
        RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);
+       RegisterIterator("ITERATE:VALID:DOMAINNAMES", 1, NULL, GetValidDomainNames, NULL, DeleteHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
 }