Back to index

webcit  8.12-dfsg
inetconf.c
Go to the documentation of this file.
00001 /* 
00002  * Functions which handle Internet domain configuration etc.
00003  */
00004 
00005 #include "webcit.h"
00006 #include "webserver.h"
00007 
00008 
00009 typedef enum _e_cfg {
00010        ic_localhost,
00011        ic_directory,
00012        ic_smarthost,
00013        ic_fallback,
00014        ic_rbl,
00015        ic_spamass,
00016        ic_masq,
00017        ic_clamav,
00018        ic_notify,
00019        ic_max
00020 } ECfg;
00021 
00022 
00023   /* These are server config keywords; do not localize! */
00024 ConstStr CfgNames[] = {
00025        { HKEY("localhost") },
00026        { HKEY("directory") },
00027        { HKEY("smarthost") },
00028        { HKEY("fallbackhost") },
00029        { HKEY("rbl") },
00030        { HKEY("spamassassin") },
00031        { HKEY("masqdomain") },
00032        { HKEY("clamav") },
00033        { HKEY("notify") }
00034 };
00035 
00036        
00037 
00038 
00039 /*
00040  * display the inet config dialog 
00041  */
00042 void load_inetconf(void)
00043 {
00044        wcsession *WCC = WC;
00045        StrBuf *Buf, *CfgToken, *Value;
00046        void *vHash;
00047        HashList *Hash;
00048        char nnn[64];
00049        int i, len, nUsed;
00050        
00051        WCC->InetCfg = NewHash(1, NULL);
00052 
00053        for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
00054               Hash = NewHash(1, NULL);
00055               Put(WCC->InetCfg, CKEY(CfgNames[i]), Hash, HDeleteHash);
00056        }
00057 
00058        serv_printf("CONF GETSYS|application/x-citadel-internet-config");
00059        Buf = NewStrBuf();
00060        StrBuf_ServGetln(Buf);
00061               
00062        if (GetServerStatus(Buf, NULL) == 1) {
00063               CfgToken = NewStrBuf();
00064               while ((len = StrBuf_ServGetln(Buf),
00065                      ((len >= 0) && 
00066                       ((len != 3) ||
00067                        strcmp(ChrPtr(Buf), "000")))))
00068               {
00069                      Value = NewStrBuf();
00070  
00071                      StrBufExtract_token(CfgToken, Buf, 1, '|');
00072                      StrBufExtract_token(Value, Buf, 0, '|');
00073                      GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
00074                      Hash = (HashList*) vHash;
00075                      if (Hash == NULL) {
00076                             syslog(1, "ERROR Loading inet config line: [%s]\n", 
00077                                    ChrPtr(Buf));
00078                             FreeStrBuf(&Value);
00079                             continue;
00080                      }
00081                      nUsed = GetCount(Hash);
00082                      nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
00083                      Put(Hash, nnn, nUsed, Value, HFreeStrBuf); 
00084               }
00085               FreeStrBuf(&CfgToken);
00086        }
00087        FreeStrBuf(&Buf);
00088 }
00089 
00090 
00091 /*
00092  * save changes to the inet config
00093  */
00094 void new_save_inetconf(void) {
00095        wcsession *WCC = WC;
00096        HashList *Hash;
00097        StrBuf *Str;
00098        StrBuf *Buf;
00099        const StrBuf *eType, *eNum, *eName;
00100        char nnn[64];
00101        void *vHash, *vStr;
00102        int i, nUsed;
00103 
00104        load_inetconf();
00105        eType = sbstr("etype");
00106 
00107        GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
00108        Hash = (HashList*) vHash;
00109        if (Hash == NULL) {
00110               AppendImportantMessage(_("Invalid Parameter"), -1);
00111               url_do_template();
00112               return;
00113        }
00114 
00115        if (strcasecmp(bstr("oper"), "delete") == 0) {
00116               eNum = sbstr("ename");
00117               if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
00118                   (vStr == NULL)) {
00119                      AppendImportantMessage(_("Invalid Parameter"), -1);
00120                      url_do_template();
00121                      return;
00122               }
00123 
00124               Str = (StrBuf*)vStr;
00125               AppendImportantMessage(SKEY(Str));
00126               AppendImportantMessage(_(" has been deleted."), -1);
00127               FlushStrBuf(Str);    
00128        }
00129        else if (!strcasecmp(bstr("oper"), "add")) {
00130               StrBuf *name;
00131               eName = sbstr("ename");
00132               if (eName == NULL) {
00133                      AppendImportantMessage(_("Invalid Parameter"), -1);
00134                      url_do_template();
00135                      return;
00136               }
00137 
00138               nUsed = GetCount(Hash);
00139               nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
00140               name = NewStrBufDup(eName);
00141               StrBufTrim(name);
00142               Put(Hash, nnn, nUsed, name, HFreeStrBuf); 
00143               AppendImportantMessage(SKEY(eName));
00144               AppendImportantMessage( /*<domain> added status message*/ _(" added."), -1); 
00145        }
00146 
00147        Buf = NewStrBuf();
00148        serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
00149        StrBuf_ServGetln(Buf);
00150        if (GetServerStatus(Buf, NULL) == 4) {
00151               for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
00152                      HashPos *where;
00153                      const char *Key;
00154                      long KeyLen;
00155 
00156                      GetHash(WCC->InetCfg, CKEY(CfgNames[i]), &vHash);
00157                      Hash = (HashList*) vHash;
00158                      if (Hash == NULL) {
00159                             AppendImportantMessage(_("Invalid Parameter"), -1);
00160                             url_do_template();
00161                             return;
00162                      }
00163                      if (GetCount(Hash) > 0) {
00164                             where = GetNewHashPos(Hash, 0);
00165                             while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
00166                                    Str = (StrBuf*) vStr;
00167                                    if ((Str!= NULL) && (StrLength(Str) > 0))
00168                                           serv_printf("%s|%s", 
00169                                                      ChrPtr(Str),
00170                                                      CfgNames[i].Key); 
00171                             }
00172                             DeleteHashPos(&where);
00173                      }                    
00174               }
00175               serv_puts("000");
00176               DeleteHash(&WCC->InetCfg);
00177        }
00178        FreeStrBuf(&Buf);
00179        url_do_template();
00180 }
00181 
00182 void DeleteInetConfHash(StrBuf *Target, WCTemplputParams *TP)
00183 {
00184        wcsession *WCC = WC;
00185 
00186        if (WCC->InetCfg != NULL)
00187               DeleteHash(&WCC->InetCfg);
00188 
00189 }
00190 
00191 
00192 HashList *GetInetConfHash(StrBuf *Target, WCTemplputParams *TP)
00193 {
00194        wcsession *WCC = WC;
00195        void *vHash;
00196 
00197        if (WCC->InetCfg == NULL)
00198               load_inetconf();
00199        GetHash(WCC->InetCfg, TKEY(5), &vHash);
00200        PutBstr(HKEY("__SERVCFG:INET:TYPE"), NewStrBufPlain(TKEY(5)));
00201        return vHash;
00202 }
00203 
00204 void 
00205 InitModule_INETCONF
00206 (void)
00207 {
00208        WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
00209        RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
00210        RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInetConfHash, NULL, CTX_NONE);
00211 }