Esempio n. 1
0
/**
 * nmt_newt_choice_dialog:
 * @button1: the label for the first button
 * @button2: the label for the second button
 * @message: a printf()-style message format
 * @...: arguments
 *
 * Displays the given message in a dialog box with two buttons with
 * the indicated labels, and waits for the user to click one.
 *
 * Returns: which button was clicked: 0 for @button1 or 1 for @button2
 */
int
nmt_newt_choice_dialog (const char *button1,
                        const char *button2,
                        const char *message,
                        ...)
{
	va_list ap;
	char *msg, *msg_lc, *button1_lc, *button2_lc;
	int choice;

	va_start (ap, message);
	msg = g_strdup_vprintf (message, ap);
	va_end (ap);

	msg_lc = nmt_newt_locale_from_utf8 (msg);
	button1_lc = nmt_newt_locale_from_utf8 (button1);
	button2_lc = nmt_newt_locale_from_utf8 (button2);
	choice = newtWinChoice (NULL, button1_lc, button2_lc, "%s", msg_lc);

	g_free (button1_lc);
	g_free (button2_lc);
	g_free (msg_lc);
	g_free (msg);

	return choice;
}
Esempio n. 2
0
// Let user change GREEN address.
int greenaddressmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	int rc;
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	sprintf(message, _("If you change this IP address, and you are logged in remotely, "
		"your connection to the %s machine will be broken, and you will have to reconnect "
		"on the new IP. This is a risky operation, and should only be attempted if you "
		"have physical access to the machine, should something go wrong."), NAME);
	rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
	
	if (rc == 0 || rc == 1)
	{
		if (changeaddress(kv, "GREEN", 0, ""))
		{
			netaddresschange = 1;
			writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");			
			writehostsfiles();			
		}
	}
	
	freekeyvalues(kv);

	return 0;
}
/* Let user change GREEN address. */
int greenaddressmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	int rc;
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}

	rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
		ctr[TR_WARNING_LONG]);
	
	if (rc == 0 || rc == 1)
	{
		if (changeaddress(kv, "GREEN", 0, ""))
		{
			netaddresschange = 1;
			writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");			
			writehostsfiles();			
		}
	}
	
	freekeyvalues(kv);

	return 0;
}
Esempio n. 4
0
static VALUE rb_ext_Screen_WinChoice(VALUE self, VALUE args)
{
  if (RARRAY_LEN(args) < 4) {
    rb_raise(rb_eArgError, "4 arguments required");
  } else {

    newtWinChoice(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
        StringValuePtr(RARRAY_PTR(args)[2]), StringValuePtr(RARRAY_PTR(args)[3]));
  }

  return Qnil;
}
Esempio n. 5
0
int ask_clear_card_entry(int card)
{
	char message[STRING_SIZE];
	int rc;

	sprintf(message, _("Do you really want to remove the assigned %s interface?"), ucolourcard[card]);
	rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);

	if ( rc = 0 || rc == 1) {
		clear_card_entry(card);
	} else return 1;

	return 0;
}
Esempio n. 6
0
// =======================================================
int CInterfaceNewt::msgBoxYesNo(const char *szTitle, const char *szText, ...)
{
  char szBuf[4096];
  va_list args;
  int nRes;

  va_start(args, szText);
  vsnprintf(szBuf, sizeof(szBuf), szText, args);
  va_end(args);

  if (!getBatchMode())
    {
      nRes = newtWinChoice((char *) szTitle, i18n("Yes"), i18n("No"), szBuf);
      return ((nRes == 1) ? MSGBOX_YES : MSGBOX_NO);
    }
  else
    {
      showDebug(1, "Error: %s\n", szBuf);
      return MSGBOX_NO;
    }
}
Esempio n. 7
0
// =======================================================
int CInterfaceNewt::msgBoxContinueCancel(const char *szTitle, const char *szText, ...)
{
  char szBuf[4096];
  va_list args;
  int nRes;

  va_start(args, szText);
  vsnprintf(szBuf, sizeof(szBuf), szText, args);
  va_end(args);
 
  if (!getBatchMode())
    {
      nRes = newtWinChoice((char *) szTitle, i18n("Continue"), i18n("Cancel"), szBuf);
      return ((nRes == 1) ? MSGBOX_CONTINUE : MSGBOX_CANCEL);
    }
  else
    {
      showDebug(1, "Error: %s\n", szBuf);
      return MSGBOX_CANCEL;
    }
}
/* JKFIXME: Assumes CD is mounted as /mnt/source                      */
static void queryCDMediaCheck(char *dev) {
    int rc;
    char mediasum[33];
    int isostatus;

    /* dont bother to test in automated installs */
    if (FL_KICKSTART(flags) && !FL_MEDIACHECK(flags))
        return;

    /* see what status is */
    isostatus = getISOStatusFromCDROM(dev, mediasum);
    writeISOStatus(isostatus, mediasum);

    /* see if we should check image(s) */
    /* in rescue mode only test if they explicitly asked to */
    if ((!isostatus && !FL_RESCUE(flags)) || FL_MEDIACHECK(flags)) {
        startNewt();
        rc = newtWinChoice(_("CD Found"), _("OK"), _("Skip"), 
             _("To begin testing the CD media before installation press %s.\n\n"
               "Choose %s to skip the media test and start the installation."),
             _("OK"), _("Skip"));

        if (rc != 2) {
            /* unmount CD now we've identified */
            /* a valid disc #1 is present */
            umountStage2();
            umount("/mnt/source");
      
            /* test CD(s) */
            mediaCheckCdrom(dev);
      
            /* remount stage2 from CD #1 and proceed */
            mountCdromStage2(dev);
        }
    }
}
Esempio n. 9
0
/* set to NULL if not needed */
int urlinstStartTransfer(struct iurlinfo * ui, char * filename, 
                         char *extraHeaders) {
    char * buf;
    int fd, port;
    int family = -1;
    char * finalPrefix;
    struct in_addr addr;
    struct in6_addr addr6;
    char *hostname, *portstr;

    if (!strcmp(ui->prefix, "/"))
        finalPrefix = "";
    else
        finalPrefix = ui->prefix;

    buf = alloca(strlen(finalPrefix) + strlen(filename) + 20);
    if (*filename == '/')
        sprintf(buf, "%s%s", finalPrefix, filename);
    else
        sprintf(buf, "%s/%s", finalPrefix, filename);
    
    logMessage(INFO, "transferring %s://%s/%s to a fd",
               ui->protocol == URL_METHOD_FTP ? "ftp" : "http",
               ui->address, buf);

    splitHostname(ui->address, &hostname, &portstr);
    if (portstr == NULL)
        port = -1;
    else
        port = atoi(portstr);

    if (inet_pton(AF_INET, hostname, &addr) >= 1)
        family = AF_INET;
    else if (inet_pton(AF_INET6, hostname, &addr6) >= 1)
        family = AF_INET6;
    else {
        if (mygethostbyname(hostname, &addr, AF_INET) == 0) {
            family = AF_INET;
        } else if (mygethostbyname(hostname, &addr6, AF_INET6) == 0) {
            family = AF_INET6;
        } else {
            logMessage(ERROR, "cannot determine address family of %s",
                       hostname);
        }
    }

    if (ui->protocol == URL_METHOD_FTP) {
        ui->ftpPort = ftpOpen(hostname, family,
                              ui->login ? ui->login : "******", 
                              ui->password ? ui->password : "******", 
                              NULL, port);
        if (ui->ftpPort < 0)
            return -2;

        fd = ftpGetFileDesc(ui->ftpPort, addr6, family, buf);
        if (fd < 0) {
            close(ui->ftpPort);
            return -1;
        }
    } else {
#ifdef	ROCKS
	{
		/*
		 * try harder to start HTTP transfer
		 */
		int	tries = 1;
		int	rc;

		logMessage(INFO, "ROCKS:urlinstStartTransfer:http://%s/%s\n"
			"Headers:%s\n",
			ui->address, filename, extraHeaders);
		fd = -1;

		while ((fd < 0) && (tries < 10)) {
			fd = httpGetFileDesc(ui->address, -1, buf,
				extraHeaders);
			if (fd == FTPERR_FAILED_DATA_CONNECT) {
				/* Server busy, backoff */
				sleep(60);
				tries = 1;
				continue;
			}

			logMessage(INFO,
				"ROCKS:urlinstStartTransfer:attempt (%d)",
				tries);

			sleep(1);

			++tries;
		}

		if (fd < 0) {
			logMessage(ERROR, "ROCKS:urlinstStartTransfer:Failed");
			rc = newtWinChoice(_("GET File Error"), 
				_("Retry"), _("Cancel"), 
				_("Could not get file:\n\nhttp://%s/%s\n\n%s"), 
				ui->address, filename, 
				ftpStrerror(fd, URL_METHOD_HTTP));
			if (rc == 1)
				return urlinstStartTransfer(ui, filename,
					extraHeaders);
			else	
				return -1;
		}
	}
#else
        fd = httpGetFileDesc(hostname, port, buf, extraHeaders);
        if (fd < 0)
            return -1;
#endif /* ROCKS */
    }

    if (!FL_CMDLINE(flags))
        winStatus(70, 3, _("Retrieving"), "%s %s...", _("Retrieving"), 
                  filename);

    return fd;
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
	int choice;
	char *sections[14]; /* need to fill this out AFTER knowing lang */
	int rc;
	struct keyvalue *kv;
	char selectedshortlang[STRING_SIZE] = "en";
	int autook = 0;
	int doreboot = 0;
	struct stat statbuf;
	
	memset(&statbuf, 0, sizeof(struct stat));
			
	/* Log file/terminal stuff. */
	if (argc >= 2)
		logname = argv[1];	
	else
		logname = strdup("/root/setup.log");

	if (!(flog = fopen(logname, "w+")))
	{
		printf("Couldn't open log terminal\n");
		return 1;
	}
	
	/* Engage auto operation (run through 'normal' selections automatically) */
	if (argc >= 3)
	{
		if (strlen(argv[2]) == 12 && strncmp(argv[2], "firstInstall", 12) == 0)
		{
			/* This execution only follows the installer; outgoing rules are cleared */
			automode = 1;
		}
		else if (strlen(argv[2]) == 15 && strncmp(argv[2], "networkingOnly", 15) == 0)
		{
			/* This execution only runs during bootup when the NICs have changed */
			automode = 2;
		}
		else
		{
			/* All other values mean generic auto mode during normal operation */
			automode = 3;
		}
	}
	
	fprintf(flog, "Setup program started.\n");

	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings")))
	{
		printf("Smoothwall is not properly installed.\n");
		return 1;
	}
	findkey(kv, "LANGUAGE", selectedshortlang);
	
	ctr = english_tr; 
	
	newtInit();
	newtCls();

	newtDrawRootText(0, 0, TITLE " -- http://smoothwall.org/");
	newtPushHelpLine(ctr[TR_HELPLINE]);		

	if (automode == 0)
	{
		/* Admin selects each menu item individually */
		sections[0] = ctr[TR_RESTORE_CONFIGURATION];
		sections[1] = ctr[TR_KEYBOARD_MAPPING];
		sections[2] = ctr[TR_TIMEZONE];
		sections[3] = ctr[TR_HOSTNAME];
		sections[4] = ctr[TR_WEB_PROXY];
		sections[5] = ctr[TR_DEFAULT_SECURITY_LEVEL];
		sections[6] = ctr[TR_ISDN_CONFIGURATION];
		sections[7] = ctr[TR_ADSL_CONFIGURATION];
		sections[8] = ctr[TR_NETWORKING];	
		sections[9] = ctr[TR_DHCP_SERVER_CONFIGURATION],
		sections[10] = ctr[TR_ROOT_PASSWORD];
		sections[11] = ctr[TR_SETUP_PASSWORD];
		sections[12] = ctr[TR_ADMIN_PASSWORD];
		sections[13] = NULL;	
	
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
			
		if (usbfail)
			fprintf(flog, "USB HCI not detected.\n");
		else
			fprintf(flog, "USB HCI detected.\n");		
			
		choice = 0;
		for (;;)
		{
			rc = newtWinMenu(ctr[TR_SECTION_MENU],
				ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
				sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
			
			if (rc == 2)
				break;
			
			switch (choice)
			{
				case 0:
					handlerestore();
					break;

				case 1:
					handlekeymap();
					break;
				
				case 2:
					handletimezone();
					break;
				
				case 3:
					handlehostname();
					break;

				case 4:
					handlewebproxy();
					break;
					
				case 5:
					handledefaults();
					break;

				case 6:
					handleisdn();
					break;

				case 7:
					handleadsl();
					break;
				
				case 8:
					handlenetworking();
					break;
					
				case 9:
					handledhcp();
					break;
									
				case 10:
					handlerootpassword();
					break;

				case 11:
					handlesetuppassword();
					break;
					
				case 12:
					handleadminpassword();
					break;
		
				default:
					break;
			}
		}
	}
	else if (automode == 2)
	{
		/* Admin specified networkingOnly as the third arg */
		/* This happens when the NIC change and rc.sysint runs setup */
		handlenetworking();
		autook = 2;
	}
	else
	{
		/* automode is 1 (firstInstall) or 3 (generic) */
		usbfail = 1;
				
		if (newtWinChoice(ctr[TR_RESTORE_CONFIGURATION], ctr[TR_NO], ctr[TR_YES],
			ctr[TR_RESTORE_LONG]) != 1)
		{
			if (!(handlerestore()))
				goto EXIT;
		}
	
		if (!(handlekeymap()))
			goto EXIT;
		if (!(handletimezone()))
			goto EXIT;
		if (!(handlehostname()))
			goto EXIT;
		if (!(handledefaults()))
			goto EXIT;
		if (!(handlenetworking()))
			goto EXIT;

		if (!performedrestore)
		{
			choice = 0;
			
			for (;;)
			{		
				sections[0] = ctr[TR_WEB_PROXY];
				sections[1] = ctr[TR_ISDN_CONFIGURATION];
				sections[2] = ctr[TR_ADSL_CONFIGURATION];
				sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION],
				sections[4] = NULL;	
	
				rc = newtWinMenu(ctr[TR_SECTION_MENU],
					ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
					sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL);
				
				if (rc == 2)
					break;
				
				switch (choice)
				{
					case 0:
						handlewebproxy();
						break;
						
					case 1:
						handleisdn();
						break;
	
					case 2:
						handleadsl();
						break;
											
					case 3:
						handledhcp();
						break;
	
					default:
						break;
				}
			}
		}	

		if (!(handleadminpassword()))
			goto EXIT;
		if (!(handlerootpassword()))
			goto EXIT;
	
		autook = 1;
	}

EXIT:	
	if (automode == 1 || automode == 3)
	{
		if (autook)
			newtWinMessage("", ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
		else
			newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
	}
	else if (automode == 2)
	{
		if (autook == 2)
		{
			fprintf(flog, "Setup program ended.\n");
			fflush(flog);
			fclose(flog);
			newtFinished();
			return 0;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		if (rebootrequired)
		{
			if (newtWinChoice("", ctr[TR_YES], ctr[TR_NO],
				ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2)
			{
				doreboot = 1;
			}
		} 
	}

	fprintf(flog, "Setup program ended.\n");
	fflush(flog);
	fclose(flog);
		
	newtFinished();

 	if (doreboot)
		system("/sbin/shutdown -r now");

	return 0;
}
Esempio n. 11
0
/* Use SSL. Must be entirely different since the return
 * type is a pointer to an SSL structure.
 */
BIO *
urlinstStartSSLTransfer(struct iurlinfo * ui, char * filename, 
                         char *extraHeaders, int silentErrors,
                         int flags, char *nextServer) {

	extern  void watchdog_reset();
	int	tries = 1;
	int	rc;
	int	errorcode = -1;
	int	sleepmin = KS_RETRY_MIN;
	char	*returnedHeaders;
	BIO	*sbio = 0;

	logMessage(INFO, "ROCKS:transferring https://%s/%s\nHeaders:%s\n",
	       ui->address, filename, extraHeaders);

	/* Add 'public' path element if we dont have a cert. */
	if (!haveCertificate())
		addPublic(&filename);

	while ((errorcode < 0) && (tries < 10)) {
		sbio = httpsGetFileDesc(ui->address, -1, filename,
			extraHeaders, &errorcode, &returnedHeaders);

		if (errorcode == 0) {
			char	*ptr;
			char	trackers[256];
			char	pkgservers[256];

			if ((ptr = strstr(returnedHeaders,
					"X-Avalanche-Trackers:")) != NULL) {
				sscanf(ptr, "X-Avalanche-Trackers: %256s",
					trackers);
			} else {
				if (nextServer != NULL) {
					snprintf(trackers, sizeof(trackers) - 1,
						"%s", nextServer);
				} else {
					strcpy(trackers, "127.0.0.1");
				}
			}

			if ((ptr = strstr(returnedHeaders,
					"X-Avalanche-Pkg-Servers:")) != NULL) {
				sscanf(ptr, "X-Avalanche-Pkg-Servers: %256s",
					pkgservers);
			} else {
				if (nextServer != NULL) {
					snprintf(pkgservers,
						sizeof(pkgservers) - 1, "%s",
						nextServer);
				} else {
					strcpy(pkgservers, "127.0.0.1");
				}
			}

			writeAvalancheInfo(trackers, pkgservers);

		} else if (errorcode == FTPERR_FAILED_DATA_CONNECT) {
			/*
			 * read the retry value from the return message
			 */
			char	*ptr;
			int	sleeptime = 0;

			if ((ptr = strstr(returnedHeaders, "Retry-After:"))
					!= NULL) {
				sscanf(ptr, "Retry-After: %d", &sleeptime);
			}

			if (sleeptime <= 0) {
				/*
				 * Backoff a random interval between
				 * KS_RETRY_MIN and KS_RETRY_MAX
				 */
				sleeptime = sleepmin +
					((KS_RETRY_MAX - sleepmin) *
					(rand()/(float)RAND_MAX));
			}

			winStatus(55, 3, _("Server Busy"), _("I will retry "
				"for a ks file after a %d sec sleep..."), 
				sleeptime, 0);

			/*
			 * this must be in a loop, as the alarm associated
			 * with the watchdog timer is sending a signal which
			 * interrupts the sleep().
			 */
			while ((sleeptime = sleep(sleeptime)) != 0) {
				;
			}

			newtPopWindow();

			tries = 1;
			/* Don't let the watchdog fire if the kickstart
			   server is reporting busy */
			watchdog_reset();
			continue;
		} else if (errorcode == FTPERR_REFUSED) {
			/*
			 * always accept the parent credentials
			 */
			forceParentAuth();
			continue;
		}

		logMessage(INFO, "ROCKS:urlinstStartSSLTransfer:attempt (%d)",
			tries);

		sleep(1);

		++tries;
	}

	if (errorcode < 0) {
		logMessage(ERROR, "ROCKS:urlinstStartSSLTransfer:Failed");
		rc = 0;

		/* Go through the public door automatically, but only
		 * if we have not tried it already. */
		if (errorcode == FTPERR_SERVER_SECURITY && !addPublic(&filename)) {
			rc = 1;
		}
		else {
			rc = newtWinChoice(_("GET File Error"), 
				_("Retry"), _("Cancel"), 
				_("Could not get file:\n\nhttps://%s/%s\n\n%s"),
				ui->address, filename, 
				ftpStrerror(errorcode, URL_METHOD_HTTP));
		}
		if (rc==1) 	/* Retry */
			return urlinstStartSSLTransfer(ui, filename,
				extraHeaders, silentErrors, flags, nextServer);
		else	/* Cancel */
			return NULL;
	}

	if (!FL_CMDLINE(flags))
		winStatus(70, 3, _("Retrieving"), "%s %.*s...", 
			_("Retrieving"), 60, filename);

	return sbio;
}
/*
 * Given cd device cddriver, this function will attempt to check its internal
 * checksum.
 *
 * JKFIXME: this ignores "location", which should be fixed */
static char * mediaCheckCdrom(char *cddriver) {
    int rc;
    int first;

    devMakeInode(cddriver, "/tmp/cdrom");

    first = 1;
    do {
        char *descr;
        char *tstamp;
        int ejectcd;

        /* init every pass */
        ejectcd = 0;
        descr = NULL;

        /* if first time through, see if they want to eject the CD      */
        /* currently in the drive (most likely the CD they booted from) */
        /* and test a different disk.  Otherwise just test the disk in  */
        /* the drive since it was inserted in the previous pass through */
        /* this loop, so they want it tested.                           */
        if (first) {
            first = 0;
            rc = newtWinChoice(_("Media Check"), _("Test"), _("Eject CD"),
                               _("Choose \"%s\" to test the CD currently in "
                                 "the drive, or \"%s\" to eject the CD and "
                                 "insert another for testing."), _("Test"),
                               _("Eject CD"));

            if (rc == 2)
                ejectcd = 1;
        }

        if (!ejectcd) {
            /* XXX MSFFIXME: should check return code for error */
            readStampFileFromIso("/tmp/cdrom", &tstamp, &descr);
            mediaCheckFile("/tmp/cdrom", descr);

            if (descr)
                free(descr);
        }

        if (!FL_NOEJECT(flags))
            ejectCdrom();
        else
            logMessage(INFO, "noeject in effect, not ejecting cdrom");

        rc = newtWinChoice(_("Media Check"), _("Test"), _("Continue"),
                       _("If you would like to test additional media, "
                       "insert the next CD and press \"%s\". "
                       "Testing each CD is not strictly required, however "
                       "it is highly recommended.  Minimally, the CDs should "
                       "be tested prior to using them for the first time. "
                       "After they have been successfully tested, it is not "
                       "required to retest each CD prior to using it again."),
                       _("Test"), _("Continue"));

        if (rc == 2) {
            if (!FL_NOEJECT(flags))
                unlink("/tmp/cdrom");
            else
                logMessage(INFO, "noeject in effect, not unmounting /tmp/cdrom");
            return NULL;
        } else {
            continue;
        }
    } while (1);
    
    return NULL;
}
Esempio n. 13
0
// They can change BLUE, ORANGE and GREEN too :)
int addressesmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	struct keyvalue *mainkv = initkeyvalues();
	int rc = 0;
	char *sections[5];
	char *green = "GREEN";
	char *orange = "ORANGE";
	char *blue = "BLUE";
	char *red = "RED";
	int c = 0;
	char greenaddress[STRING_SIZE];
	char oldgreenaddress[STRING_SIZE];
	char temp[STRING_SIZE];
	char temp2[STRING_SIZE];
	char message[1000];
	int configtype;
	int done;
	int choice;
	char hostname[STRING_SIZE];
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);
	
	sections[c] = green;
	c++;
	if (HAS_BLUE)
	{
		sections[c] = blue;
		c++;
	}
	if (HAS_ORANGE)
	{
		sections[c] = orange;
		c++;
	}
	if (HAS_RED)
	{
		sections[c] = red;
		c++;
	}
	sections[c] = NULL;

	choice = 0;	
	done = 0;	
	while (!done)
	{
		rc = newtWinMenu(_("Address settings"),
			_("Select the interface you wish to reconfigure."), 50, 5,
			5, 6, sections, &choice, _("OK"), _("Done"), NULL);	

		if (rc == 0 || rc == 1)
		{
			if (strcmp(sections[choice], "GREEN") == 0)
			{
				findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
				sprintf(message, _("If you change this IP address, and you are logged in remotely, "
					"your connection to the %s machine will be broken, and you will have to reconnect "
					"on the new IP. This is a risky operation, and should only be attempted if you "
					"have physical access to the machine, should something go wrong."), NAME);
				rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
				if (rc == 0 || rc == 1)
				{
					if (changeaddress(kv, "GREEN", 0, ""))
					{
						netaddresschange = 1;
						writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
						writehostsfiles();
						findkey(kv, "GREEN_ADDRESS", greenaddress);
						snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
						snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
						replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
						chown  (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
					}
				}
			}
			if (strcmp(sections[choice], "BLUE") == 0)
			{
				if (changeaddress(kv, "BLUE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "ORANGE") == 0)
			{
				if (changeaddress(kv, "ORANGE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "RED") == 0)
			{
				strcpy(hostname, "");
				findkey(mainkv, "HOSTNAME", hostname);
				if (changeaddress(kv, "RED", 1, hostname))
					netaddresschange = 1;
			}
		}
		else
			done = 1;
	}
	
	writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
	freekeyvalues(kv);
	freekeyvalues(mainkv);
	
	return 0;
}
Esempio n. 14
0
int oktoleave(void)
{
	struct keyvalue *kv = initkeyvalues();
	char temp[STRING_SIZE];
	int configtype;
	int rc;
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}	

	strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
	if (configtype < 1 || configtype > 4) configtype = 1;

	if (HAS_GREEN)
	{
		strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No GREEN interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "GREEN")))
		{
			errorbox(_("Missing an IP address on GREEN."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_RED)
	{

		strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
		if (!(strlen(temp)))
		{
			rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
				_("No RED interface assigned."));
			if (rc == 0 || rc == 1)
			{
				freekeyvalues(kv);
				return 0;
			}
		}
		if (!(interfacecheck(kv, "RED")))
		{
			errorbox(_("Missing an IP address on RED."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_ORANGE)
	{
		strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No ORANGE interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "ORANGE")))
		{
			errorbox(_("Missing an IP address on ORANGE."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_BLUE)
	{
		strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No BLUE interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "BLUE")))
		{
			errorbox(_("Missing an IP address on BLUE."));
			freekeyvalues(kv);
			return 0;
		}
	}
	
	strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
	if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
	{
		strcpy(temp, ""); findkey(kv, "DNS1", temp);
		if (!(strlen(temp)))
		{
                       errorbox(_("Missing DNS."));
			freekeyvalues(kv);
			return 0;
		}
		strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("Missing Default Gateway."));
			freekeyvalues(kv);
			return 0;
		}
	}
	return 1;
}
Esempio n. 15
0
/* Driver menu.  Choose drivers.. */
int drivermenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[STRING_SIZE];
	char temp[STRING_SIZE] = "1";

	int configtype;
	int i, rc, kcount = 0, neednics;

	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	if (findkey(kv, "CONFIG_TYPE", temp))
		configtype = atol(temp);
	else {
		fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
		configtype = atol(temp);
		replacekeyvalue(kv, "CONFIG_TYPE", temp);
		writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
	}

	strcpy(message, _("Configure network drivers, and which interface each card is assigned to. "
		"The current configuration is as follows:\n\n"));

	kcount = 0;
	neednics = 0;
	if (HAS_GREEN) {
		sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_GREEN_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_RED) {
		sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_RED_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_ORANGE) {
		sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
		strcat(message, temp);
		if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_BLUE) {
		sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_BLUE_CARD_].macaddr)) {
			sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}

	for ( i=0 ; i<4; i++)
		if (strcmp(knics[i].macaddr, ""))
			kcount++;

	if (neednics = kcount)
	{
		strcat(message, "\n");
		strcat(message, _("Do you wish to change these settings?"));
		rc = newtWinChoice(_("Drivers and card assignments"), _("OK"),
			_("Cancel"), message);
		if (rc == 0 || rc == 1)
		{
			changedrivers();
		}
	} else {
		changedrivers();
	}
	freekeyvalues(kv);

	return 1;
}
int main(int argc, char *argv[])
{
	int choice;
	char *sections[13]; /* need to fill this out AFTER knowing lang */
	int rc;
	struct keyvalue *kv;
	char selectedshortlang[STRING_SIZE] = "en";
	int autook = 0;
	int doreboot = 0;
	struct stat statbuf;
	
	memset(&statbuf, 0, sizeof(struct stat));
			
	/* Log file/terminal stuff. */
	if (argc >= 2)
		logname = argv[1];	
	else
		logname = strdup("/root/setup.log");

	if (!(flog = fopen(logname, "w+")))
	{
		printf("Couldn't open log terminal\n");
		return 1;
	}
	
	if (argc >= 3)
		automode = 1;
	
	fprintf(flog, "Setup program started.\n");

	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings")))
	{
		printf("SmoothWall is not properly installed.\n");
		return 1;
	}
	findkey(kv, "LANGUAGE", selectedshortlang);
	
	ctr = english_tr; 
	
	newtInit();
	newtCls();

	newtDrawRootText(0, 0, "                SmoothWall Express 3.0 -- http://smoothwall.org/");
	newtPushHelpLine(ctr[TR_HELPLINE]);		

	if (automode == 0)
	{
		sections[0] = ctr[TR_RESTORE_CONFIGURATION];
		sections[1] = ctr[TR_KEYBOARD_MAPPING];
		sections[2] = ctr[TR_HOSTNAME];
		sections[3] = ctr[TR_WEB_PROXY];
		sections[4] = ctr[TR_DEFAULT_SECURITY_LEVEL];
		sections[5] = ctr[TR_ISDN_CONFIGURATION];
		sections[6] = ctr[TR_ADSL_CONFIGURATION];
		sections[7] = ctr[TR_NETWORKING];	
		sections[8] = ctr[TR_DHCP_SERVER_CONFIGURATION],
		sections[9] = ctr[TR_ROOT_PASSWORD];
		sections[10] = ctr[TR_SETUP_PASSWORD];
		sections[11] = ctr[TR_ADMIN_PASSWORD];
		sections[12] = NULL;	
	
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
			
		if (usbfail)
			fprintf(flog, "USB HCI not detected.\n");
		else
			fprintf(flog, "USB HCI detected.\n");		
			
		choice = 0;
		for (;;)
		{
			rc = newtWinMenu(ctr[TR_SECTION_MENU],
				ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
				sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
			
			if (rc == 2)
				break;
			
			switch (choice)
			{
				case 0:
					handlerestore();
					break;

				case 1:
					handlekeymap();
					break;
				
				case 2:
					handlehostname();
					break;

				case 3:
					handlewebproxy();
					break;
					
				case 4:
					handledefaults();
					break;

				case 5:
					handleisdn();
					break;

				case 6:
					handleadsl();
					break;
				
				case 7:
					handlenetworking();
					break;
					
				case 8:
					handledhcp();
					break;
									
				case 9:
					handlerootpassword();
					break;

				case 10:
					handlesetuppassword();
					break;
					
				case 11:
					handleadminpassword();
					break;
		
				default:
					break;
			}
		}
	}
	else
	{
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
				
		if (newtWinChoice(TITLE, ctr[TR_NO], ctr[TR_YES],
			ctr[TR_RESTORE_LONG]) != 1)
		{
			if (!(handlerestore()))
				goto EXIT;
		}
	
		if (!(handlekeymap()))
			goto EXIT;
		if (!(handlehostname()))
			goto EXIT;
		if (!(handledefaults()))
			goto EXIT;
		if (!(handlenetworking()))
			goto EXIT;

		if (!performedrestore)
		{
			choice = 0;
			
			for (;;)
			{		
				sections[0] = ctr[TR_WEB_PROXY];
				sections[1] = ctr[TR_ISDN_CONFIGURATION];
				sections[2] = ctr[TR_ADSL_CONFIGURATION];
				sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION],
				sections[4] = NULL;	
	
				rc = newtWinMenu(ctr[TR_SECTION_MENU],
					ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
					sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL);
				
				if (rc == 2)
					break;
				
				switch (choice)
				{
					case 0:
						handlewebproxy();
						break;
						
					case 1:
						handleisdn();
						break;
	
					case 2:
						handleadsl();
						break;
											
					case 3:
						handledhcp();
						break;
	
					default:
						break;
				}
			}
		}	

		if (!(handleadminpassword()))
			goto EXIT;
		if (!(handlerootpassword()))
			goto EXIT;
	
		autook = 1;
	}

EXIT:	
	if (automode != 0)
	{
		if (autook)
			newtWinMessage(TITLE, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
		else
			newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
	}
	else
	{
		if (rebootrequired)
		{
			if (newtWinChoice(TITLE, ctr[TR_YES], ctr[TR_NO],
				ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2)
			{
				doreboot = 1;
			}
		} 
	}

	fprintf(flog, "Setup program ended.\n");
	fflush(flog);
	fclose(flog);
		
	newtFinished();

 	if (doreboot)
		system("/sbin/shutdown -r now");

	return 0;
}
Esempio n. 17
0
/* setup hard drive based install from a partition with a filesystem and
 * ISO images on that filesystem
 */
char * mountHardDrive(struct installMethod * method,
		      char * location, struct loaderData_s * loaderData) {
    int rc;
    int i;

    newtComponent listbox, label, dirEntry, form, okay, back, text;
    struct newtExitStruct es;
    newtGrid entryGrid, grid, buttons;

    int done = 0;
    char * dir = strdup("");
    char * tmpDir;
    char * url = NULL;
    char * buf, *substr;
    int numPartitions;

    char **partition_list;
    char *selpart;
    char *kspartition = NULL, *ksdirectory = NULL;

    /* handle kickstart/stage2= data first if available */
    if (loaderData->method == METHOD_HD && loaderData->stage2Data) {
        kspartition = ((struct hdInstallData *)loaderData->stage2Data)->partition;
        ksdirectory = ((struct hdInstallData *)loaderData->stage2Data)->directory;
        logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory);

        /* if exist, duplicate */
        if (kspartition)
            kspartition = strdup(kspartition);
        if (ksdirectory) {
            ksdirectory = strdup(ksdirectory);
        } else {
            ksdirectory = strdup("/images/install.img");
        }

        if (!kspartition || !ksdirectory) {
            logMessage(ERROR, "missing partition or directory specification");
            loaderData->method = -1;

            if (loaderData->inferredStage2)
                loaderData->invalidRepoParam = 1;
        } else {
            /* if we start with /dev, strip it (#121486) */
            char *kspart = kspartition;
            if (!strncmp(kspart, "/dev/", 5))
                kspart = kspart + 5;

            url = setupIsoImages(kspart, ksdirectory, location);
            if (!url) {
                logMessage(ERROR, "unable to find %s installation images on hd",
                           getProductName());
                loaderData->method = -1;

                if (loaderData->inferredStage2)
                    loaderData->invalidRepoParam = 1;
            } else {
                free(kspartition);
                free(ksdirectory);
                return url;
            }
        }
    } else {
        kspartition = NULL;
        ksdirectory = NULL;
    }

    /* if we're here its either because this is interactive, or the */
    /* hd kickstart directive was faulty and we have to prompt for  */
    /* location of harddrive image                                  */

    partition_list = NULL;
    while (!done) {
        /* if we're doing another pass free this up first */
        if (partition_list)
            freePartitionsList(partition_list);

        partition_list = getPartitionsList(NULL);
        numPartitions = lenPartitionsList(partition_list);

        /* no partitions found, try to load a device driver disk for storage */
        if (!numPartitions) {
            rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"),
                               _("You don't seem to have any hard drives on "
                                 "your system! Would you like to configure "
                                 "additional devices?"));
            if (rc == 2) {
                loaderData->stage2Data = NULL;
                return NULL;
            }

            rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0);
            continue;
        }

        /* now find out which partition has the stage2 image */
        checked_asprintf(&buf, _("What partition and directory on that "
                                 "partition holds the installation image "
                                 "for %s?  If you don't see the disk drive "
                                 "you're using listed here, press F2 to "
                                 "configure additional devices."),
                         getProductName());

        text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0);
        free(buf);

        listbox = newtListbox(-1, -1, numPartitions > 5 ? 5 : numPartitions,
                              NEWT_FLAG_RETURNEXIT | 
                              (numPartitions > 5 ? NEWT_FLAG_SCROLL : 0));

        for (i = 0; i < numPartitions; i++)
            newtListboxAppendEntry(listbox,partition_list[i],partition_list[i]);

        /* if we had ks data around use it to prime entry, then get rid of it*/
        if (kspartition) {
            newtListboxSetCurrentByKey(listbox, kspartition);
            free(kspartition);
            kspartition = NULL;
        }

        label = newtLabel(-1, -1, _("Directory holding image:"));

        dirEntry = newtEntry(28, 11, dir, 28, (const char **) &tmpDir,
                             NEWT_ENTRY_SCROLL);

        /* if we had ks data around use it to prime entry, then get rid of it*/
        if (ksdirectory) {
            newtEntrySet(dirEntry, ksdirectory, 1);
            free(ksdirectory);
            ksdirectory = NULL;
        }

        entryGrid = newtGridHStacked(NEWT_GRID_COMPONENT, label,
                                     NEWT_GRID_COMPONENT, dirEntry,
                                     NEWT_GRID_EMPTY);

        buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL);

        grid = newtCreateGrid(1, 4);
        newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, entryGrid,
                         0, 0, 0, 1, 0, 0);
        newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
                         0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

        newtGridWrappedWindow(grid, _("Select Partition"));

        form = newtForm(NULL, NULL, 0);
        newtFormAddHotKey(form, NEWT_KEY_F2);
        newtFormAddHotKey(form, NEWT_KEY_F12);

        newtGridAddComponentsToForm(grid, form, 1);
        newtGridFree(grid, 1);

        newtFormRun(form, &es);

        selpart = newtListboxGetCurrent(listbox);

        free(dir);
        if (tmpDir && *tmpDir) {
            /* Protect from form free. */
            dir = strdup(tmpDir);
        } else  {
            dir = strdup("");
        }

        newtFormDestroy(form);
        newtPopWindow();

        if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) {
            loaderData->stage2Data = NULL;
            return NULL;
        } else if (es.reason == NEWT_EXIT_HOTKEY && es.u.key == NEWT_KEY_F2) {
            rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0);
            continue;
        }

        logMessage(INFO, "partition %s selected", selpart);

        /* If the user-provided URL points at a repo instead of a stage2
         * image, fix that up now.
         */
        substr = strstr(dir, ".img");
        if (!substr || (substr && *(substr+4) != '\0')) {
            checked_asprintf(&dir, "%s/images/install.img", dir);
        }

        loaderData->invalidRepoParam = 1;

        url = setupIsoImages(selpart, dir, location);
        if (!url) {
            newtWinMessage(_("Error"), _("OK"), 
                           _("Device %s does not appear to contain "
                             "an installation image."), selpart, getProductName());
            continue;
        }

        done = 1; 
    }

    free(dir);

    return url;
}
/* They can change ORANGE and GREEN too :) */
int addressesmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	struct keyvalue *mainkv = initkeyvalues();
	int rc = 0;
	char *sections[6];
	char *green = "GREEN";
	char *orange = "ORANGE";
	char *purple = "PURPLE";
	char *red = "RED";
	int c = 0;
	char temp[STRING_SIZE];
	int configtype;
	int done;
	int choice;
	char hostname[STRING_SIZE];
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "main/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);
	
	sections[c] = green;
	c++;
	if (CONFIG_TYPE_ORANGE(configtype))
	{
		sections[c] = orange;
		c++;
	}
	if (CONFIG_TYPE_PURPLE(configtype))
	{
		sections[c] = purple;
		c++;
	}
	if (CONFIG_TYPE_RED(configtype))
	{
		sections[c] = red;
		c++;
	}
	sections[c] = NULL;

	choice = 0;	
	done = 0;	
	while (!done)
	{
		rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
			ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
			5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);	

		if (rc == 0 || rc == 1)
		{
			if (strcmp(sections[choice], "GREEN") == 0)
			{
				rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
					ctr[TR_WARNING_LONG]);
				if (rc == 0 || rc == 1)
				{
					if (changeaddress(kv, "GREEN", 0, ""))
					{
						netaddresschange = 1;
						writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");			
						writehostsfiles();			
					}
				}
			}
			if (strcmp(sections[choice], "ORANGE") == 0)
			{
				if (changeaddress(kv, "ORANGE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "PURPLE") == 0)
			{
				if (changeaddress(kv, "PURPLE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "RED") == 0)
			{
				strcpy(hostname, "");
				findkey(mainkv, "HOSTNAME", hostname);
				if (changeaddress(kv, "RED", 1, hostname))
					netaddresschange = 1;
			}
		}
		else
			done = 1;
	}
	
	writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");
	freekeyvalues(kv);
	freekeyvalues(mainkv);
	
	return 0;
}
/* set up a cdrom, nominally for installation 
 *
 * location: where to mount the cdrom at JKFIXME: ignored
 * interactive: whether or not to prompt about questions/errors (1 is yes)
 *
 * loaderData is the kickstart info, can be NULL meaning no info
 *
 * requirepkgs=1 means CD should have packages, otherwise we just find stage2
 *
 * side effect: found cdrom is mounted as /mnt/source.  stage2 mounted
 * as /mnt/runtime.
 */
char * setupCdrom(char * location, struct loaderData_s * loaderData,
                  moduleInfoSet modInfo, moduleList modLoaded, 
                  moduleDeps modDeps, int interactive, int requirepkgs) {
    int i, r, rc;
    int foundinvalid = 0;
    int stage2inram = 0;
    char * buf;
    char *stage2img;
    struct device ** devices;

    devices = probeDevices(CLASS_CDROM, BUS_UNSPEC, 0);
    if (!devices) {
        logMessage(ERROR, "got to setupCdrom without a CD device");
        return NULL;
    }

    /* JKFIXME: ASSERT -- we have a cdrom device when we get here */
    do {
        for (i = 0; devices[i]; i++) {
            if (!devices[i]->device)
                continue;

            logMessage(INFO,"trying to mount CD device %s", devices[i]->device);

            if (devMakeInode(devices[i]->device, "/tmp/cdrom") != 0) {
                logMessage(ERROR, "unable to create device node for %s",
                           devices[i]->device);
                continue;
            }

            if (!doPwMount("/tmp/cdrom", "/mnt/source", "iso9660", 
                           IMOUNT_RDONLY, NULL)) {
                if (!access("/mnt/source/images/stage2.img", R_OK) &&
                    (!requirepkgs || !access("/mnt/source/.discinfo", R_OK))) {

                    /* if in rescue mode lets copy stage 2 into RAM so we can */
                    /* free up the CD drive and user can have it avaiable to  */
                    /* aid system recovery.                                   */
                    if (FL_RESCUE(flags) && !FL_TEXT(flags) &&
                        totalMemory() > 128000) {
                        rc = copyFile("/mnt/source/images/stage2.img", 
                                      "/tmp/ramfs/stage2.img");
                        stage2img = "/tmp/ramfs/stage2.img";
                        stage2inram = 1;
                    } else {
                        stage2img = strdup("/mnt/source/images/stage2.img");
                        stage2inram = 0;
                    }
	
                    rc = mountStage2(stage2img);

                    /* if we failed, umount /mnt/source and keep going */
                    if (rc) {
                        logMessage(INFO, "mounting stage2 failed");

                        umount("/mnt/source");
                        if (rc == -1)
                            foundinvalid = 1;
                        continue;
                    }

                    /* do the media check */
                    queryCDMediaCheck(devices[i]->device);

                    /* if in rescue mode and we copied stage2 to RAM */
                    /* we can now unmount the CD                     */
                    if (FL_RESCUE(flags) && stage2inram) {
                        umount("/mnt/source");
                        unlink("/tmp/cdrom");
                    }

                    r = asprintf(&buf, "cdrom://%s:/mnt/source",
                                 devices[i]->device);
                    if (r == -1)
                        return NULL;
                    else
                        return buf;

                }

                /* this wasnt the CD we were looking for, clean up and */
                /* try the next CD drive                               */
                umount("/mnt/source");
            }
        }

        if (interactive) {
            char * buf;
            if (foundinvalid)
                buf = sdupprintf(_("No %s CD was found which matches your "
                                   "boot media.  Please insert the %s CD "
                                   "and press %s to retry."), getProductName(),
                                 getProductName(), _("OK"));
            else
                buf = sdupprintf(_("The %s CD was not found in any of your "
                                   "CDROM drives. Please insert the %s CD "
                                   "and press %s to retry."), getProductName(),
                                 getProductName(), _("OK"));

            if (!FL_NOEJECT(flags)) {
                ejectCdrom();
                unlink("/tmp/cdrom");
            } else {
                logMessage(INFO, "noeject in effect, not ejecting cdrom");
            }
            rc = newtWinChoice(_("CD Not Found"),
                               _("OK"), _("Back"), buf, _("OK"));
            free(buf);
            if (rc == 2)
                return NULL;
        } else {
            /* we can't ask them about it, so just return not found */
            return NULL;
        }
    } while (1);

    return NULL;
}
/* Driver menu.  Choose drivers.. */
int drivermenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	char temp[STRING_SIZE], temp1[STRING_SIZE];
	char driver[STRING_SIZE], dev[STRING_SIZE];
	int configtype;
	int rc;

	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);

	strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
	
	/* This horrible bit formats the heading :( */
	strcpy(driver, "");
	findkey(kv, "GREEN_DISPLAYDRIVER", driver);
	findnicdescription(driver, temp);
	strcpy(dev, ctr[TR_UNSET]);
	findkey(kv, "GREEN_DEV", dev);
	displaynicinfowithmac(temp1, sizeof(temp1), "GREEN", dev, temp);
	strcat(message, temp1);

	if (CONFIG_TYPE_ORANGE(configtype))
	{
		strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "ORANGE", dev, temp);
		strcat(message, temp1);
	}
	if (CONFIG_TYPE_PURPLE(configtype))
	{
		strcpy(driver, "");
		findkey(kv, "PURPLE_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]);
		findkey(kv, "PURPLE_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "PURPLE", dev, temp);
		strcat(message, temp1);
	}
	if (CONFIG_TYPE_RED(configtype))
	{
		strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "RED", dev, temp);
		strcat(message, temp1);
	}
	strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
	rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
		ctr[TR_CANCEL], message);
	if (rc == 0 || rc == 1)
	{
		/* Shit, got to do something.. */
		changedrivers();
	}
	
	freekeyvalues(kv);

	return 1;
}
int main(void) {
    newtComponent b1, b2, b3, b4;
    newtComponent answer, f, t;
    newtGrid grid, subgrid;
    char * flowedText;
    int textWidth, textHeight, rc;
    char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
    char * entries[10];
    struct newtWinEntry autoEntries[] = {
	{ "An entry", entries + 0, 0 },
	{ "Another entry", entries + 1, 0 },
	{ "Third entry", entries + 2, 0 },
	{ "Fourth entry", entries + 3, 0 },
	{ NULL, NULL, 0 } };

    memset(entries, 0, sizeof(entries));

    newtInit();
    newtCls();

    b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
    b2 = newtButton(-1, -1, "Another Button");
    b3 = newtButton(-1, -1, "But, but");
    b4 = newtButton(-1, -1, "But what?");

    f = newtForm(NULL, NULL, 0);

    grid = newtCreateGrid(2, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 
			NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);


    newtFormAddComponents(f, b1, b2, b3, b4, NULL);

    newtGridWrappedWindow(grid, "first window");
    newtGridFree(grid, 1);

    answer = newtRunForm(f);
	
    newtFormDestroy(f);
    newtPopWindow();

    flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
			  	"columns long, so some wrapping should be "
			  	"done. Did you know that the quick, brown "
			  	"fox jumped over the lazy dog?\n\n"
				"In other news, it's pretty important that we "
				"can properly force a line break.",
				40, 5, 5, &textWidth, &textHeight);
    t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, flowedText);
    free(flowedText);

    
    b1 = newtButton(-1, -1, "Okay");
    b2 = newtButton(-1, -1, "Cancel");

    grid = newtCreateGrid(1, 2);
    subgrid = newtCreateGrid(2, 1);

    newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
    newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);

    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
			NEWT_GRID_FLAG_GROWX);
    newtGridWrappedWindow(grid, "another example");
    newtGridDestroy(grid, 1);

    f = newtForm(NULL, NULL, 0);
    newtFormAddComponents(f, b1, t, b2, NULL);
    answer = newtRunForm(f);

    newtPopWindow();
    newtFormDestroy(f);

    newtWinMessage("Simple", "Ok", "This is a simple message window");
    newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");

    textWidth = 0;
    rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
		     "newtWinMenu() call. It may or may not have a scrollbar, "
		     "depending on the need for one.", 50, 5, 5, 3, 
		     menuContents, &textWidth, "Ok", "Cancel", NULL);

    rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
		     "newtWinEntries() call. It lets you get a lot of input "
		     "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", 
		     "Cancel", NULL);

    newtFinished();

    printf("rc = 0x%x item = %d\n", rc, textWidth);

    return 0;
}
Esempio n. 22
0
bool ui__dialog_yesno(const char *msg)
{
	/* newtWinChoice should really be accepting const char pointers... */
	return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;
}