4 * Functions which handle Internet domain configuration etc.
11 * display the inet config dialog
13 void display_inetconf(void)
32 char *ic_spec[ic_max];
34 char *ic_keyword[ic_max];
35 char *ic_boxtitle[ic_max];
36 char *ic_desc[ic_max];
38 /* These are server config keywords; do not localize! */
39 ic_keyword[0] = "localhost";
40 ic_keyword[1] = "directory";
41 ic_keyword[2] = "smarthost";
42 ic_keyword[3] = "rbl";
43 ic_keyword[4] = "spamassassin";
44 ic_keyword[5] = "masqdomain";
46 ic_boxtitle[0] = _("Local host aliases");
47 ic_boxtitle[1] = _("Directory domains");
48 ic_boxtitle[2] = _("Smart hosts");
49 ic_boxtitle[3] = _("RBL hosts");
50 ic_boxtitle[4] = _("SpamAssassin hosts");
51 ic_boxtitle[5] = _("Masqueradable domains");
53 ic_desc[0] = _("(domains for which this host receives mail)");
54 ic_desc[1] = _("(domains mapped with the Global Address Book)");
55 ic_desc[2] = _("(if present, forward all outbound mail to one of these hosts)");
56 ic_desc[3] = _("(hosts running a Realtime Blackhole List)");
57 ic_desc[4] = _("(hosts running the SpamAssassin service)");
58 ic_desc[5] = _("(Domains as which users are allowed to masquerade)");
60 for (i=0; i<ic_max; ++i) {
61 ic_spec[i] = strdup("");
66 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
67 serv_getln(buf, sizeof buf);
68 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
70 extract_token(ename, buf, 0, '|', sizeof ename);
71 extract_token(etype, buf, 1, '|', sizeof etype);
73 for (i=0; i<ic_max; ++i) {
74 if (!strcasecmp(etype, ic_keyword[i])) {
80 ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
81 if (!IsEmptyStr(ic_spec[which])) strcat(ic_spec[which], "\n");
82 strcat(ic_spec[which], ename);
85 ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
86 if (!IsEmptyStr(ic_misc)) strcat(ic_misc, "\n");
92 output_headers(1, 1, 2, 0, 0, 0);
93 wprintf("<div id=\"banner\">\n");
95 wprintf(_("Internet configuration"));
99 wprintf("<div id=\"content\" class=\"service\">\n");
101 wprintf("<div class=\"fix_scrollbar_bug\">"
102 "<table border=0 width=100%% cellspacing=\"10px\" cellpadding=\"10px\"> "
103 "<tr><td valign=top width=50%%>\n");
104 for (which=0; which<ic_max; ++which) {
105 if (which == (ic_max / 2)) {
106 wprintf("</td><td valign=top>");
108 svput("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
109 do_template("beginbox", NULL);
110 wprintf("<span class=\"menudesc\">");
111 escputs(ic_desc[which]);
112 wprintf("</span><br />");
113 wprintf("<table border=0 cellspacing=\"2px\" cellpadding=\"2px\" width=94%% "
114 "class=\"altern\" >\n");
116 if (!IsEmptyStr(ic_spec[which])) {
117 for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
119 wprintf("<tr class=\"%s\">",
120 (bg ? "even" : "odd")
122 wprintf("<td align=left>");
123 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
125 wprintf("</td><td align=left>"
126 "<span class=\"button_link\">"
127 "<a href=\"save_inetconf?oper=delete&ename=");
129 wprintf("&etype=%s\" ", ic_keyword[which]);
130 wprintf("onClick=\"return confirm('%s');\">",
131 _("Delete this entry?"));
132 wprintf(_("Delete"));
133 wprintf("</a></span></td></tr>\n");
137 wprintf("<form method=\"post\" action=\"save_inetconf\">\n");
138 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
140 "<input type=\"text\" name=\"ename\" maxlength=\"64\">"
141 "<input type=\"hidden\" name=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
142 wprintf("</td><td align=left>"
143 "<input type=\"submit\" name=\"oper\" value=\"Add\">"
144 "</td></tr></table></form>\n");
145 do_template("endbox", NULL);
148 wprintf("</td></tr></table></div>\n");
151 for (i=0; i<ic_max; ++i) {
160 * save changes to the inet config
162 void save_inetconf(void) {
171 newconfig = malloc(65536);
173 strcpy(newconfig, "");
174 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
175 serv_getln(buf, SIZ);
176 if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
177 extract_token(ename, buf, 0, '|', SIZ);
178 extract_token(etype, buf, 1, '|', SIZ);
179 if (IsEmptyStr(buf)) {
180 /* skip blank lines */
182 else if ((!strcasecmp(ename, bstr("ename")))
183 && (!strcasecmp(etype, bstr("etype")))
184 && (!strcasecmp(bstr("oper"), "delete"))
186 sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
189 if (!IsEmptyStr(newconfig)) strcat(newconfig, "\n");
190 strcat(newconfig, buf);
194 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
195 serv_getln(buf, SIZ);
197 serv_puts(newconfig);
198 if (!strcasecmp(bstr("oper"), "add")) {
199 serv_printf("%s|%s", bstr("ename"), bstr("etype") );
200 sprintf(WC->ImportantMessage, _("%s added."), bstr("ename"));
213 typedef enum _e_cfg {
223 typedef struct _ConstStrBuf {
229 /* These are server config keywords; do not localize! */
230 ConstStrBuf CfgNames[] = {
231 { HKEY("localhost") },
232 { HKEY("directory") },
233 { HKEY("smarthost") },
235 { HKEY("spamassassin") },
236 { HKEY("masqdomain") }
243 * display the inet config dialog
245 void load_inetconf(void)
247 struct wcsession *WCC = WC;
248 StrBuf *Buf, *Token, *Value;
255 WCC->InetCfg = NewHash(1, NULL);
257 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
258 Hash = NewHash(1, NULL);
259 Put(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, Hash, HDeleteHash);
262 serv_printf("CONF GETSYS|application/x-citadel-internet-config");
263 serv_getln(buf, sizeof buf);
268 while ((len = StrBuf_ServGetln(Buf),
269 strcmp(ChrPtr(Buf), "000"))) {
272 StrBufExtract_token(Token, Buf, 1, '|');
273 StrBufExtract_token(Value, Buf, 0, '|');
274 GetHash(WCC->InetCfg, ChrPtr(Token), StrLength(Token), &vHash);
275 Hash = (HashList*) vHash;
277 lprintf(1, "ERROR Loading inet config line: [%s]\n",
282 nUsed = GetCount(Hash);
283 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
284 Put(Hash, nnn, nUsed, Value, HFreeStrBuf);
293 * save changes to the inet config
295 void new_save_inetconf(void) {
296 struct wcsession *WCC = WC;
299 const StrBuf *eType, *eNum, *eName;
306 eType = sbstr("etype");
308 GetHash(WCC->InetCfg, ChrPtr(eType), StrLength(eType), &vHash);
309 Hash = (HashList*) vHash;
311 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
316 if (strcasecmp(bstr("oper"), "delete") == 0) {
317 eNum = sbstr("ename");
318 if (!GetHash(Hash, ChrPtr(eNum), StrLength(eNum), &vStr) ||
320 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
326 sprintf(WC->ImportantMessage, _("%s has been deleted."), ChrPtr(Str));
329 else if (!strcasecmp(bstr("oper"), "add")) {
330 eName = sbstr("ename");
332 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
337 nUsed = GetCount(Hash);
338 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
340 Put(Hash, nnn, nUsed, NewStrBufDup(eName), HFreeStrBuf);
341 sprintf(WC->ImportantMessage, "%s added.", ChrPtr(eName));
344 serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
345 serv_getln(buf, SIZ);
347 for (i = 0; i < (sizeof(CfgNames) / sizeof(ConstStrBuf)); i++) {
352 GetHash(WCC->InetCfg, CfgNames[i].name, CfgNames[i].len, &vHash);
353 Hash = (HashList*) vHash;
355 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
359 if (GetCount(Hash) > 0) {
360 where = GetNewHashPos();
361 while (GetNextHashPos(Hash, where, &KeyLen, &Key, &vStr)) {
362 Str = (StrBuf*) vStr;
363 if ((Str!= NULL) && (StrLength(Str) > 0))
368 DeleteHashPos(&where);
372 DeleteHash(&WCC->InetCfg);
378 void InetCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
380 SVPutBuf("SERVCFG:INET:HOSTNAME", vContext, 1);
383 void DeleteInectConfHash(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context)
385 struct wcsession *WCC = WC;
386 if (WCC->InetCfg == NULL)
388 DeleteHash(&WCC->InetCfg);
393 HashList *GetInetConfHash(WCTemplateToken *Token)
395 struct wcsession *WCC = WC;
398 if (WCC->InetCfg == NULL)
400 GetHash(WCC->InetCfg,
401 Token->Params[2]->Start,
402 Token->Params[2]->len,
404 svprintf(HKEY("SERVCFG:INET:TYPE"), WCS_STRING, Token->Params[2]->Start);
412 WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0);
413 WebcitAddUrlHandler(HKEY("save_inetconf"), new_save_inetconf, AJAX);
414 RegisterIterator("SERVCFG:INET", 1, NULL, GetInetConfHash, InetCfgSubst, NULL);
415 RegisterNamespace("SERVCFG:FLUSHINETCFG",0, 0, DeleteInectConfHash);