4 * Functions which handle Internet domain configuration etc.
11 * display the inet config dialog
13 void display_inetconf(void)
33 char *ic_spec[ic_max];
35 char *ic_keyword[ic_max];
36 char *ic_boxtitle[ic_max];
37 char *ic_desc[ic_max];
39 /* These are server config keywords; do not localize! */
40 ic_keyword[0] = "localhost";
41 ic_keyword[1] = "directory";
42 ic_keyword[2] = "smarthost";
43 ic_keyword[3] = "rbl";
44 ic_keyword[4] = "spamassassin";
45 ic_keyword[5] = "masqdomain";
46 ic_keyword[6] = "clamav";
48 ic_boxtitle[0] = _("Local host aliases");
49 ic_boxtitle[1] = _("Directory domains");
50 ic_boxtitle[2] = _("Smart hosts");
51 ic_boxtitle[3] = _("RBL hosts");
52 ic_boxtitle[4] = _("SpamAssassin hosts");
53 ic_boxtitle[5] = _("Masqueradable domains");
54 ic_boxtitle[6] = _("ClamAV clamd hosts");
56 ic_desc[0] = _("(domains for which this host receives mail)");
57 ic_desc[1] = _("(domains mapped with the Global Address Book)");
58 ic_desc[2] = _("(if present, forward all outbound mail to one of these hosts)");
59 ic_desc[3] = _("(hosts running a Realtime Blackhole List)");
60 ic_desc[4] = _("(hosts running the SpamAssassin service)");
61 ic_desc[5] = _("(Domains as which users are allowed to masquerade)");
62 ic_desc[6] = _("(hosts running the ClamAV clamd service)");
64 for (i=0; i<ic_max; ++i) {
65 ic_spec[i] = strdup("");
70 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
71 serv_getln(buf, sizeof buf);
72 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
74 extract_token(ename, buf, 0, '|', sizeof ename);
75 extract_token(etype, buf, 1, '|', sizeof etype);
77 for (i=0; i<ic_max; ++i) {
78 if (!strcasecmp(etype, ic_keyword[i])) {
84 ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
85 if (!IsEmptyStr(ic_spec[which])) strcat(ic_spec[which], "\n");
86 strcat(ic_spec[which], ename);
89 ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
90 if (!IsEmptyStr(ic_misc)) strcat(ic_misc, "\n");
96 output_headers(1, 1, 2, 0, 0, 0);
97 wprintf("<div id=\"banner\">\n");
99 wprintf(_("Internet configuration"));
103 wprintf("<div id=\"content\" class=\"service\">\n");
105 wprintf("<div class=\"fix_scrollbar_bug\">"
106 "<table border=0 width=100%% cellspacing=\"10\" cellpadding=\"10\"> "
107 "<tr><td valign=top width=50%%>\n");
108 for (which=0; which<ic_max; ++which) {
109 if (which == (ic_max / 2)) {
110 wprintf("</td><td valign=top>");
112 svput("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
113 do_template("beginbox", NULL);
114 wprintf("<span class=\"menudesc\">");
115 escputs(ic_desc[which]);
116 wprintf("</span><br />");
117 wprintf("<table border=0 cellspacing=\"2px\" cellpadding=\"2px\" width=94%% "
118 "class=\"altern\" >\n");
120 if (!IsEmptyStr(ic_spec[which])) {
121 for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
123 wprintf("<tr class=\"%s\">",
124 (bg ? "even" : "odd")
126 wprintf("<td align=left>");
127 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
129 wprintf("</td><td align=left>"
130 "<span class=\"button_link\">"
131 "<a href=\"save_inetconf?oper=delete&ename=");
133 wprintf("&etype=%s\" ", ic_keyword[which]);
134 wprintf("onClick=\"return confirm('%s');\">",
135 _("Delete this entry?"));
136 wprintf(_("Delete"));
137 wprintf("</a></span></td></tr>\n");
141 wprintf("<form method=\"post\" action=\"save_inetconf\">\n");
142 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
144 "<input type=\"text\" name=\"ename\" maxlength=\"64\">"
145 "<input type=\"hidden\" name=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
146 wprintf("</td><td align=left>"
147 "<input type=\"submit\" name=\"oper\" value=\"Add\">"
148 "</td></tr></table></form>\n");
149 do_template("endbox", NULL);
152 wprintf("</td></tr></table></div>\n");
155 for (i=0; i<ic_max; ++i) {
164 * save changes to the inet config
166 void save_inetconf(void) {
175 newconfig = malloc(65536);
177 strcpy(newconfig, "");
178 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
179 serv_getln(buf, SIZ);
180 if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
181 extract_token(ename, buf, 0, '|', SIZ);
182 extract_token(etype, buf, 1, '|', SIZ);
183 if (IsEmptyStr(buf)) {
184 /* skip blank lines */
186 else if ((!strcasecmp(ename, bstr("ename")))
187 && (!strcasecmp(etype, bstr("etype")))
188 && (!strcasecmp(bstr("oper"), "delete"))
190 sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
193 if (!IsEmptyStr(newconfig)) strcat(newconfig, "\n");
194 strcat(newconfig, buf);
198 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
199 serv_getln(buf, SIZ);
201 serv_puts(newconfig);
202 if (!strcasecmp(bstr("oper"), "add")) {
203 serv_printf("%s|%s", bstr("ename"), bstr("etype") );
204 sprintf(WC->ImportantMessage, _("%s added."), bstr("ename"));
217 typedef enum _e_cfg {
228 typedef struct _ConstStrBuf {
234 /* These are server config keywords; do not localize! */
235 ConstStrBuf CfgNames[] = {
236 { HKEY("localhost") },
237 { HKEY("directory") },
238 { HKEY("smarthost") },
240 { HKEY("spamassassin") },
241 { HKEY("masqdomain") },
249 * display the inet config dialog
251 void load_inetconf(void)
253 struct wcsession *WCC = WC;
254 StrBuf *Buf, *Token, *Value;
261 WCC->InetCfg = NewHash(1, NULL);
263 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
264 Hash = NewHash(1, NULL);
265 Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
268 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
269 serv_getln(buf, sizeof buf);
274 while ((len = StrBuf_ServGetln(Buf),
275 strcmp(ChrPtr(Buf), "000"))) {
278 StrBufExtract_token(Token, Buf, 1, '|');
279 StrBufExtract_token(Value, Buf, 0, '|');
280 GetHash(WCC->InetCfg, ChrPtr(Token), StrLength(Token), &vHash);
281 Hash = (HashList*) vHash;
283 lprintf(1, "ERROR Loading inet config line: [%s]\n",
288 nUsed = GetCount(Hash);
289 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
290 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
299 * save changes to the inet config
301 void new_save_inetconf(void) {
302 struct wcsession *WCC = WC;
305 const StrBuf *eType, *eNum, *eName;
312 eType = sbstr("etype");
314 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
315 Hash = (HashList*) vHash;
317 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
322 if (strcasecmp(bstr("oper"), "delete") == 0) {
323 eNum = sbstr("ename");
324 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
326 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
332 sprintf(WC->ImportantMessage, _("%s has been deleted."), ChrPtr(Str));
335 else if (!strcasecmp(bstr("oper"), "add")) {
336 eName = sbstr("ename");
338 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
343 nUsed = GetCount(Hash);
344 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
346 Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf);
347 sprintf(WC->ImportantMessage, "%s added.", ChrPtr(eName));
350 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
351 serv_getln(buf, SIZ);
353 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
358 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
359 Hash = (HashList*) vHash;
361 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
365 if (GetCount(Hash) > 0) {
366 where = GetNewHashPos();
367 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
368 Str = (StrBuf*) vStr;
369 if ((Str!= NULL) && (StrLength(Str) > 0))
374 DeleteHashPos(&where);
378 DeleteHash(&WCC->InetCfg);
384 void InetCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
386 SVPutBuf("SERVCFG:INET:HOSTNAME", vContext, 1);
389 void DeleteInectConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
391 struct wcsession *WCC = WC;
392 if (WCC->InetCfg == NULL)
394 DeleteHash(&WCC->InetCfg);
399 HashList *GetInetConfHash(WCTemplateToken *Token)
401 struct wcsession *WCC = WC;
404 if (WCC->InetCfg == NULL)
406 GetHash(WCC->InetCfg,
407 Token->Params[2]->Start,
408 Token->Params[2]->len,
410 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, Token->Params[2]->Start);
418 WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0);
419 WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX);
420 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL, CTX_INETCFG);
421 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInectConfHash, CTX_INETCFG);