3 * Functions which handle Internet domain configuration etc.
24 /* These are server config keywords; do not localize! */
25 ConstStr CfgNames[] = {
26 { HKEY("localhost") },
27 { HKEY("directory") },
28 { HKEY("smarthost") },
29 { HKEY("fallbackhost") },
31 { HKEY("spamassassin") },
32 { HKEY("masqdomain") },
41 * display the inet config dialog
43 void load_inetconf(void) {
45 StrBuf *Buf, *CfgToken, *Value;
51 WCC->InetCfg = NewHash(1, NULL);
53 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
54 Hash = NewHash(1, NULL);
55 Put(WCC->InetCfg, CKEY(CfgNames[i]), Hash, HDeleteHash);
58 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
60 StrBuf_ServGetln(Buf);
62 if (GetServerStatus(Buf, NULL) == 1) {
63 CfgToken = NewStrBuf();
64 while ((len = StrBuf_ServGetln(Buf), ((len >= 0) && ((len != 3) || strcmp(ChrPtr(Buf), "000"))))) {
66 StrBufExtract_token(CfgToken, Buf, 1, '|');
68 // VILE SLEAZY HACK: change obsolete "directory" domains to "localhost" domains
69 if (!strcasecmp(ChrPtr(CfgToken), "directory")) {
70 FreeStrBuf(&CfgToken);
71 CfgToken = NewStrBufPlain(HKEY("localhost"));
74 StrBufExtract_token(Value, Buf, 0, '|');
75 GetHash(WCC->InetCfg, ChrPtr(CfgToken), StrLength(CfgToken), &vHash);
76 Hash = (HashList *) vHash;
78 syslog(LOG_WARNING, "ERROR Loading inet config line: [%s]", ChrPtr(Buf));
82 nUsed = GetCount(Hash);
83 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed + 1);
84 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
86 FreeStrBuf(&CfgToken);
93 * save changes to the inet config
95 void new_save_inetconf(void) {
100 const StrBuf *eType, *eNum, *eName;
106 eType = sbstr("etype");
108 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
109 Hash = (HashList *) vHash;
111 AppendImportantMessage(_("Invalid Parameter"), -1);
116 if (strcasecmp(bstr("oper"), "delete") == 0) {
117 eNum = sbstr("ename");
118 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) || (vStr == NULL)) {
119 AppendImportantMessage(_("Invalid Parameter"), -1);
124 Str = (StrBuf *) vStr;
125 AppendImportantMessage(SKEY(Str));
126 AppendImportantMessage(_(" has been deleted."), -1);
129 else if (!strcasecmp(bstr("oper"), "add")) {
131 eName = sbstr("ename");
133 AppendImportantMessage(_("Invalid Parameter"), -1);
138 nUsed = GetCount(Hash);
139 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed + 1);
140 name = NewStrBufDup(eName);
142 Put(Hash, nnn, nUsed, name, HFreeStrBuf);
143 AppendImportantMessage(SKEY(eName));
144 AppendImportantMessage( /*<domain> added status message */ _(" added."), -1);
148 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
149 StrBuf_ServGetln(Buf);
150 if (GetServerStatus(Buf, NULL) == 4) {
151 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStr)); i++) {
156 GetHash(WCC->InetCfg, CKEY(CfgNames[i]), &vHash);
157 Hash = (HashList *) vHash;
159 AppendImportantMessage(_("Invalid Parameter"), -1);
163 if (GetCount(Hash) > 0) {
164 where = GetNewHashPos(Hash, 0);
165 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
166 Str = (StrBuf *) vStr;
167 if ((Str != NULL) && (StrLength(Str) > 0))
168 serv_printf("%s|%s", ChrPtr(Str), CfgNames[i].Key);
170 DeleteHashPos(&where);
174 DeleteHash(&WCC->InetCfg);
181 void DeleteInetConfHash(StrBuf * Target, WCTemplputParams * TP) {
184 if (WCC->InetCfg != NULL)
185 DeleteHash(&WCC->InetCfg);
190 HashList *GetInetConfHash(StrBuf * Target, WCTemplputParams * TP) {
194 if (WCC->InetCfg == NULL)
196 GetHash(WCC->InetCfg, TKEY(5), &vHash);
197 PutBstr(HKEY("__SERVCFG:INET:TYPE"), NewStrBufPlain(TKEY(5)));
202 HashList *GetValidDomainNames(StrBuf * Target, WCTemplputParams * TP) {
204 HashList *ValidDomainNames = NULL;
208 serv_printf("GVDN %d", gvdnlevel);
210 StrBuf_ServGetln(Line);
211 if (GetServerStatus(Line, &State) == 1) {
215 ValidDomainNames = NewHash(1, NULL);
216 while (!Done && (StrBuf_ServGetln(Line) >= 0))
217 if ((StrLength(Line) == 3) && !strcmp(ChrPtr(Line), "000")) {
221 Put(ValidDomainNames, IKEY(n), NewStrBufDup(Line), HFreeStrBuf);
222 n++; /* #0 is the type... */
225 else if (State == 550)
226 AppendImportantMessage(_("Higher access is required to access this function."), -1);
230 return ValidDomainNames;
235 void InitModule_INETCONF(void) {
236 WebcitAddUrlHandler(HKEY("save_inetconf"), "", 0, new_save_inetconf, 0);
237 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
238 RegisterNamespace("SERVCFG:FLUSHINETCFG", 0, 0, DeleteInetConfHash, NULL, CTX_NONE);
239 RegisterIterator("ITERATE:VALID:DOMAINNAMES", 1, NULL, GetValidDomainNames, NULL, DeleteHash, CTX_STRBUF, CTX_NONE,