/*
* Client-side support functions.
*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2016 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.
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
-#ifdef HAVE_UTMP_H
-#include <utmp.h>
-#endif
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#endif
#include <libcitadel.h>
-///#include "citadel.h"
#include "citadel_ipc.h"
#include "screen.h"
-#ifndef HAVE_GETUTLINE
-struct utmp *getutline(struct utmp *ut);
-#endif
-
#define ROUTINES_C
-///#include "citadel.h"
#include "routines.h"
#include "commands.h"
#include "citadel_decls.h"
#define IFNAIDE if (axlevel<AxAideU)
extern unsigned userflags;
-//extern char *axdefs[8];
extern char sigcaught;
extern char rc_floor_mode;
extern int rc_ansi_color;
}
}
+/*
+ * Edit a user's Internet email addresses
+ */
+void edit_user_internet_email_addresses(CtdlIPC *ipc, char *who)
+{
+ char buf[SIZ];
+ char *resp = NULL;
+ int num_recs = 0;
+ char **recs = NULL;
+ char ch;
+ int i, j;
+ int quitting = 0;
+ int modified = 0;
+ int r;
+ char emailaddrs[512];
+
+ r = CtdlIPCAideGetEmailAddresses(ipc, who, emailaddrs, buf);
+ if (r / 100 == 1) {
+ while (!IsEmptyStr(emailaddrs)) {
+ extract_token(buf, emailaddrs, 0, '\n', sizeof buf);
+ remove_token(emailaddrs, 0, '\n');
+ if (!IsEmptyStr(buf)) {
+ ++num_recs;
+ if (num_recs == 1) recs = malloc(sizeof(char *));
+ else recs = realloc(recs, (sizeof(char *)) * num_recs);
+ recs[num_recs-1] = malloc(strlen(buf) + 1);
+ strcpy(recs[num_recs-1], buf);
+ }
+ }
+ }
+
+ do {
+ scr_printf("\n");
+ color(BRIGHT_WHITE);
+ scr_printf(" Internet email addresses for %s\n", who);
+ color(DIM_WHITE);
+ scr_printf("--- --------------------------------------------------\n");
+ for (i=0; i<num_recs; ++i) {
+ color(DIM_WHITE);
+ scr_printf("%3d ", i+1);
+ color(BRIGHT_CYAN);
+ scr_printf("%s\n", recs[i]);
+ color(DIM_WHITE);
+ }
+
+ ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
+ switch(ch) {
+ case 'a':
+ newprompt("Enter new email address: ", buf, 50);
+ striplt(buf);
+ if (!IsEmptyStr(buf)) {
+ // FIXME validate the email address (format, our own domain, addr does not belong to another user)
+ ++num_recs;
+ if (num_recs == 1) {
+ recs = malloc(sizeof(char *));
+ }
+ else {
+ recs = realloc(recs, (sizeof(char *)) * num_recs);
+ }
+ recs[num_recs-1] = strdup(buf);
+ }
+ modified = 1;
+ break;
+ case 'd':
+ i = intprompt("Delete which address", 1, 1, num_recs) - 1;
+ free(recs[i]);
+ --num_recs;
+ for (j=i; j<num_recs; ++j) {
+ recs[j] = recs[j+1];
+ }
+ modified = 1;
+ break;
+ case 's':
+ r = 1;
+ for (i = 0; i < num_recs; i++)
+ r += 1 + strlen(recs[i]);
+ resp = (char *)calloc(1, r);
+ if (!resp) {
+ scr_printf("Can't save config - out of memory!\n");
+ logoff(ipc, 1);
+ }
+ if (num_recs) for (i = 0; i < num_recs; i++) {
+ strcat(resp, recs[i]);
+ strcat(resp, "\n");
+ }
+ r = CtdlIPCAideSetEmailAddresses(ipc, who, resp, buf);
+ if (r / 100 != 4) {
+ scr_printf("%s\n", buf);
+ } else {
+ scr_printf("Saved %d addresses.\n", num_recs);
+ modified = 0;
+ quitting = 1;
+ }
+ free(resp);
+ break;
+ case 'q':
+ quitting = !modified || boolprompt("Quit without saving", 0);
+ break;
+ default:
+ break;
+ }
+ } while (!quitting);
+
+ if (recs != NULL) {
+ for (i=0; i<num_recs; ++i) free(recs[i]);
+ free(recs);
+ }
+}
+
+
/*
* Edit or delete a user (cmd=25 to edit/create, 96 to delete)
*/
return;
}
- if (cmd == 25) {
- val_user(ipc, user->fullname, 0); /* Display registration */
+ if (cmd == 25) { // user edit
+
+ /* val_user(ipc, user->fullname, 0); we used to display the vCard here but there's really no need */
if (!newnow) {
change_name = 1;
}
user->axlevel = intprompt("Access level", user->axlevel, 0, 6);
- if (boolprompt("Permission to send Internet mail", (user->flags & US_INTERNET)))
+ if (boolprompt("Permission to send Internet mail", (user->flags & US_INTERNET))) {
user->flags |= US_INTERNET;
- else
+ }
+ else {
user->flags &= ~US_INTERNET;
- if (boolprompt("Ask user to register again", !(user->flags & US_REGIS)))
+ }
+ if (boolprompt("Ask user to register again", !(user->flags & US_REGIS))) {
user->flags &= ~US_REGIS;
- else
+ }
+ else {
user->flags |= US_REGIS;
- user->timescalled = intprompt("Times called",
- user->timescalled, 0, INT_MAX);
- user->posted = intprompt("Messages posted",
- user->posted, 0, INT_MAX);
- user->lastcall = boolprompt("Set last call to now", 0) ?
- time(NULL) : user->lastcall;
- user->USuserpurge = intprompt("Purge time (in days, 0 for system default",
- user->USuserpurge, 0, INT_MAX);
+ }
+ user->timescalled = intprompt("Times called", user->timescalled, 0, INT_MAX);
+ user->posted = intprompt("Messages posted", user->posted, 0, INT_MAX);
+ user->lastcall = boolprompt("Set last login to now", 0) ? time(NULL) : user->lastcall;
+ user->USuserpurge = intprompt("Purge time (in days, 0 for system default", user->USuserpurge, 0, INT_MAX);
}
if (cmd == 96) {
scr_printf("%s\n", buf);
}
free(user);
+
+ if (boolprompt("Edit this user's Internet email addresses", 0)) {
+ edit_user_internet_email_addresses(ipc, who);
+ }
+
}
}
-#ifndef HAVE_STRERROR
-/*
- * replacement strerror() for systems that don't have it
- */
-char *strerror(int e)
-{
- static char buf[128];
-
- snprintf(buf, sizeof buf, "errno = %d",e);
- return(buf);
-}
-#endif
-
-
void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax)
{
static char dots[] =
*/
void locate_host(CtdlIPC* ipc, char *hbuf)
{
-#ifndef HAVE_UTMP_H
- char buf[SIZ];
- FILE *who;
- int a,b;
-
- who = (FILE *)popen("who am i","r");
+ FILE *who = (FILE *)popen("who am i","r");
if (who==NULL) {
strcpy(hbuf, ipc->ServInfo.fqdn);
return;
}
- fgets(buf,sizeof buf,who);
+ fgets(hbuf, SIZ, who);
pclose(who);
-
- b = 0;
- for (a=0; !IsEmptyStr(&buf[a]); ++a) {
- if ((buf[a]=='(')||(buf[a]==')')) ++b;
- }
- if (b<2) {
- strcpy(hbuf, ipc->ServInfo.fqdn);
- return;
- }
-
- for (a=0; a<strlen(buf); ++a) {
- if (buf[a]=='(') {
- strcpy(buf,&buf[a+1]);
- }
- }
- for (a=0; a<strlen(buf); ++a) {
- if (buf[a]==')') buf[a] = 0;
- }
-
- if (IsEmptyStr(buf)) strcpy(hbuf, ipc->ServInfo.fqdn);
- else strncpy(hbuf,buf,24);
-#else
- char *tty = ttyname(0);
-#ifdef HAVE_GETUTXLINE
- struct utmpx ut, *put;
-#else
- struct utmp ut, *put;
-#endif
-
- if (tty == NULL) {
- fail:
- safestrncpy(hbuf, ipc->ServInfo.fqdn, 24);
- return;
- }
-
- if (strncmp(tty, "/dev/", 5))
- goto fail;
-
- safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
-
-#ifdef HAVE_GETUTXLINE /* Solaris uses this */
- if ((put = getutxline(&ut)) == NULL)
-#else
- if ((put = getutline(&ut)) == NULL)
-#endif
- goto fail;
-
-#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
- if (put->ut_type == USER_PROCESS) {
-#endif
-#if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
- if (*put->ut_host)
- safestrncpy(hbuf, put->ut_host, 24);
- else
-#endif
- safestrncpy(hbuf, put->ut_line, 24);
-#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
- }
- else goto fail;
-#endif
-#endif /* HAVE_UTMP_H */
+ stripallbut(hbuf, '(' , ')' );
}
/*