X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsiteconfig.c;h=7a93d44af096e10b43b155c49a502584d88cc3bc;hb=329fae6737e16938ee440d79bc89a03e4eb5268c;hp=041bcb1c26f5b0928e8f79b39ce8768d2c2da6bb;hpb=7f5c03bd732302f360f6840f0d815ad3e644416d;p=citadel.git diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index 041bcb1c2..7a93d44af 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -1,12 +1,20 @@ /* * Administrative screen for site-wide configuration + * + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ - #include "webcit.h" #include "webserver.h" - HashList *ZoneHash = NULL; ConstStr ExpirePolicyString = {CStrOf(roompolicy) }; @@ -35,8 +43,7 @@ void LoadExpirePolicy(GPEXWhichPolicy which) WCC->Policy[which].expire_value = StrBufExtractNext_long(Buf, &Pos, '|'); } else if (State == 550) - StrBufAppendBufPlain(WCC->ImportantMsg, - _("Higher access is required to access this function."), -1, 0); + AppendImportantMessage(_("Higher access is required to access this function."), -1); FreeStrBuf(&Buf); } @@ -54,8 +61,7 @@ void SaveExpirePolicyFromHTTP(GPEXWhichPolicy which) StrBuf_ServGetln(Buf); GetServerStatus(Buf, &State); if (State == 550) - StrBufAppendBufPlain(WC->ImportantMsg, - _("Higher access is required to access this function."), -1, 0); + AppendImportantMessage(_("Higher access is required to access this function."), -1); FreeStrBuf(&Buf); } @@ -68,7 +74,7 @@ int ConditionalExpire(StrBuf *Target, WCTemplputParams *TP) which = GetTemplateTokenNumber(Target, TP, 2, 0); CompareWith = GetTemplateTokenNumber(Target, TP, 3, 0); - if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which); + LoadExpirePolicy(which); return WCC->Policy[which].expire_mode == CompareWith; } @@ -79,7 +85,7 @@ void tmplput_ExpireValue(StrBuf *Target, WCTemplputParams *TP) wcsession *WCC = WC; which = GetTemplateTokenNumber(Target, TP, 0, 0); - if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which); + LoadExpirePolicy(which); StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_value); } @@ -90,12 +96,11 @@ void tmplput_ExpireMode(StrBuf *Target, WCTemplputParams *TP) wcsession *WCC = WC; which = GetTemplateTokenNumber(Target, TP, 2, 0); - if (WCC->Policy[which].loaded == 0) LoadExpirePolicy(which); + LoadExpirePolicy(which); StrBufAppendPrintf(Target, "%d", WCC->Policy[which].expire_mode); } - void LoadZoneFiles(void) { icalarray *zones; @@ -109,7 +114,7 @@ void LoadZoneFiles(void) Put(ZoneHash, HKEY("UTC"), ZName, HFreeStrBuf); zones = icaltimezone_get_builtin_timezones(); for (z = 0; z < zones->num_elements; ++z) { - /* lprintf(9, "Location: %-40s tzid: %s\n", + /* syslog(9, "Location: %-40s tzid: %s\n", icaltimezone_get_location(icalarray_element_at(zones, z)), icaltimezone_get_tzid(icalarray_element_at(zones, z)) ); */ @@ -126,7 +131,7 @@ typedef struct _CfgMapping { int type; const char *Key; long len; -}CfgMapping; +} CfgMapping; #define CFG_STR 1 #define CFG_YES 2 @@ -199,11 +204,12 @@ CfgMapping ServerConfig[] = { {CFG_STR, HKEY("c_xmpp_s2s_port")}, {CFG_STR, HKEY("c_pop3_fetch")}, {CFG_STR, HKEY("c_pop3_fastest")}, - {CFG_YES , HKEY("c_spam_flag_only")}, - {CFG_YES , HKEY("c_guest_logins")} + {CFG_YES, HKEY("c_spam_flag_only")}, + {CFG_YES, HKEY("c_guest_logins")} }; + /* * display all configuration items */ @@ -213,7 +219,7 @@ void load_siteconfig(void) StrBuf *Buf; HashList *Cfg; long len; - int i; + int i, j; if (WCC->ServCfg == NULL) WCC->ServCfg = NewHash(1, NULL); @@ -226,63 +232,65 @@ void load_siteconfig(void) if (GetServerStatus(Buf, NULL) != 1) { StrBufCutLeft(Buf, 4); AppendImportantMessage(SKEY(Buf)); + FreeStrBuf(&Buf); return; } - i = 0; + j = i = 0; while (len = StrBuf_ServGetln(Buf), - (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) && - ((len != 3) || (strcmp(ChrPtr(Buf), "000")!= 0)) - ) + (len >= 0) && + ((len != 3) || strcmp(ChrPtr(Buf), "000"))) { - Put(Cfg, - ServerConfig[i].Key, - ServerConfig[i].len, - Buf, - HFreeStrBuf); - i++; - if (i <= sizeof(ServerConfig) / sizeof(CfgMapping)) + if (i < (sizeof(ServerConfig) / sizeof(CfgMapping))) + { + Put(Cfg, + ServerConfig[i].Key, + ServerConfig[i].len, + Buf, + HFreeStrBuf); + i++; Buf = NewStrBuf(); - else - Buf = NULL; - } - if (strcmp(ChrPtr(Buf), "000")!=0) - { - /* WHOOOOPSI??? burn the lines we don't understand */ - while ((len = StrBuf_ServGetln(Buf), - strcmp(ChrPtr(Buf), "000"))) {} - AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1); - return; + } + else { + if (j == 0) + AppendImportantMessage(_("WARNING: Failed to parse Server Config; do you run a to new citserver?"), -1); + j++; + } } FreeStrBuf(&Buf); - LoadExpirePolicy(sitepolicy); + LoadExpirePolicy(roompolicy); + LoadExpirePolicy(floorpolicy); LoadExpirePolicy(mailboxespolicy); + LoadExpirePolicy(sitepolicy); } -/** +/* * parse siteconfig changes */ void siteconfig(void) { wcsession *WCC = WC; int i; - char buf[256]; + StrBuf *Line; if (strlen(bstr("ok_button")) == 0) { display_aide_menu(); return; } + Line = NewStrBuf(); serv_printf("CONF set"); - serv_getln(buf, sizeof buf); - if (buf[0] != '4') { - safestrncpy(WCC->ImportantMessage, &buf[4], sizeof WCC->ImportantMessage); + StrBuf_ServGetln(Line); + if (GetServerStatusMsg(Line, NULL, 1, 4) != 4) { display_aide_menu(); + FreeStrBuf(&Line); return; } + FreeStrBuf(&Line); + for (i=0; i < (sizeof(ServerConfig) / sizeof(CfgMapping)); i ++) { switch (ServerConfig[i].type) { @@ -310,8 +318,7 @@ void siteconfig(void) FreeStrBuf(&WCC->serv_info->serv_default_cal_zone); WCC->serv_info->serv_default_cal_zone = NewStrBufDup(sbstr("c_default_cal_zone")); - safestrncpy(WCC->ImportantMessage, _("Your system configuration has been updated."), - sizeof WCC->ImportantMessage); + AppendImportantMessage(_("Your system configuration has been updated."), -1); DeleteHash(&WCC->ServCfg); display_aide_menu(); } @@ -382,6 +389,73 @@ int ConditionalServCfgCTXStrBuf(StrBuf *Target, WCTemplputParams *TP) else return 0; } +/*----------------------------------------------------------------------------* + * Displaying Logging * + *----------------------------------------------------------------------------*/ +typedef struct __LogStatusStruct { + int Enable; + StrBuf *Name; +}LogStatusStruct; + +void DeleteLogStatusStruct(void *v) +{ + LogStatusStruct *Stat = (LogStatusStruct*)v; + + FreeStrBuf(&Stat->Name); + free(Stat); +} + +void tmplput_servcfg_LogName(StrBuf *Target, WCTemplputParams *TP) +{ + LogStatusStruct *Stat = (LogStatusStruct*) CTX; + StrBufAppendTemplate(Target, TP, Stat->Name, 1); +} + +int ConditionalServCfgThisLogEnabled(StrBuf *Target, WCTemplputParams *TP) +{ + LogStatusStruct *Stat = (LogStatusStruct*) CTX; + return Stat->Enable; +} + +HashList *iterate_GetSrvLogEnable(StrBuf *Target, WCTemplputParams *TP) +{ + HashList *Hash = NULL; + StrBuf *Buf; + LogStatusStruct *Stat; + const char *Pos; + int Done = 0; + long len; + int num_logs = 0; + + serv_puts("LOGP"); + Buf = NewStrBuf(); + StrBuf_ServGetln(Buf); + if (GetServerStatus(Buf, NULL) == 1) { + Hash = NewHash(1, Flathash); + while (!Done) { + len = StrBuf_ServGetln(Buf); + if ((len <0) || + ((len == 3) && + !strcmp(ChrPtr(Buf), "000"))) + { + Done = 1; + break; + } + Stat = (LogStatusStruct*) malloc (sizeof(LogStatusStruct)); + Pos = NULL; + Stat->Name = NewStrBufPlain(NULL, len); + StrBufExtract_NextToken(Stat->Name, Buf, &Pos, '|'); + Stat->Enable = StrBufExtractNext_int(Buf, &Pos, '|'); + + Put(Hash, IKEY(num_logs), Stat, DeleteLogStatusStruct); + num_logs++; + } + } + FreeStrBuf(&Buf); + return Hash; +} + + void InitModule_SITECONFIG (void) @@ -406,6 +480,10 @@ InitModule_SITECONFIG RegisterConditional(HKEY("COND:EXPIRE:MODE"), 2, ConditionalExpire, CTX_NONE); RegisterNamespace("EXPIRE:VALUE", 1, 2, tmplput_ExpireValue, NULL, CTX_NONE); RegisterNamespace("EXPIRE:MODE", 1, 2, tmplput_ExpireMode, NULL, CTX_NONE); + + RegisterConditional(HKEY("COND:SERVCFG:THISLOGENABLE"), 4, ConditionalServCfgThisLogEnabled, CTX_SRVLOG); + RegisterIterator("SERVCFG:LOGENABLE", 0, NULL, iterate_GetSrvLogEnable, NULL, DeleteHash, CTX_SRVLOG, CTX_NONE, IT_NOFLAG); + RegisterNamespace("SERVCFG:LOGNAME", 0, 1, tmplput_servcfg_LogName, NULL, CTX_SRVLOG); } void