use the same way to display all banners and services contents
[citadel.git] / webcit / useredit.c
index cc3c5bd198308bebfa165ec8a2ffee819c2a2dc4..16f4c48f72c5324a028c70ad83677e67be428786 100644 (file)
 /*
  * $Id$
- *
- * Administrative screen to add/change/delete user accounts
+ */
+/**
+ * \defgroup AdminTasks Administrative screen to add/change/delete user accounts
+ * \ingroup CitadelConfig
  *
  */
+/*@{*/
 
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <limits.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
 #include "webcit.h"
 #include "webserver.h"
 
 
-
-
-
+/**
+ * \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(1, 1, 2, 0, 1, 0, 0);
+       output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
-       wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
-               "<td>"
-               "<span class=\"titlebar\">"
-               "<img src=\"/static/usermanag_48x.gif\">"
-               "Edit or delete users"
-               "</span></td></tr></table>\n"
-               "</div>\n<div id=\"content\">\n"
-       );
+       wprintf("<img src=\"static/usermanag_48x.gif\">");
+        wprintf("<h1>");
+       wprintf(_("Edit or delete users"));
+        wprintf("</h1>");
+        wprintf("</div>");
+
+        wprintf("<div id=\"content\" class=\"service\">\n");
 
        if (message != NULL) wprintf(message);
 
-       wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP><TD>\n");
+       wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
 
-       svprintf("BOXTITLE", WCS_STRING, "Add users");
+       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'.<br /><br />");
+       wprintf(_("To create a new user account, enter the desired "
+               "user name in the box below and click 'Create'."));
+       wprintf("<br /><br />");
 
-        wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/create_user\">\n");
-        wprintf("New user: ");
-        wprintf("<input type=text name=username><br />\n"
-               "<input type=submit value=\"Create\">"
-               "</FORM></CENTER>\n");
+        wprintf("<center><form method=\"POST\" action=\"create_user\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+        wprintf(_("New user: "));
+        wprintf("<input type=\"text\" name=\"username\"><br />\n"
+               "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
+               "</form></center>\n", _("Create"));
 
        do_template("endbox");
 
-       wprintf("</TD><TD>");
+       wprintf("</td><td>");
 
-       svprintf("BOXTITLE", WCS_STRING, "Edit or Delete users");
+       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'.<br /><br />");
+       wprintf(_("To edit an existing user account, select the user "
+               "name from the list and click 'Edit'."));
+       wprintf("<br /><br />");
        
-        wprintf("<CENTER>"
-               "<FORM METHOD=\"POST\" ACTION=\"/display_edituser\">\n");
-        wprintf("<SELECT NAME=\"username\" SIZE=10 STYLE=\"width:100%%\">\n");
+        wprintf("<center>"
+               "<form method=\"POST\" action=\"display_edituser\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+        wprintf("<select name=\"username\" size=10 style=\"width:100%%\">\n");
         serv_puts("LIST");
         serv_getln(buf, sizeof buf);
         if (buf[0] == '1') {
                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                         extract_token(username, buf, 0, '|', sizeof username);
-                        wprintf("<OPTION");
+                        wprintf("<option");
                        if (preselect != NULL)
                           if (!strcasecmp(username, preselect))
-                             wprintf(" SELECTED");
+                             wprintf(" selected");
                        wprintf(">");
                         escputs(username);
                         wprintf("\n");
                 }
         }
-        wprintf("</SELECT><br />\n");
+        wprintf("</select><br />\n");
 
-        wprintf("<input type=submit name=sc value=\"Edit configuration\">");
-        wprintf("<input type=submit name=sc value=\"Edit address book entry\">");
-        wprintf("<input type=submit name=sc value=\"Delete user\" "
-               "onClick=\"return confirm('Delete this user?');\">");
-        wprintf("</FORM></CENTER>\n");
+        wprintf("<input type=\"submit\" name=\"edit_config_button\" value=\"%s\">", _("Edit configuration"));
+        wprintf("<input type=\"submit\" name=\"edit_abe_button\" value=\"%s\">", _("Edit address book entry"));
+        wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
+               "onClick=\"return confirm('%s');\">", _("Delete user"), _("Delete this user?"));
+        wprintf("</form></center>\n");
        do_template("endbox");
 
-       wprintf("</TD></TR></TABLE>\n");
+       wprintf("</td></tr></table>\n");
 
        wDumpContent(1);
 }
 
 
 
-/* 
- * Locate the message number of a user's vCard in the current room
+/**
+ * \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];
@@ -126,7 +117,7 @@ long locate_user_vcard(char *username, long usernum) {
        struct stuff_t *ptr;
 
 TRYAGAIN:
-       /* Search for the user's vCard */
+       /** 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")) {
@@ -136,7 +127,7 @@ TRYAGAIN:
                stuff = ptr;
        }
 
-       /* Iterate through the message list looking for vCards */
+       /** Iterate through the message list looking for vCards */
        while (stuff != NULL) {
                serv_printf("MSG0 %ld|2", stuff->msgnum);
                serv_getln(buf, sizeof buf);
@@ -145,8 +136,8 @@ TRYAGAIN:
                                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")) {
+                                       if (  (!strcasecmp(content_type, "text/x-vcard"))
+                                          || (!strcasecmp(content_type, "text/vcard")) ) {
                                                vcard_msgnum = stuff->msgnum;
                                        }
                                }
@@ -158,7 +149,7 @@ TRYAGAIN:
                stuff = ptr;
        }
 
-       /* If there's no vcard, create one */
+       /** 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");
@@ -177,8 +168,10 @@ TRYAGAIN:
 }
 
 
-/* 
- * Display the form for editing a user's address book entry
+/**
+ * \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_edit_address_book_entry(char *username, long usernum) {
        char roomname[SIZ];
@@ -186,7 +179,7 @@ void display_edit_address_book_entry(char *username, long usernum) {
        char error_message[SIZ];
        long vcard_msgnum = (-1L);
 
-       /* Locate the user's config room, creating it if necessary */
+       /** 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);
@@ -197,7 +190,7 @@ void display_edit_address_book_entry(char *username, long usernum) {
                serv_getln(buf, sizeof buf);
                if (buf[0] != '2') {
                        sprintf(error_message,
-                               "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                               "<img src=\"static/error.gif\" align=center>"
                                "%s<br /><br />\n", &buf[4]);
                        select_user_to_edit(error_message, username);
                        return;
@@ -208,34 +201,36 @@ void display_edit_address_book_entry(char *username, long usernum) {
 
        if (vcard_msgnum < 0) {
                sprintf(error_message,
-                       "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                       "Could not create/edit vCard"
-                       "<br /><br />\n"
+                       "<img src=\"static/error.gif\" align=center>%s<br /><br />\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");
+       do_edit_vcard(vcard_msgnum, "1", "select_user_to_edit");
 }
 
 
 
 
-/*
- * Edit a user.  If supplied_username is null, look in the "username"
+/**
+ * \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[SIZ];
-       char error_message[SIZ];
+       char buf[1024];
+       char error_message[1024];
        time_t now;
 
-       char username[SIZ];
-       char password[SIZ];
+       char username[256];
+       char password[256];
        unsigned int flags;
        int timescalled;
        int msgsposted;
@@ -256,7 +251,7 @@ void display_edituser(char *supplied_username, int is_new) {
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                sprintf(error_message,
-                       "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                       "<img src=\"static/error.gif\" align=center>"
                        "%s<br /><br />\n", &buf[4]);
                select_user_to_edit(error_message, username);
                return;
@@ -272,122 +267,156 @@ void display_edituser(char *supplied_username, int is_new) {
        lastcall = extract_long(&buf[4], 7);
        purgedays = extract_long(&buf[4], 8);
 
-       if (!strcmp(bstr("sc"), "Edit address book entry")) {
+       if (!IsEmptyStr(bstr("edit_abe_button"))) {
                display_edit_address_book_entry(username, usernum);
                return;
        }
 
-       if (!strcmp(bstr("sc"), "Delete user")) {
+       if (!IsEmptyStr(bstr("delete_button"))) {
                delete_user(username);
                return;
        }
 
-       output_headers(1, 1, 2, 0, 0, 0, 0);
+       output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">"
-               "Edit user account: ");
+       wprintf("<h1>");
+       wprintf(_("Edit user account: "));
        escputs(username);
-       wprintf("</SPAN></TD></TR></TABLE>\n");
-       wprintf("</div>\n<div id=\"content\">\n");
+        wprintf("</h1>");
+        wprintf("</div>");
+
+        wprintf("<div id=\"content\" class=\"service\">\n");
 
-       wprintf("<div id=\"fix_scrollbar_bug\">"
-               "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
-       wprintf("<FORM METHOD=\"POST\" ACTION=\"/edituser\">\n"
-               "<INPUT TYPE=\"hidden\" NAME=\"username\" VALUE=\"");
+       wprintf("<div class=\"fix_scrollbar_bug\">"
+               "<table class=\"useredit_background\"><tr><td>\n");
+       wprintf("<form method=\"POST\" action=\"edituser\">\n"
+               "<input type=\"hidden\" name=\"username\" value=\"");
        escputs(username);
        wprintf("\">\n");
-       wprintf("<INPUT TYPE=\"hidden\" NAME=\"is_new\" VALUE=\"%d\">\n"
-               "<INPUT TYPE=\"hidden\" NAME=\"usernum\" VALUE=\"%ld\">\n",
+       wprintf("<input type=\"hidden\" name=\"is_new\" value=\"%d\">\n"
+               "<input type=\"hidden\" name=\"usernum\" value=\"%ld\">\n",
                is_new, usernum);
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
 
-       wprintf("<INPUT TYPE=\"hidden\" NAME=\"flags\" VALUE=\"%d\">\n", flags);
+       wprintf("<input type=\"hidden\" name=\"flags\" value=\"%d\">\n", flags);
 
-       wprintf("<CENTER><TABLE>");
+       wprintf("<center><table>");
 
-       wprintf("<TR><TD>Password</TD><TD>"
-               "<INPUT TYPE=\"password\" NAME=\"password\" VALUE=\"");
+       wprintf("<tr><td>");
+       wprintf(_("Password"));
+       wprintf("</td><td>"
+               "<input type=\"password\" name=\"password\" value=\"");
        escputs(password);
-       wprintf("\" MAXLENGTH=\"20\"></TD></TR>\n");
+       wprintf("\" maxlength=\"20\"></td></tr>\n");
+
+       wprintf("<tr><td>");
+       wprintf(_("Permission to send Internet mail"));
+       wprintf("</td><td>");
+       wprintf("<input type=\"checkbox\" name=\"inetmail\" value=\"yes\" ");
+       if (flags & US_INTERNET) {
+               wprintf("checked ");
+       }
+       wprintf("></td></tr>\n");
 
-       wprintf("<TR><TD>Times logged in</TD><TD>"
-               "<INPUT TYPE=\"text\" NAME=\"timescalled\" VALUE=\"");
+       wprintf("<tr><td>");
+       wprintf(_("Number of logins"));
+       wprintf("</td><td>"
+               "<input type=\"text\" name=\"timescalled\" value=\"");
        wprintf("%d", timescalled);
-       wprintf("\" MAXLENGTH=\"6\"></TD></TR>\n");
+       wprintf("\" maxlength=\"6\"></td></tr>\n");
 
-       wprintf("<TR><TD>Messages posted</TD><TD>"
-               "<INPUT TYPE=\"text\" NAME=\"msgsposted\" VALUE=\"");
+       wprintf("<tr><td>");
+       wprintf(_("Messages submitted"));
+       wprintf("</td><td>"
+               "<input type=\"text\" name=\"msgsposted\" value=\"");
        wprintf("%d", msgsposted);
-       wprintf("\" MAXLENGTH=\"6\"></TD></TR>\n");
+       wprintf("\" maxlength=\"6\"></td></tr>\n");
 
-       wprintf("<TR><TD>Access level</TD><TD>"
-               "<SELECT NAME=\"axlevel\">\n");
+       wprintf("<tr><td>");
+       wprintf(_("Access level"));
+       wprintf("</td><td>"
+               "<select name=\"axlevel\">\n");
        for (i=0; i<7; ++i) {
-               wprintf("<OPTION ");
+               wprintf("<option ");
                if (axlevel == i) {
-                       wprintf("SELECTED ");
+                       wprintf("selected ");
                }
-               wprintf("VALUE=\"%d\">%d - %s</OPTION>\n",
+               wprintf("value=\"%d\">%d - %s</option>\n",
                        i, i, axdefs[i]);
        }
-       wprintf("</SELECT></TD></TR>\n");
+       wprintf("</select></td></tr>\n");
 
-       wprintf("<TR><TD>User ID number</TD><TD>"
-               "<INPUT TYPE=\"text\" NAME=\"usernum\" VALUE=\"");
+       wprintf("<tr><td>");
+       wprintf(_("User ID number"));
+       wprintf("</td><td>"
+               "<input type=\"text\" name=\"usernum\" value=\"");
        wprintf("%ld", usernum);
-       wprintf("\" MAXLENGTH=\"7\"></TD></TR>\n");
+       wprintf("\" maxlength=\"7\"></td></tr>\n");
 
        now = time(NULL);
-       wprintf("<TR><TD>Date/time of last login</TD><TD>"
-               "<SELECT NAME=\"lastcall\">\n");
+       wprintf("<tr><td>");
+       wprintf(_("Date and time of last login"));
+       wprintf("</td><td>"
+               "<select name=\"lastcall\">\n");
 
-       wprintf("<OPTION SELECTED VALUE=\"%ld\">", lastcall);
+       wprintf("<option selected value=\"%ld\">", lastcall);
        escputs(asctime(localtime(&lastcall)));
-       wprintf("</OPTION>\n");
+       wprintf("</option>\n");
 
-       wprintf("<OPTION VALUE=\"%ld\">", now);
+       wprintf("<option value=\"%ld\">", now);
        escputs(asctime(localtime(&now)));
-       wprintf("</OPTION>\n");
+       wprintf("</option>\n");
 
-       wprintf("</SELECT></TD></TR>");
+       wprintf("</select></td></tr>");
 
-       wprintf("<TR><TD>Auto-purge after days</TD><TD>"
-               "<INPUT TYPE=\"text\" NAME=\"purgedays\" VALUE=\"");
+       wprintf("<tr><td>");
+       wprintf(_("Auto-purge after this many days"));
+       wprintf("</td><td>"
+               "<input type=\"text\" name=\"purgedays\" value=\"");
        wprintf("%d", purgedays);
-       wprintf("\" MAXLENGTH=\"5\"></TD></TR>\n");
+       wprintf("\" maxlength=\"5\"></td></tr>\n");
 
-       wprintf("</TABLE>\n");
+       wprintf("</table>\n");
 
-       wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"OK\">\n"
+       wprintf("<input type=\"submit\" name=\"ok_button\" value=\"%s\">\n"
                "&nbsp;"
-               "<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n"
-               "<br /><br /></FORM>\n");
+               "<input type=\"submit\" name=\"cancel\" value=\"%s\">\n"
+               "<br /><br /></form>\n", _("Save changes"), _("Cancel"));
 
-       wprintf("</CENTER>\n");
+       wprintf("</center>\n");
        wprintf("</td></tr></table></div>\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 (strcasecmp(bstr("action"), "OK")) {
-               safestrncpy(message, "Edit user cancelled.", sizeof message);
+       if (IsEmptyStr(bstr("ok_button"))) {
+               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|%s|%s|%s|%s|%s|%s|%s|",
+               serv_printf("ASUP %s|%s|%d|%s|%s|%s|%s|%s|%s|",
                        bstr("username"),
                        bstr("password"),
-                       bstr("flags"),
+                       flags,
                        bstr("timescalled"),
                        bstr("msgsposted"),
                        bstr("axlevel"),
@@ -398,7 +427,7 @@ void edituser(void) {
                serv_getln(buf, sizeof buf);
                if (buf[0] != '2') {
                        sprintf(message,
-                               "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                               "<img src=\"static/error.gif\" align=center>"
                                "%s<br /><br />\n", &buf[4]);
                }
                else {
@@ -406,7 +435,8 @@ void edituser(void) {
                }
        }
 
-       /* If we are in the middle of creating a new user, move on to
+       /**
+        * If we are in the middle of creating a new user, move on to
         * the vCard edit screen.
         */
        if (is_new) {
@@ -417,7 +447,10 @@ void edituser(void) {
        }
 }
 
-
+/**
+ * \brief burge a user 
+ * \param username the name of the user to remove
+ */
 void delete_user(char *username) {
        char buf[SIZ];
        char message[SIZ];
@@ -426,7 +459,7 @@ void delete_user(char *username) {
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                sprintf(message,
-                       "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                       "<img src=\"static/error.gif\" align=center>"
                        "%s<br /><br />\n", &buf[4]);
        }
        else {
@@ -437,7 +470,10 @@ void delete_user(char *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];
@@ -449,16 +485,19 @@ void create_user(void) {
        serv_getln(buf, sizeof buf);
 
        if (buf[0] == '2') {
-               /* sprintf(error_message, "<b>User has been created.</b>");
-               select_user_to_edit(error_message, username); */
+               sprintf(WC->ImportantMessage,
+                       _("A new user has been created."));
                display_edituser(username, 1);
        }
        else {
                sprintf(error_message,
-                       "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                       "<img src=\"static/error.gif\" align=center>"
                        "%s<br /><br />\n", &buf[4]);
                select_user_to_edit(error_message, NULL);
        }
 
 }
 
+
+
+/*@}*/