From 31b598b10dcc8f63c5cf77cffb6f305f7cff1339 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 28 Sep 2008 21:23:10 +0000 Subject: [PATCH] * templatize user editing * swap order of DoTemplate to be more intuitive * add missing break on error to EvaluateConditional * add date printing functions (unfinishded) --- webcit/http_datestring.c | 21 ++++ webcit/notes.c | 2 +- webcit/static/t/userlist_detailview.html | 42 +++++++ webcit/subst.c | 17 +-- webcit/useredit.c | 146 ++++++++++++++++++++--- webcit/webcit.h | 4 +- 6 files changed, 204 insertions(+), 28 deletions(-) create mode 100644 webcit/static/t/userlist_detailview.html diff --git a/webcit/http_datestring.c b/webcit/http_datestring.c index 33f578464..d4c69bf6c 100644 --- a/webcit/http_datestring.c +++ b/webcit/http_datestring.c @@ -64,4 +64,25 @@ void http_datestring(char *buf, size_t n, time_t xtime) { } +void tmplput_nowstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + time_t now; + now = time(NULL); + StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0); +} +void tmplput_nowno(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) +{ + time_t now; + now = time(NULL); + StrBufAppendPrintf(Target, "%l", now); +} + +void +InitModule_DATE +(void) +{ + RegisterNamespace("DATE:NOW:STR", 1, 2, tmplput_nowstr, CTX_NONE); + RegisterNamespace("DATE:NOW:NO", 1, 2, tmplput_nowno, CTX_NONE); +} + /*@}*/ diff --git a/webcit/notes.c b/webcit/notes.c index 58e9bc850..d08b0777f 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -347,7 +347,7 @@ void display_note(long msgnum, int unread) { if (v) { // display_vnote_div(v); DoTemplate(HKEY("vnoteitem"), - v, WC->WBuf, CTX_VNOTE); + WC->WBuf, v, CTX_VNOTE); /* uncomment these lines to see ugly debugging info diff --git a/webcit/static/t/userlist_detailview.html b/webcit/static/t/userlist_detailview.html new file mode 100644 index 000000000..b0e5e9e3d --- /dev/null +++ b/webcit/static/t/userlist_detailview.html @@ -0,0 +1,42 @@ + + + + +
+
+
+
+"> +"> + + + +
+ + + + + + + + + + +
" maxlength="63">
" maxlength="20">
>
+">  ">

+
+
+ diff --git a/webcit/subst.c b/webcit/subst.c index d5297d14c..6ede4a74c 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -815,6 +815,7 @@ int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmp ChrPtr(pTmpl->FileName), Token->Line, ChrPtr(Token->FlatToken)); + return 0; } Cond = (ConditionalStruct *) vConditional; @@ -1150,7 +1151,7 @@ const char* PrintTemplate(void *vSubst) * \brief Display a variable-substituted template * \param templatename template file to load */ -void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType) +void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType) { HashList *Static; HashList *StaticLocal; @@ -1383,7 +1384,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo It->DoSubTemplate(SubBuf, vContext, Tokens); DoTemplate(Tokens->Params[1]->Start, Tokens->Params[1]->len, - vContext, SubBuf, + SubBuf, vContext, It->ContextType); StrBufAppendBuf(Target, SubBuf, 0); @@ -1472,19 +1473,19 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con StrBuf *Headline = NewStrBuf(); DoTemplate(Tokens->Params[1]->Start, Tokens->Params[1]->len, - Context, Headline, + Context, ContextType); SVPutBuf("BOXTITLE", Headline, 0); } - DoTemplate(HKEY("beginbox"), Context, Target, ContextType); + DoTemplate(HKEY("beginbox"), Target, Context, ContextType); DoTemplate(Tokens->Params[0]->Start, Tokens->Params[0]->len, - Context, Target, + Context, ContextType); - DoTemplate(HKEY("endbox"), Context, Target, ContextType); + DoTemplate(HKEY("endbox"), Target, Context, ContextType); } void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType) @@ -1500,8 +1501,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co if (Tokens->Params[i * 2]->len > 0) { DoTemplate(Tokens->Params[i * 2]->Start, Tokens->Params[i * 2]->len, - Context, TabNames[i], + Context, ContextType); } else { @@ -1516,8 +1517,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co DoTemplate(Tokens->Params[i * 2 + 1]->Start, Tokens->Params[i * 2 + 1]->len, - Context, Target, + Context, ContextType); StrEndTab(Target, i, nTabs); } diff --git a/webcit/useredit.c b/webcit/useredit.c index 19cbbf001..f016b2e21 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -102,16 +102,46 @@ void select_user_to_edit(char *message, char *preselect) typedef struct _UserListEntry { - StrBuf *UserName; - int AccessLevel; int UID; - StrBuf *LastLogon; - time_t LastLogonT; + int AccessLevel; int nLogons; int nPosts; + + StrBuf *UserName; StrBuf *Passvoid; + StrBuf *LastLogon; + time_t LastLogonT; + /* Just available for Single users to view: */ + unsigned int Flags; + int DaysTillPurge; } UserListEntry; + +UserListEntry* NewUserListOneEntry(StrBuf *SerializedUser) +{ + UserListEntry *ul; + + if (StrLength(SerializedUser) < 8) + return NULL; + + ul = (UserListEntry*) malloc(sizeof(UserListEntry)); + ul->UserName = NewStrBuf(); + ul->LastLogon = NewStrBuf(); + ul->Passvoid = NewStrBuf(); + + StrBufExtract_token(ul->UserName, SerializedUser, 0, '|'); + StrBufExtract_token(ul->Passvoid, SerializedUser, 1, '|'); + ul->Flags = (unsigned int)StrBufExtract_long(SerializedUser, 2, '|'); + ul->nLogons = StrBufExtract_int(SerializedUser, 3, '|'); + ul->nPosts = StrBufExtract_int(SerializedUser, 4, '|'); + ul->AccessLevel = StrBufExtract_int(SerializedUser, 5, '|'); + ul->UID = StrBufExtract_int(SerializedUser, 6, '|'); + StrBufExtract_token(ul->LastLogon, SerializedUser, 7, '|'); + /// TODO: ul->LastLogon -> ulLastLogonT + ul->DaysTillPurge = StrBufExtract_int(SerializedUser, 8, '|'); + return ul; +} + void DeleteUserListEntry(void *vUserList) { UserListEntry *ul = (UserListEntry*) vUserList; @@ -141,7 +171,8 @@ UserListEntry* NewUserListEntry(StrBuf *SerializedUserList) ul->nLogons = StrBufExtract_int(SerializedUserList, 4, '|'); ul->nPosts = StrBufExtract_int(SerializedUserList, 5, '|'); StrBufExtract_token(ul->Passvoid, SerializedUserList, 6, '|'); - + ul->Flags = 0; + ul->DaysTillPurge = -1; return ul; } @@ -353,12 +384,17 @@ void tmplput_USERLIST_UID(StrBuf *Target, int nArgs, WCTemplateToken *Token, voi StrBufAppendPrintf(Target, "%d", ul->UID, 0); } -void tmplput_USERLIST_LastLogon(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) +void tmplput_USERLIST_LastLogonNo(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) { UserListEntry *ul = (UserListEntry*) Context; StrBufAppendBuf(Target, ul->LastLogon, 0); } +void tmplput_USERLIST_LastLogonStr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) +{ + UserListEntry *ul = (UserListEntry*) Context; + StrEscAppend(Target, NULL, asctime(localtime(&ul->LastLogonT)), 0, 0); +} void tmplput_USERLIST_nLogons(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) { @@ -374,6 +410,20 @@ void tmplput_USERLIST_nPosts(StrBuf *Target, int nArgs, WCTemplateToken *Token, StrBufAppendPrintf(Target, "%d", ul->nPosts, 0); } +void tmplput_USERLIST_Flags(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) +{ + UserListEntry *ul = (UserListEntry*) Context; + + StrBufAppendPrintf(Target, "%d", ul->Flags, 0); +} + +void tmplput_USERLIST_DaysTillPurge(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType) +{ + UserListEntry *ul = (UserListEntry*) Context; + + StrBufAppendPrintf(Target, "%d", ul->DaysTillPurge, 0); +} + int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType) { UserListEntry *ul = (UserListEntry*) Context; @@ -386,7 +436,23 @@ int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType) else return 0; } - + +int ConditionalFlagINetEmail(WCTemplateToken *Tokens, void *Context, int ContextType) +{ + UserListEntry *ul = (UserListEntry*) Context; + return (ul->Flags & US_INTERNET) != 0; +} + +int ConditionalUserAccess(WCTemplateToken *Tokens, void *Context, int ContextType) +{ + UserListEntry *ul = (UserListEntry*) Context; + + if (Tokens->Params[3]->Type == TYPE_LONG) + return (Tokens->Params[3]->lvalue == ul->AccessLevel); + else + return 0; +} + /** * \brief Locate the message number of a user's vCard in the current room * \param username the plaintext name of the user @@ -504,9 +570,47 @@ void display_edit_address_book_entry(char *username, long usernum) { } +void display_edituser(char *supplied_username, int is_new) { + UserListEntry* UL; + StrBuf *Buf; + char error_message[1024]; + char MajorStatus; + char username[256]; + + if (supplied_username != NULL) { + safestrncpy(username, supplied_username, sizeof username); + } + else { + safestrncpy(username, bstr("username"), sizeof username); + } + + Buf = NewStrBuf(); + serv_printf("AGUP %s", username); + StrBuf_ServGetln(Buf); + MajorStatus = ChrPtr(Buf)[0]; + StrBufCutLeft(Buf, 4); + if (MajorStatus != '2') { + ///TODO ImportantMessage + sprintf(error_message, + "" + "%s

\n", ChrPtr(Buf)); + select_user_to_edit(error_message, username); + FreeStrBuf(&Buf); + return; + } + else { + UL = NewUserListOneEntry(Buf); + output_headers(1, 0, 0, 0, 1, 0); + DoTemplate(HKEY("userlist_detailview"), NULL, (void*) UL, CTX_USERLIST); + end_burst(); + + } + FreeStrBuf(&Buf); +} + -/** +/* * * \brief Edit a user. * If supplied_username is null, look in the "username" * web variable for the name of the user to edit. @@ -515,7 +619,7 @@ void display_edit_address_book_entry(char *username, long usernum) { * to send the user to the vCard editor next. * \param supplied_username user to look up or NULL if to search in the environment * \param is_new should we create the user? - */ + * / void display_edituser(char *supplied_username, int is_new) { char buf[1024]; char error_message[1024]; @@ -687,7 +791,7 @@ void display_edituser(char *supplied_username, int is_new) { wDumpContent(1); } - +*/ /** * \brief do the backend operation of the user edit on the server @@ -833,13 +937,21 @@ InitModule_USEREDIT WebcitAddUrlHandler(HKEY("edituser"), edituser, 0); WebcitAddUrlHandler(HKEY("create_user"), create_user, 0); - RegisterNamespace("USERLIST:USERNAME", 0, 1, tmplput_USERLIST_UserName, CTX_USERLIST); - RegisterNamespace("USERLIST:ACCLVLNO", 0, 0, tmplput_USERLIST_AccessLevelNo, CTX_USERLIST); - RegisterNamespace("USERLIST:ACCLVLSTR", 0, 0, tmplput_USERLIST_AccessLevelStr, CTX_USERLIST); - RegisterNamespace("USERLIST:UID", 0, 0, tmplput_USERLIST_UID, CTX_USERLIST); - RegisterNamespace("USERLIST:LASTLOGON", 0, 0, tmplput_USERLIST_LastLogon, CTX_USERLIST); - RegisterNamespace("USERLIST:NLOGONS", 0, 0, tmplput_USERLIST_nLogons, CTX_USERLIST); - RegisterNamespace("USERLIST:NPOSTS", 0, 0, tmplput_USERLIST_nPosts, CTX_USERLIST); + RegisterNamespace("USERLIST:USERNAME", 0, 1, tmplput_USERLIST_UserName, CTX_USERLIST); + RegisterNamespace("USERLIST:ACCLVLNO", 0, 0, tmplput_USERLIST_AccessLevelNo, CTX_USERLIST); + RegisterNamespace("USERLIST:ACCLVLSTR", 0, 0, tmplput_USERLIST_AccessLevelStr, CTX_USERLIST); + RegisterNamespace("USERLIST:UID", 0, 0, tmplput_USERLIST_UID, CTX_USERLIST); + RegisterNamespace("USERLIST:LASTLOGON:STR", 0, 0, tmplput_USERLIST_LastLogonStr, CTX_USERLIST); + RegisterNamespace("USERLIST:LASTLOGON:NO", 0, 0, tmplput_USERLIST_LastLogonNo, CTX_USERLIST); + RegisterNamespace("USERLIST:NLOGONS", 0, 0, tmplput_USERLIST_nLogons, CTX_USERLIST); + RegisterNamespace("USERLIST:NPOSTS", 0, 0, tmplput_USERLIST_nPosts, CTX_USERLIST); + + RegisterNamespace("USERLIST:FLAGS", 0, 0, tmplput_USERLIST_Flags, CTX_USERLIST); + RegisterNamespace("USERLIST:DAYSTILLPURGE", 0, 0, tmplput_USERLIST_DaysTillPurge, CTX_USERLIST); + + RegisterConditional(HKEY("COND:USERNAME"), 0, ConditionalUser, CTX_USERLIST); + RegisterConditional(HKEY("COND:USERACCESS"), 0, ConditionalUserAccess, CTX_USERLIST); + RegisterConditional(HKEY("COND:USERLIST:FLAG:USE_INTERNET"), 0, ConditionalFlagINetEmail, CTX_USERLIST); RegisterConditional(HKEY("COND:USERNAME"), 0, ConditionalUser, CTX_USERLIST); RegisterIterator("USERLIST", 0, NULL, iterate_load_userlist, NULL, DeleteHash, CTX_USERLIST); diff --git a/webcit/webcit.h b/webcit/webcit.h index 9ba816a3c..9c1a0583b 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -352,8 +352,8 @@ void SVCallback(char *keyname, size_t keylen, WCHandlerFunc fcn_ptr); void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref); #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c) -void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType); -#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL, 0); +void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType); +#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, b, 0); void url_do_template(void); int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup); -- 2.30.2