* Set all version numbers to 7.41 for upcoming beta.
[citadel.git] / webcit / siteconfig.c
blob785a54d36a55658846e6015be4ae45acb50fb236
1 /*
2 * $Id$
4 * Administrative screen for site-wide configuration
5 */
8 #include "webcit.h"
9 #include "webserver.h"
12 HashList *ZoneHash = NULL;
16 void LoadZoneFiles(void)
18 icalarray *zones;
19 int z;
20 long len;
21 const char *this_zone;
22 StrBuf *ZName;
24 ZoneHash = NewHash(1, NULL);
25 ZName = NewStrBufPlain(HKEY("UTC"));
26 Put(ZoneHash, HKEY("UTC"), ZName, HFreeStrBuf);
27 zones = icaltimezone_get_builtin_timezones();
28 for (z = 0; z < zones->num_elements; ++z) {
29 /* lprintf(9, "Location: %-40s tzid: %s\n",
30 icaltimezone_get_location(icalarray_element_at(zones, z)),
31 icaltimezone_get_tzid(icalarray_element_at(zones, z))
32 ); */
33 this_zone = icaltimezone_get_location(icalarray_element_at(zones, z));
34 len = strlen(this_zone);
35 ZName = NewStrBufPlain(this_zone, len);
36 Put(ZoneHash, this_zone, len, ZName, HFreeStrBuf);
38 SortByHashKey(ZoneHash, 0);
42 typedef struct _CfgMapping {
43 int type;
44 const char *Key;
45 long len;
46 }CfgMapping;
48 #define CFG_STR 1
49 #define CFG_YES 2
50 #define CFG_NO 3
52 CfgMapping ServerConfig[] = {
53 {CFG_STR, HKEY("c_nodename")},
54 {CFG_STR, HKEY("c_fqdn")},
55 {CFG_STR, HKEY("c_humannode")},
56 {CFG_STR, HKEY("c_phonenum")},
57 {CFG_YES, HKEY("c_creataide")},
58 {CFG_STR, HKEY("c_sleeping")},
59 {CFG_STR, HKEY("c_initax")},
60 {CFG_YES, HKEY("c_regiscall")},
61 {CFG_YES, HKEY("c_twitdetect")},
62 {CFG_STR, HKEY("c_twitroom")},
63 {CFG_STR, HKEY("c_moreprompt")},
64 {CFG_YES, HKEY("c_restrict")},
65 {CFG_STR, HKEY("c_bbs_city")},
66 {CFG_STR, HKEY("c_sysadm")},
67 {CFG_STR, HKEY("c_maxsessions")},
68 {CFG_STR, HKEY("reserved1")},
69 {CFG_STR, HKEY("c_userpurge")},
70 {CFG_STR, HKEY("c_roompurge")},
71 {CFG_STR, HKEY("c_logpages")},
72 {CFG_STR, HKEY("c_createax")},
73 {CFG_STR, HKEY("c_maxmsglen")},
74 {CFG_STR, HKEY("c_min_workers")},
75 {CFG_STR, HKEY("c_max_workers")},
76 {CFG_STR, HKEY("c_pop3_port")},
77 {CFG_STR, HKEY("c_smtp_port")},
78 {CFG_NO , HKEY("c_rfc822_strict_from")}, /* note: reverse bool */
79 {CFG_YES, HKEY("c_aide_zap")},
80 {CFG_STR, HKEY("c_imap_port")},
81 {CFG_STR, HKEY("c_net_freq")},
82 {CFG_YES, HKEY("c_disable_newu")},
83 {CFG_STR, HKEY("reserved2")},
84 {CFG_STR, HKEY("c_purge_hour")},
85 {CFG_STR, HKEY("c_ldap_host")},
86 {CFG_STR, HKEY("c_ldap_port")},
87 {CFG_STR, HKEY("c_ldap_base_dn")},
88 {CFG_STR, HKEY("c_ldap_bind_dn")},
89 {CFG_STR, HKEY("c_ldap_bind_pw")},
90 {CFG_STR, HKEY("c_ip_addr")},
91 {CFG_STR, HKEY("c_msa_port")},
92 {CFG_STR, HKEY("c_imaps_port")},
93 {CFG_STR, HKEY("c_pop3s_port")},
94 {CFG_STR, HKEY("c_smtps_port")},
95 {CFG_YES, HKEY("c_enable_fulltext")},
96 {CFG_YES, HKEY("c_auto_cull")},
97 {CFG_YES, HKEY("c_instant_expunge")},
98 {CFG_YES, HKEY("c_allow_spoofing")},
99 {CFG_YES, HKEY("c_journal_email")},
100 {CFG_YES, HKEY("c_journal_pubmsgs")},
101 {CFG_STR, HKEY("c_journal_dest")},
102 {CFG_STR, HKEY("c_default_cal_zone")},
103 {CFG_STR, HKEY("c_pftcpdict_port")},
104 {CFG_STR, HKEY("c_mgesve_port")},
105 {CFG_STR, HKEY("c_auth_mode")},
106 {CFG_STR, HKEY("c_funambol_host")},
107 {CFG_STR, HKEY("c_funambol_port")},
108 {CFG_STR, HKEY("c_funambol_source")},
109 {CFG_STR, HKEY("c_funambol_auth")},
110 {CFG_YES, HKEY("c_rbl_at_greeting")},
111 {CFG_STR, HKEY("c_master_user")},
112 {CFG_STR, HKEY("c_master_pass")},
113 {CFG_STR, HKEY("c_pager_program")},
114 {CFG_YES, HKEY("c_imap_keep_from")},
115 {CFG_STR, HKEY("c_xmpp_c2s_port")},
116 {CFG_STR, HKEY("c_xmpp_s2s_port")},
117 {CFG_STR, HKEY("c_pop3_fetch")},
118 {CFG_STR, HKEY("c_pop3_fastest")},
119 {CFG_YES , HKEY("c_spam_flag_only")}
124 * display all configuration items
126 void load_siteconfig(void)
128 wcsession *WCC = WC;
129 StrBuf *Buf, *CfgToken;
130 HashList *Cfg;
131 char buf[SIZ];
132 long len;
133 int i;
135 if (WCC->ServCfg == NULL)
136 WCC->ServCfg = NewHash(1, NULL);
137 Cfg = WCC->ServCfg;
139 serv_printf("CONF get");
140 serv_getln(buf, sizeof buf);
141 i = 0;
142 Buf = NewStrBuf();
143 while ((sizeof(ServerConfig) / sizeof(CfgMapping)) &&
144 (len = StrBuf_ServGetln(Buf),
145 strcmp(ChrPtr(Buf), "000")) &&
146 (i <= sizeof(ServerConfig)))
148 Put(Cfg,
149 ServerConfig[i].Key,
150 ServerConfig[i].len,
151 Buf,
152 HFreeStrBuf);
153 i++;
154 if (i <= sizeof(ServerConfig) / sizeof(CfgMapping))
155 Buf = NewStrBuf();
156 else
157 Buf = NULL;
159 FreeStrBuf(&Buf);
161 serv_puts("GPEX site");
162 Buf = NewStrBuf();
163 CfgToken = NULL;
164 StrBuf_ServGetln(Buf);
165 if (GetServerStatus(Buf, NULL) == 2) {
166 StrBufCutLeft(Buf, 4);
168 CfgToken = NewStrBuf();
169 StrBufExtract_token(CfgToken, Buf, 0, '|');
170 Put(Cfg, HKEY("sitepolicy"), CfgToken, HFreeStrBuf);
172 CfgToken = NewStrBuf();
173 StrBufExtract_token(CfgToken, Buf, 1, '|');
174 Put(Cfg, HKEY("sitevalue"), CfgToken, HFreeStrBuf);
177 serv_puts("GPEX mailboxes");
178 StrBuf_ServGetln(Buf);
179 if (GetServerStatus(Buf, NULL) == 2) {
180 StrBufCutLeft(Buf, 4);
182 CfgToken = NewStrBuf();
183 StrBufExtract_token(CfgToken, Buf, 0, '|');
184 Put(Cfg, HKEY("mboxpolicy"), CfgToken, HFreeStrBuf);
186 CfgToken = NewStrBuf();
187 StrBufExtract_token(CfgToken, Buf, 1, '|');
188 Put(Cfg, HKEY("mboxvalue"), CfgToken, HFreeStrBuf);
190 FreeStrBuf(&Buf);
195 * parse siteconfig changes
197 void siteconfig(void)
199 wcsession *WCC = WC;
200 int i;
201 char buf[256];
203 if (strlen(bstr("ok_button")) == 0) {
204 display_aide_menu();
205 return;
207 serv_printf("CONF set");
208 serv_getln(buf, sizeof buf);
209 if (buf[0] != '4') {
210 safestrncpy(WCC->ImportantMessage, &buf[4], sizeof WCC->ImportantMessage);
211 display_aide_menu();
212 return;
215 for (i=0; i < (sizeof(ServerConfig) / sizeof(CfgMapping)); i ++)
217 switch (ServerConfig[i].type) {
218 default:
219 case CFG_STR:
220 serv_putbuf(SBstr(ServerConfig[i].Key, ServerConfig[i].len));
221 break;
222 case CFG_YES:
223 serv_puts(YesBstr(ServerConfig[i].Key,
224 ServerConfig[i].len) ?
225 "1" : "0");
226 break;
227 case CFG_NO:
228 serv_puts(YesBstr(ServerConfig[i].Key,
229 ServerConfig[i].len) ?
230 "0" : "1");
231 break;
234 serv_puts("000");
236 serv_printf("SPEX site|%d|%d", ibstr("sitepolicy"), ibstr("sitevalue"));
237 serv_getln(buf, sizeof buf);
238 serv_printf("SPEX mailboxes|%d|%d", ibstr("mboxpolicy"), ibstr("mboxvalue"));
239 serv_getln(buf, sizeof buf);
240 FreeStrBuf(&WCC->serv_info->serv_default_cal_zone);
241 WCC->serv_info->serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone"));
243 safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."),
244 sizeof WCC->ImportantMessage);
245 DeleteHash(&WCC->ServCfg);
246 display_aide_menu();
249 void tmplput_servcfg(StrBuf *Target, WCTemplputParams *TP)
251 wcsession *WCC = WC;
252 void *vBuf;
253 StrBuf *Buf;
255 if (WCC->is_aide) {
256 if (WCC->ServCfg == NULL)
257 load_siteconfig();
258 GetHash(WCC->ServCfg, TKEY(0), &vBuf);
259 Buf = (StrBuf*) vBuf;
260 StrBufAppendTemplate(Target, TP, Buf, 1);
264 int ConditionalServCfg(StrBuf *Target, WCTemplputParams *TP)
266 wcsession *WCC = WC;
267 void *vBuf;
268 StrBuf *Buf;
270 if (WCC->is_aide) {
271 if (WCC->ServCfg == NULL)
272 load_siteconfig();
273 GetHash(WCC->ServCfg, TKEY(2), &vBuf);
274 if (vBuf == NULL) return 0;
275 Buf = (StrBuf*) vBuf;
276 if (TP->Tokens->nParameters == 3) {
277 return 1;
279 else if (TP->Tokens->Params[3]->Type == TYPE_STR)
280 return (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
281 else return (StrTol(Buf) == TP->Tokens->Params[3]->lvalue);
283 else return 0;
286 int ConditionalServCfgSubst(StrBuf *Target, WCTemplputParams *TP)
288 wcsession *WCC = WC;
289 void *vBuf;
290 StrBuf *Buf;
292 if (WCC->is_aide) {
293 if (WCC->ServCfg == NULL)
294 load_siteconfig();
295 GetHash(WCC->ServCfg, TKEY(2), &vBuf);
296 if (vBuf == NULL) return 0;
297 Buf = (StrBuf*) vBuf;
299 return CompareSubstToStrBuf(Buf, TP->Tokens->Params[3]);
301 else return 0;
304 void
305 InitModule_SITECONFIG
306 (void)
308 WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, CTX_NONE);
310 RegisterNamespace("SERV:CFG", 1, 2, tmplput_servcfg, CTX_NONE);
311 RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg, CTX_NONE);
312 RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst, CTX_NONE);