X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fuseredit.c;h=06b54b1759955d04e0dd232431d4782076e03ac9;hb=bedf5c0b955473d8ad02eaf628e8d209f534f2b6;hp=4904e9fe56cbb0ffbe0a4f66f98ad4b4145c65f1;hpb=f0a28ed307058c0f5d1edeb3fd315aba47a858de;p=citadel.git diff --git a/webcit/useredit.c b/webcit/useredit.c index 4904e9fe5..06b54b175 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -1,96 +1,237 @@ /* - * Administrative screen to add/change/delete user accounts + * $Id$ + */ +/** + * \defgroup AdminTasks Administrative screen to add/change/delete user accounts + * \ingroup CitadelConfig * */ +/*@{*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "webcit.h" +#include "webserver.h" - - - -void select_user_to_edit(char *message) +/** + * \brief show a list of available users to edit them + * \param message the header message??? + * \param preselect which user should be selected in the browser + */ +void select_user_to_edit(char *message, char *preselect) { char buf[SIZ]; char username[SIZ]; - output_headers(3); /* No room banner on this screen */ + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n"); + wprintf("" + "
" + "" + ""); + wprintf(_("Edit or delete users")); + wprintf("
\n" + "
\n
\n" + ); if (message != NULL) wprintf(message); - wprintf("
"); - wprintf("" - "Add/change/delete user accounts" - "
\n"); + wprintf("
\n"); + + svprintf("BOXTITLE", WCS_STRING, _("Add users")); + do_template("beginbox"); + + wprintf(_("To create a new user account, enter the desired " + "user name in the box below and click 'Create'.")); + wprintf("

"); + + wprintf("
\n"); + wprintf("\n", WC->nonce); + wprintf(_("New user: ")); + wprintf("
\n" + "" + "
\n", _("Create")); + + do_template("endbox"); - wprintf("" - "
To edit an existing user account, select the user " - "name from the list and click 'Edit'.

"); + wprintf("
"); + + svprintf("BOXTITLE", WCS_STRING, _("Edit or Delete users")); + do_template("beginbox"); + + wprintf(_("To edit an existing user account, select the user " + "name from the list and click 'Edit'.")); + wprintf("

"); - wprintf("
\n"); - wprintf("\n", WC->nonce); + wprintf("
\n"); - - wprintf(""); - wprintf("
\n"); + wprintf("
\n"); - wprintf("
" - "To create a new user account, enter the desired " - "user name in the box below and click 'Create'.

"); + wprintf("", _("Edit configuration")); + wprintf("", _("Edit address book entry")); + wprintf("", _("Delete user"), _("Delete this user?")); + wprintf("\n"); + do_template("endbox"); - wprintf("
\n"); - wprintf("New user: "); - wprintf("
\n" - "" - "
\n"); - - wprintf("
\n"); + wprintf("
\n"); wDumpContent(1); } -/* - * Edit a user. If supplied_username is null, look in the "username" - * web variable for the name of the user to edit. +/** + * \brief Locate the message number of a user's vCard in the current room + * \param username the plaintext name of the user + * \param usernum the number of the user on the citadel server + * \return the message id of his vcard + */ +long locate_user_vcard(char *username, long usernum) { + char buf[SIZ]; + long vcard_msgnum = (-1L); + char content_type[SIZ]; + char partnum[SIZ]; + int already_tried_creating_one = 0; + + struct stuff_t { + struct stuff_t *next; + long msgnum; + }; + + struct stuff_t *stuff = NULL; + struct stuff_t *ptr; + +TRYAGAIN: + /** Search for the user's vCard */ + serv_puts("MSGS ALL"); + serv_getln(buf, sizeof buf); + if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + ptr = malloc(sizeof(struct stuff_t)); + ptr->msgnum = atol(buf); + ptr->next = stuff; + stuff = ptr; + } + + /** Iterate through the message list looking for vCards */ + while (stuff != NULL) { + serv_printf("MSG0 %ld|2", stuff->msgnum); + serv_getln(buf, sizeof buf); + if (buf[0]=='1') { + while(serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + if (!strncasecmp(buf, "part=", 5)) { + extract_token(partnum, &buf[5], 2, '|', sizeof partnum); + extract_token(content_type, &buf[5], 4, '|', sizeof content_type); + if ( (!strcasecmp(content_type, "text/x-vcard")) + || (!strcasecmp(content_type, "text/vcard")) ) { + vcard_msgnum = stuff->msgnum; + } + } + } + } + + ptr = stuff->next; + free(stuff); + stuff = ptr; + } + + /** If there's no vcard, create one */ + if (vcard_msgnum < 0) if (already_tried_creating_one == 0) { + already_tried_creating_one = 1; + serv_puts("ENT0 1|||4"); + serv_getln(buf, sizeof buf); + if (buf[0] == '4') { + serv_puts("Content-type: text/x-vcard"); + serv_puts(""); + serv_puts("begin:vcard"); + serv_puts("end:vcard"); + serv_puts("000"); + } + goto TRYAGAIN; + } + + return(vcard_msgnum); +} + + +/** + * \brief Display the form for editing a user's address book entry + * \param username the name of the user + * \param usernum the citadel-uid of the user */ -void display_edituser(char *supplied_username) { +void display_edit_address_book_entry(char *username, long usernum) { + char roomname[SIZ]; char buf[SIZ]; char error_message[SIZ]; + long vcard_msgnum = (-1L); - char username[SIZ]; - char password[SIZ]; + /** Locate the user's config room, creating it if necessary */ + sprintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM); + serv_printf("GOTO %s||1", roomname); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + serv_printf("CRE8 1|%s|5|||1|", roomname); + serv_getln(buf, sizeof buf); + serv_printf("GOTO %s||1", roomname); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + sprintf(error_message, + "" + "%s

\n", &buf[4]); + select_user_to_edit(error_message, username); + return; + } + } + + vcard_msgnum = locate_user_vcard(username, usernum); + + if (vcard_msgnum < 0) { + sprintf(error_message, + "%s

\n", + _("An error occurred while trying to create or edit this address book entry.") + ); + select_user_to_edit(error_message, username); + return; + } + + do_edit_vcard(vcard_msgnum, "1", "select_user_to_edit"); +} + + + + +/** + * \brief Edit a user. + * If supplied_username is null, look in the "username" + * web variable for the name of the user to edit. + * + * If "is_new" is set to nonzero, this screen will set the web variables + * 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]; + time_t now; + + char username[256]; + char password[256]; unsigned int flags; int timescalled; int msgsposted; @@ -98,26 +239,27 @@ void display_edituser(char *supplied_username) { long usernum; time_t lastcall; int purgedays; + int i; if (supplied_username != NULL) { - strcpy(username, supplied_username); + safestrncpy(username, supplied_username, sizeof username); } else { - strcpy(username, bstr("username") ); + safestrncpy(username, bstr("username"), sizeof username); } serv_printf("AGUP %s", username); - serv_gets(buf); + serv_getln(buf, sizeof buf); if (buf[0] != '2') { sprintf(error_message, - "" - "%s

\n", &buf[4]); - select_user_to_edit(error_message); + "" + "%s

\n", &buf[4]); + select_user_to_edit(error_message, username); return; } - extract(username, &buf[4], 0); - extract(password, &buf[4], 1); + extract_token(username, &buf[4], 0, '|', sizeof username); + extract_token(password, &buf[4], 1, '|', sizeof password); flags = extract_int(&buf[4], 2); timescalled = extract_int(&buf[4], 3); msgsposted = extract_int(&buf[4], 4); @@ -126,40 +268,236 @@ void display_edituser(char *supplied_username) { lastcall = extract_long(&buf[4], 7); purgedays = extract_long(&buf[4], 8); - output_headers(3); /* No room banner on this screen */ - wprintf("
"); - wprintf("" - "Edit user account: "); - escputs(username); - wprintf("
\n"); + if (strlen(bstr("edit_abe_button")) > 0) { + display_edit_address_book_entry(username, usernum); + return; + } + if (strlen(bstr("delete_button")) > 0) { + delete_user(username); + return; + } - wprintf("this is %s", username); + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n"); + wprintf("
"); + wprintf(""); + wprintf(_("Edit user account: ")); + escputs(username); + wprintf("
\n"); + wprintf("
\n
\n"); + wprintf("
" + "
\n"); + wprintf("
\n" + "\n"); + wprintf("\n" + "\n", + is_new, usernum); + wprintf("\n", WC->nonce); + + wprintf("\n", flags); + + wprintf("
"); + + wprintf("\n"); + + wprintf("\n"); + + wprintf("\n"); + + wprintf("\n"); + + wprintf("\n"); + + wprintf("\n"); + + now = time(NULL); + wprintf(""); + + wprintf("\n"); + + wprintf("
"); + wprintf(_("Password")); + wprintf("" + "
"); + wprintf(_("Permission to send Internet mail")); + wprintf(""); + wprintf("
"); + wprintf(_("Number of logins")); + wprintf("" + "
"); + wprintf(_("Messages submitted")); + wprintf("" + "
"); + wprintf(_("Access level")); + wprintf("" + "
"); + wprintf(_("User ID number")); + wprintf("" + "
"); + wprintf(_("Date and time of last login")); + wprintf("" + "
"); + wprintf(_("Auto-purge after this many days")); + wprintf("" + "
\n"); + + wprintf("\n" + " " + "\n" + "

\n", _("Save changes"), _("Cancel")); + + wprintf("
\n"); + wprintf("
\n"); wDumpContent(1); } +/** + * \brief do the backend operation of the user edit on the server + */ +void edituser(void) { + char message[SIZ]; + char buf[SIZ]; + int is_new = 0; + unsigned int flags = 0; + + is_new = atoi(bstr("is_new")); + + if (strlen(bstr("ok_button")) == 0) { + safestrncpy(message, _("Changes were not saved."), sizeof message); + } + else { + flags = atoi(bstr("flags")); + if (!strcasecmp(bstr("inetmail"), "yes")) { + flags |= US_INTERNET; + } + else { + flags &= ~US_INTERNET ; + } + + serv_printf("ASUP %s|%s|%d|%s|%s|%s|%s|%s|%s|", + bstr("username"), + bstr("password"), + flags, + bstr("timescalled"), + bstr("msgsposted"), + bstr("axlevel"), + bstr("usernum"), + bstr("lastcall"), + bstr("purgedays") + ); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + sprintf(message, + "" + "%s

\n", &buf[4]); + } + else { + safestrncpy(message, "", sizeof message); + } + } + /** + * If we are in the middle of creating a new user, move on to + * the vCard edit screen. + */ + if (is_new) { + display_edit_address_book_entry( bstr("username"), atol(bstr("usernum")) ); + } + else { + select_user_to_edit(message, bstr("username")); + } +} + +/** + * \brief burge a user + * \param username the name of the user to remove + */ +void delete_user(char *username) { + char buf[SIZ]; + char message[SIZ]; + + serv_printf("ASUP %s|0|0|0|0|0|", username); + serv_getln(buf, sizeof buf); + if (buf[0] != '2') { + sprintf(message, + "" + "%s

\n", &buf[4]); + } + else { + safestrncpy(message, "", sizeof message); + } + select_user_to_edit(message, bstr("username")); +} + + + +/** + * \brief create a new user + * take the web environment username and create it on the citadel server + */ void create_user(void) { char buf[SIZ]; char error_message[SIZ]; char username[SIZ]; - strcpy(username, bstr("username")); + safestrncpy(username, bstr("username"), sizeof username); serv_printf("CREU %s", username); - serv_gets(buf); + serv_getln(buf, sizeof buf); if (buf[0] == '2') { - display_edituser(username); + sprintf(WC->ImportantMessage, + _("A new user has been created.")); + display_edituser(username, 1); } else { sprintf(error_message, - "" - "%s

\n", &buf[4]); - select_user_to_edit(error_message); + "" + "%s

\n", &buf[4]); + select_user_to_edit(error_message, NULL); } } + + + +/*@}*/