* When saving a Task, if the status is COMPLETED then also set PERCENT-COMPLETE:100...
[citadel.git] / webcit / siteconfig.c
blob709693e59f20535e8b2d502e658c60d307720716
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 serv_getln(buf, sizeof buf);
179 if (buf[0] == '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);
194 * parse siteconfig changes
196 void siteconfig(void)
198 wcsession *WCC = WC;
199 int i;
200 char buf[256];
202 if (strlen(bstr("ok_button")) == 0) {
203 display_aide_menu();
204 return;
206 serv_printf("CONF set");
207 serv_getln(buf, sizeof buf);
208 if (buf[0] != '4') {
209 safestrncpy(WCC->ImportantMessage, &buf[4], sizeof WCC->ImportantMessage);
210 display_aide_menu();
211 return;
214 for (i=0; i < (sizeof(ServerConfig) / sizeof(CfgMapping)); i ++)
216 switch (ServerConfig[i].type) {
217 default:
218 case CFG_STR:
219 serv_putbuf(SBstr(ServerConfig[i].Key, ServerConfig[i].len));
220 break;
221 case CFG_YES:
222 serv_puts(YesBstr(ServerConfig[i].Key,
223 ServerConfig[i].len) ?
224 "1" : "0");
225 break;
226 case CFG_NO:
227 serv_puts(YesBstr(ServerConfig[i].Key,
228 ServerConfig[i].len) ?
229 "0" : "1");
230 break;
233 serv_puts("000");
235 serv_printf("SPEX site|%d|%d", ibstr("sitepolicy"), ibstr("sitevalue"));
236 serv_getln(buf, sizeof buf);
237 serv_printf("SPEX mailboxes|%d|%d", ibstr("mboxpolicy"), ibstr("mboxvalue"));
238 serv_getln(buf, sizeof buf);
239 FreeStrBuf(&serv_info.serv_default_cal_zone);
240 serv_info.serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone"));
242 safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."),
243 sizeof WCC->ImportantMessage);
244 DeleteHash(&WCC->ServCfg);
245 display_aide_menu();
248 void tmplput_servcfg(StrBuf *Target, WCTemplputParams *TP)
250 wcsession *WCC = WC;
251 void *vBuf;
252 StrBuf *Buf;
254 if (WCC->is_aide) {
255 if (WCC->ServCfg == NULL)
256 load_siteconfig();
257 GetHash(WCC->ServCfg, TKEY(0), &vBuf);
258 Buf = (StrBuf*) vBuf;
259 StrBufAppendTemplate(Target, TP, Buf, 1);
263 int ConditionalServCfg(StrBuf *Target, WCTemplputParams *TP)
265 wcsession *WCC = WC;
266 void *vBuf;
267 StrBuf *Buf;
269 if (WCC->is_aide) {
270 if (WCC->ServCfg == NULL)
271 load_siteconfig();
272 GetHash(WCC->ServCfg, TKEY(2), &vBuf);
273 if (vBuf == NULL) return 0;
274 Buf = (StrBuf*) vBuf;
275 if (TP->Tokens->nParameters == 3) {
276 return 1;
278 else if (TP->Tokens->Params[3]->Type == TYPE_STR)
279 return (strcmp(TP->Tokens->Params[3]->Start, ChrPtr(Buf)) == 0);
280 else return (StrTol(Buf) == TP->Tokens->Params[3]->lvalue);
282 else return 0;
285 int ConditionalServCfgSubst(StrBuf *Target, WCTemplputParams *TP)
287 wcsession *WCC = WC;
288 void *vBuf;
289 StrBuf *Buf;
291 if (WCC->is_aide) {
292 if (WCC->ServCfg == NULL)
293 load_siteconfig();
294 GetHash(WCC->ServCfg, TKEY(2), &vBuf);
295 if (vBuf == NULL) return 0;
296 Buf = (StrBuf*) vBuf;
298 return CompareSubstToStrBuf(Buf, TP->Tokens->Params[3]);
300 else return 0;
303 void
304 InitModule_SITECONFIG
305 (void)
307 WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, CTX_NONE);
309 RegisterNamespace("SERV:CFG", 1, 2, tmplput_servcfg, CTX_NONE);
310 RegisterConditional(HKEY("COND:SERVCFG"), 3, ConditionalServCfg, CTX_NONE);
311 RegisterConditional(HKEY("COND:SERVCFG:SUBST"), 4, ConditionalServCfgSubst, CTX_NONE);