summaryrefslogtreecommitdiffstats
path: root/release/sysinstall/register.c
blob: b5200716da3108075dbf24548dad49dfe8270512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * The new sysinstall program.
 *
 * This is probably the last program in the `sysinstall' line - the next
 * generation being essentially a complete rewrite.
 *
 * $Id: register.c,v 1.7 1997/05/26 04:57:56 jkh Exp $
 *
 * Copyright (c) 1997
 *	Jordan Hubbard.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
 *    verbatim and that no modifications are made prior to this
 *    point in the file.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include "sysinstall.h"
#include <ctype.h>

#define REGISTER_HELPFILE	"register"
#define REGISTRATION_FNAME	"/new-registration"
#define REGISTRATION_ADDRESS	"register@freebsd.org"
#define MAJORDOMO_ADDRESS	"majordomo@freebsd.org"

#define FIRSTNAME_FIELD_LEN	25
#define LASTNAME_FIELD_LEN	30
#define EMAIL_FIELD_LEN		61
#define ADDRESS_FIELD_LEN	160
#define CITY_FIELD_LEN		20
#define STATE_FIELD_LEN		15
#define ZIP_FIELD_LEN		15

static char firstname[FIRSTNAME_FIELD_LEN], lastname[LASTNAME_FIELD_LEN],
    email[EMAIL_FIELD_LEN], address[ADDRESS_FIELD_LEN],
    city[CITY_FIELD_LEN], state[STATE_FIELD_LEN], zip[ZIP_FIELD_LEN];

static int	okbutton, cancelbutton;

/* What the screen size is meant to be */
#define REGISTER_DIALOG_Y		0
#define REGISTER_DIALOG_X		2
#define REGISTER_DIALOG_WIDTH		COLS - 4
#define REGISTER_DIALOG_HEIGHT		LINES - 2

static Layout layout[] = {
#define LAYOUT_LASTNAME		0
    { 1, 2, LASTNAME_FIELD_LEN - 1, LASTNAME_FIELD_LEN - 1,
      "Last Name:", "Your surname (family name) or company name should go here.",
      lastname, STRINGOBJ, NULL },
#define LAYOUT_FIRSTNAME	1
    { 1, 36, FIRSTNAME_FIELD_LEN - 1, FIRSTNAME_FIELD_LEN - 1,
      "First Name:", "Your given name or a contact name if registering for a company.",
      firstname, STRINGOBJ, NULL },
#define LAYOUT_EMAIL		2
    { 6, 2, EMAIL_FIELD_LEN - 1, EMAIL_FIELD_LEN - 1,
      "EMail Address:",
      "Where you'd like any announcement email sent, e.g. bsdmail@someplace.com",
      email, STRINGOBJ, NULL },
#define LAYOUT_ADDRESS		3
    { 10, 2, 60, ADDRESS_FIELD_LEN - 1,
      "Street address:", "Your street address, all in one line (optional).",
      address, STRINGOBJ, NULL },
#define LAYOUT_CITY		4
    { 14, 2, CITY_FIELD_LEN - 1, CITY_FIELD_LEN - 1,
      "City:", "Your city name (optional)",
      city, STRINGOBJ, NULL },
#define LAYOUT_STATE		5
    { 14, 26, STATE_FIELD_LEN - 1, STATE_FIELD_LEN - 1,
      "State / Province:",
      "Your local state or province.",
      state, STRINGOBJ, NULL },
#define LAYOUT_ZIP		5
    { 14, 50, ZIP_FIELD_LEN - 1, ZIP_FIELD_LEN - 1,
      "Zip / Country Code:",
      "Your U.S. Zip code or International country code (optional).",
      zip, STRINGOBJ, NULL },
#define LAYOUT_OKBUTTON		7
    { 18, 20, 0, 0,
      "OK", "Select this if you are happy with these settings",
      &okbutton, BUTTONOBJ, NULL },
#define LAYOUT_CANCELBUTTON	8
    { 18, 40, 0, 0,
      "CANCEL", "Select this if you wish to cancel this registration",
      &cancelbutton, BUTTONOBJ, NULL },
    { NULL },
};

/* Submenu selections */
#define COMMERCE_MAIL	0
#define COMMERCE_EMAIL	1
#define ANNOUNCE_LIST	2
#define NEWSLETTER	3

static struct { int y, x, sel; char *desc, *allowed; } hotspots[] = {
    { 5, 35, 0, "Do you wish to receive FreeBSD [ONLY!] related commercial mail?",         "Y" },
    { 5, 57, 0, "Do you wish to receive FreeBSD [ONLY!] related commercial email?",        "Y" },
    { 6, 35, 0, "Sign up (with majordomo@FreeBSD.org) for important announcements?",       "Y" },
    { 10, 35, 0, "Sign up for the FreeBSD Newsletter?  P = Postal (paper) copy, E = Email", "PE" },
};

/* Check the accuracy of user's choices before letting them move on */
static int
verifySettings(void)
{
    if (!lastname[0]) {
	msgConfirm("Missing last name / company name field.");
	return 0;
    }
    else if (email[0] && !index(email, '@'))
	return !msgYesNo("Hmmmm, this email address has no `@' in it.  Are you\n"
			 "sure that %s is a valid address?");
    else if (address[0] && !city[0]) {
	msgConfirm("Missing City name.");
	return 0;
    }
    else if (!email[0] && (hotspots[COMMERCE_EMAIL].sel || hotspots[NEWSLETTER].sel == 2)) {
	msgConfirm("You've signed up to receive commercial email or the newsletter by\n"
		   "email but have no email address specified!");
	return 0;
    }
    else if (!address[0] && (hotspots[COMMERCE_MAIL].sel || hotspots[NEWSLETTER].sel == 1)) {
	msgConfirm("You've signed up to receive commercial mail or the newsletter by\n"
		   "post but have no postal address specified!");
	return 0;
    }
    return 1;
}

/* Do the actual work of mailing out the registration once all is filled in */
static void
handle_registration(void)
{
    FILE *fp;
    WINDOW *save = savescr();

    dialog_clear_norefresh();
    (void)unlink(REGISTRATION_FNAME);
    fp = fopen(REGISTRATION_FNAME, "w");
    if (!fp) {
	msgConfirm("Unable to open %s for the new registration.\n"
		   "That's pretty bad!  Please fix whatever's wrong\n"
		   "and try this registration again.");
	restorescr(save);
	return;
    }
    fprintf(fp, "<entry>\n");
    fprintf(fp, "<first>%s</first>\n", firstname);
    fprintf(fp, "<last>%s</last>\n", lastname);
    fprintf(fp, "<email>%s</email>\n", email);
    fprintf(fp, "<address>%s</address>\n", address);
    fprintf(fp, "<city>%s</city>\n", city);
    fprintf(fp, "<state>%s</state>\n", state);
    fprintf(fp, "<zip>%s</zip>\n", zip);
    fprintf(fp, "<options commerce_email=\"%s\" commerce_mail=\"%s\" announce=\"%s\" newsletter=\"%s\"></options>\n",
	    hotspots[COMMERCE_EMAIL].sel ? "yes" : "no", hotspots[COMMERCE_MAIL].sel ? "yes" : "no",
	    hotspots[ANNOUNCE_LIST].sel ? "yes" : "no",
	    hotspots[NEWSLETTER].sel == 0 ? "no" : hotspots[NEWSLETTER].sel == 1 ? "postal" : "email"); 
    fprintf(fp, "<version>%s</version>\n", RELEASE_NAME);
    fprintf(fp, "</entry>\n");
    fclose(fp);
    dialog_clear_norefresh();
    if (!msgYesNo("Do you have a working network connection and outgoing email\n"
		  "enabled at this time?  I need to be able to reach freebsd.org\n"
		  "in order to submit your registration.")) {
	dialog_clear_norefresh();
	if (!vsystem("mail %s < %s", REGISTRATION_ADDRESS, REGISTRATION_FNAME)) {
	    msgConfirm("Thank you!  Your registration has been sent in successfully.\n");
	    (void)unlink(REGISTRATION_FNAME);
	}
	else {
	    msgConfirm("Argh!  The mail program returned a bad status - there\n"
		       "must be something still not quite configured correctly.\n"
		       "leaving the registration in: %s\n"
		       "When you're connected to the net and ready to send it,\n"
		       "simply type:  mail %s < %s\n", REGISTRATION_ADDRESS, REGISTRATION_FNAME,
		       REGISTRATION_FNAME);
	}
	if (hotspots[ANNOUNCE_LIST].sel) {
	    char *cp;
	    
	    dialog_clear_norefresh();
	    cp = msgGetInput(email, "What email address would you like to subscribe under?\n"
			     "This is a fairly low-traffic mailing list and only generates\n"
			     "around 5 messages a month, so it's also safe to receive at your\n"
			     "standard email address.");
	    if (!cp)
		msgConfirm("OK, I won't subscribe to announce at this time.  To do it manually\n"
			   "yourself, simply send mail to %s.", MAJORDOMO_ADDRESS);
	    else {
		dialog_clear_norefresh();
		if (!vsystem("echo subscribe freebsd-announce %s | mail %s", email, MAJORDOMO_ADDRESS))
		    msgConfirm("Your request to join the announce mailing list has been sent.\n"
			      "you should receive notification back in 24 hours or less, otherwise\n"
			      "something has gone wrong and you should try this again by sending\n"
			      "a message to %s which contains the line:\n\n"
			      "subscribe freebsd-announce %s\n", MAJORDOMO_ADDRESS, email);
		else
		    msgConfirm("Argh!  The mail program returned a bad status - there\n"
			       "must be something still not quite configured correctly.\n"
			       "Please fix this then try again by sending a message to\n"
			       "to %s which contains the line:\n\n"
			       "subscribe freebsd-announce %s\n", MAJORDOMO_ADDRESS, email);
	    }
	}
    }
    else {
	dialog_clear_norefresh();
	msgConfirm("OK, your registration has been left in the file %s\n"
		   "When you're connected to the net and ready to send it,\n"
		   "simply type:  mail %s < %s\n", REGISTRATION_FNAME,
		   REGISTRATION_ADDRESS, REGISTRATION_FNAME);
    }
    restorescr(save);
}

/* Put up a subdialog for the registration options */
static void
subdialog(WINDOW *win)
{
    int i, j, attrs;
    char help_line[80];

    attrs = getattrs(win);
    mvwaddstr(win, hotspots[COMMERCE_MAIL].y, hotspots[COMMERCE_MAIL].x - 1, "[ ] Postal Adverts");
    mvwaddstr(win, hotspots[COMMERCE_EMAIL].y, hotspots[COMMERCE_EMAIL].x - 1, "[ ] Email Adverts");
    mvwaddstr(win, hotspots[ANNOUNCE_LIST].y, hotspots[ANNOUNCE_LIST].x - 1,
	      "[ ] The announce@FreeBSD.ORG mailing list.");
    mvwaddstr(win, hotspots[NEWSLETTER].y, hotspots[NEWSLETTER].x - 1, "[ ] The FreeBSD Newsletter.");
    /* Tack up the initial values */
    for (i = 0; i < sizeof(hotspots) / sizeof(hotspots[0]); i++) {
	wattrset(win, attrs | A_BOLD);
	mvwaddch(win, hotspots[i].y, hotspots[i].x, hotspots[i].sel ? hotspots[i].allowed[hotspots[i].sel - 1] : 'N');
    }
    wattrset(win, attrs);
    wrefresh(win);

    for (i = 0; i < sizeof(hotspots) / sizeof(hotspots[0]);) {
	int ch, len = strlen(hotspots[i].desc);
	char *cp;

	/* Display the help line at the bottom of the screen */
	for (j = 0; j < 79; j++)
	    help_line[j] = (j < len) ? hotspots[i].desc[j] : ' ';
	help_line[j] = '\0';
	use_helpline(help_line);
	display_helpline(win, LINES - 1, COLS - 1);
	wmove(win, hotspots[i].y, hotspots[i].x);
	wrefresh(win);
	switch(ch = toupper(getch())) {
	case KEY_UP:
		if (i)
		    i--;
		continue;

	case KEY_DOWN:
	case '\011':	/* TAB */
	case '\012':	/* ^J */
	case '\014':	/* ^M */
	    /* Treat as a no-change op */
	    ++i;
	    break;

	case 'N':	/* No is generic to all */
	    hotspots[i].sel = 0;
	    wattrset(win, attrs | A_BOLD);
	    mvwaddch(win, hotspots[i].y, hotspots[i].x, 'N');
	    wattrset(win, attrs);
	    wrefresh(win);
	    ++i;
	    break;

	default:
	    cp = index(hotspots[i].allowed, ch);
	    if (cp) {
		hotspots[i].sel = (cp - hotspots[i].allowed) + 1;
		wattrset(win, attrs | A_BOLD);
		mvwaddch(win, hotspots[i].y, hotspots[i].x, *cp);
		wattrset(win, attrs);
		wrefresh(win);
		++i;
	    }
	    else
		beep();
	    break;
	}
    }
}

/* Register a user */
int
registerOpenDialog(void)
{
    WINDOW              *ds_win, *save = savescr();
    ComposeObj          *obj = NULL;
    int                 n = 0, cancel = FALSE;
    int			max, ret = DITEM_SUCCESS;

    dialog_clear_norefresh();
    /* We need a curses window */
    if (!(ds_win = openLayoutDialog(REGISTER_HELPFILE, " FreeBSD Registration Form:  Press F1 for Help / General Info ",
				    REGISTER_DIALOG_X, REGISTER_DIALOG_Y,
				    REGISTER_DIALOG_WIDTH, REGISTER_DIALOG_HEIGHT))) {
	beep();
	msgConfirm("Cannot open registration dialog window!!");
	restorescr(save);
	return DITEM_FAILURE;
    }

    /* Some more initialisation before we go into the main input loop */
    obj = initLayoutDialog(ds_win, layout, REGISTER_DIALOG_X, REGISTER_DIALOG_Y, &max);

reenter:
    cancelbutton = okbutton = 0;
    while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel)) {
	if (n == LAYOUT_ADDRESS)
	    subdialog(ds_win);
    }
    
    if (!cancel && !verifySettings())
	goto reenter;

    /* OK, we've got a valid registration, now push it out */
    if (!cancel)
	handle_registration();

    /* Clear this crap off the screen */
    delwin(ds_win);
    dialog_clear_norefresh();
    use_helpfile(NULL);

    restorescr(save);
    return ret;
}
OpenPOWER on IntegriCloud