Exemple #1
0
int main(int argc,char *argv[])
{
   int c;

   while ((c = getopt(argc, argv, "i:")) != EOF)
   {
      switch(c)
      {
         case 'i':
            interval_s = atof(optarg);
            break;
         default:
            usage(argv[0]);
            exit(1);
         }
   }

   if ((optind + 1) > argc)
   {
      usage(argv[0]);
      exit(1);
   }

   newtInit();

   for (c = optind; c < argc; c++)
   {
      play_wav_file(argv[c]);
   }

   newtFinished();         

   return(0);
}
Exemple #2
0
/*
 * Screen_Finished
 *
 */
static VALUE
rb_ext_Screen_Finished()
{
    newtFinished();

    return Qnil;
}
int main(int argc, char *argv[])
{
	if (argc < 2) {
		fprintf(stderr, "Usage: astman <host>\n");
		exit(1);
	}
	newtInit();
	newtCls();
	newtDrawRootText(0, 0, "Asterisk Manager (C)2002, Linux Support Services, Inc.");
	newtPushHelpLine("Welcome to the Asterisk Manager!");
	if (login(argv[1])) {
		newtFinished();
		exit(1);
	}
	manage_calls(argv[1]);
	newtFinished();
	return 0;
}
Exemple #4
0
Fichier : newt.c Projet : knaka/src
int
main (
  int argc,
  char * * argv ) {
    newtInit();
    foo("Message");
    newtFinished();
    return (0);
}
int main(int argc, char ** argv) {
    char * foo;

    newtInit();
    newtCls();

    foo = newt_select_file("Get File Name", "foo, blah blah blah",
                           "/etc", NULL);
    newtFinished();
    printf("got %s\n", foo);
    return 0;
}
Exemple #6
0
int
main(int argn, char **argv)
{
	printf("\033[H\033[2J\033[m");
	printf("使用cterm的请键入'c', 其它终端回车即可");
	fflush(stdout);
	if ('c' == getchar())
		setenv("TERM", "ansi", 1);
	else
		setenv("TERM", "vt100", 1);
	newtInit();
	newtCls();
	newtDrawRootText(0, 0, "科技辞典 1.0");
	do_dict();
	newtFinished();
	return 0;
}
Exemple #7
0
int main(int argc, char *argv[])
{

	ctl = open("/dev/dahdi/ctl", O_RDWR);
	if (ctl < 0) {
		fprintf(stderr, "Unable to open /dev/dahdi/ctl: %s\n", strerror(errno));
		exit(1);
	}
	newtInit();
	newtCls();
	
	newtDrawRootText(0,0,"DAHDI Tool (C)2002-2008 Digium, Inc.");
	newtPushHelpLine("Welcome to the DAHDI Tool!");
	show_spans();
	cleanup();
	newtFinished();
	return 0;
}
int main(int argc, char *argv[])
{

	ctl = open("/dev/zap/ctl", O_RDWR);
	if (ctl < 0) {
		fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
		exit(1);
	}
	newtInit();
	newtCls();
	
	newtDrawRootText(0,0,"Zaptel Tool (C)2002 Linux Support Services, Inc.");
	newtPushHelpLine("Welcome to the Zaptel Tool!");
	show_spans();
	cleanup();
	newtFinished();
	return 0;
}
/**
 * Exit Mondo normally.
 * @param signal The exit code (0 indicates a successful backup; 1 for Mondo means the
 * user aborted; 254 means a fatal error occured).
 * @note This function never returns.
 */
	void
	 finish(int signal) {
		char *command = NULL;

		/*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */

		/* newtPopHelpLine(); */

		register_pid(0, "mondo");
		chdir("/");
		run_program_and_log_output("umount " MNT_CDROM, FALSE);
		run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*",
								   FALSE);
		if (g_erase_tmpdir_and_scratchdir) {
			run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
		}
		if (g_selfmounted_isodir) {
			asprintf(&command, "umount %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 1);
			asprintf(&command, "rmdir %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 1);
		}
//  iamhere("foo");
		/* system("clear"); */
//  iamhere("About to call newtFinished");
		if (!g_text_mode) {
			if (does_file_exist("/THIS-IS-A-RAMDISK")) {
				log_msg(1, "Calling newtFinished()");
				newtFinished();
			} else {
				log_msg(1, "Calling newtSuspend()");
				newtSuspend();
			}
		}
//  system("clear");
//  iamhere("Finished calling newtFinished");
		printf(_("Execution run ended; result=%d\n"), signal);
		printf(_("Type 'less %s' to see the output log\n"), MONDO_LOGFILE);
		free_libmondo_global_strings();
		exit(signal);
	}
Exemple #10
0
void finish_frontend_newt(void)
{
	newtFinished();
}
/**
 * Exit Mondo with a fatal error.
 * @param error_string The error message to present to the user before exiting.
 * @note This function never returns.
 */
	void
	 fatal_error(char *error_string) {
		/*@ buffers ***************************************************** */
		char *fatalstr;
		char *tmp;
		char *command;
		static bool already_exiting = FALSE;
		int i;

		/*@ end vars **************************************************** */

		asprintf(&fatalstr, "-------FATAL ERROR---------");
		set_signals(FALSE);		// link to external func
		g_exiting = TRUE;
		log_msg(1, "%s - '%s'", fatalstr, error_string);
		printf("%s - %s\n", fatalstr, error_string);
		if (getpid() == g_mastermind_pid) {
			log_msg(2, "mastermind %d is exiting", (int) getpid());
			kill(g_main_pid, SIGTERM);
			finish(1);
		}

		if (getpid() != g_main_pid) {
			if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) {
				log_msg(2, "non-m/m %d is exiting", (int) getpid());
				kill(g_main_pid, SIGTERM);
				finish(1);
			}
		}

		log_msg(3, "OK, I think I'm the main PID.");
		if (already_exiting) {
			log_msg(3, "...I'm already exiting. Give me time, Julian!");
			finish(1);
		}

		already_exiting = TRUE;
		log_msg(2, "I'm going to do some cleaning up now.");
		paranoid_system("killall mindi 2> /dev/null");
		kill_anything_like_this("/mondo/do-not");
		kill_anything_like_this("mondo.tmp");
		kill_anything_like_this("ntfsclone");
		sync();
		asprintf(&tmp, "umount %s", g_tmpfs_mountpt);
		chdir("/");
		for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
			log_msg(2, "Waiting for child processes to terminate");
			sleep(1);
			run_program_and_log_output(tmp, 5);
		}
		paranoid_free(tmp);

		if (g_erase_tmpdir_and_scratchdir) {
			run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5);
		}

		if (g_selfmounted_isodir) {
			asprintf(&command, "umount %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 5);
			asprintf(&command, "rmdir %s", g_selfmounted_isodir);
			run_program_and_log_output(command, 5);
		}

		if (!g_text_mode) {
			log_msg(0, fatalstr);
			log_msg(0, error_string);
			//      popup_and_OK (error_string);
			newtFinished();
		}

		system
			("gzip -9c "MONDO_LOGFILE" > /tmp/MA.log.gz 2> /dev/null");
		printf
				(_("If you require technical support, please contact the mailing list.\n"));
		printf(_("See http://www.mondorescue.org for details.\n"));
		printf
				(_("The list's members can help you, if you attach that file to your e-mail.\n"));
		printf(_("Log file: %s\n"), MONDO_LOGFILE);
		if (does_file_exist("/tmp/MA.log.gz")) {
			printf
				(_("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n"));
		}
		printf(_("Mondo has aborted.\n"));
		register_pid(0, "mondo");	// finish() does this too, FYI
		if (!g_main_pid) {
			log_msg(3, "FYI - g_main_pid is blank");
		}
		finish(254);
	}
Exemple #12
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;
}
Exemple #13
0
// =======================================================
CInterfaceNewt::~CInterfaceNewt()
{
  newtFinished();
}
int main(void) {
    newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
    newtComponent lb, t, rsf, answer, timeLabel;
    newtComponent cs[10];
    newtComponent f, chklist, e1;
    struct callbackInfo cbis[3];
    char results[10];
    char * enr2, * enr3, * scaleVal;
    void ** selectedList;
    int i, numsel;
    char buf[20];
    const char * spinner = "-\\|/\\|/";
    const char * spinState;
    struct newtExitStruct es;

    newtInit();
    newtCls();

    newtSetSuspendCallback(suspend, NULL);
    newtSetHelpCallback(helpCallback);

    newtDrawRootText(0, 0, "Newt test program");
    newtPushHelpLine(NULL);
    newtDrawRootText(-50, 0, "More root text");

    newtOpenWindow(2, 2, 30, 10, "first window");
    newtOpenWindow(10, 5, 65, 16, "window 2");

    f = newtForm(NULL, "This is some help text", 0);
    chklist = newtForm(NULL, NULL, 0);

    b1 = newtButton(3, 1, "Exit");
    b2 = newtButton(18, 1, "Update");
    r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);
    r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);
    r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);
    rsf = newtForm(NULL, NULL, 0);
    newtFormAddComponents(rsf, r1, r2, r3, NULL);
    newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);

    for (i = 0; i < 10; i++) {
	sprintf(buf, "Check %d", i);
	cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
	newtFormAddComponent(chklist, cs[i]);
    }

    l1 = newtLabel(3, 6, "Scale:");
    l2 = newtLabel(3, 7, "Scrolls:");
    l3 = newtLabel(3, 8, "Hidden:");
    e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
/*    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);

    cbis[0].state = &results[0];
    cbis[0].en = e1;
    newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);

    scale = newtScale(3, 14, 32, 100);

    newtFormSetHeight(chklist, 3);

    newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
    newtFormAddComponents(f, rsf, scale, NULL);

    lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
				NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
    newtListboxAppendEntry(lb, "First", (void *) 1);
    newtListboxAppendEntry(lb, "Second", (void *) 2);
    newtListboxAppendEntry(lb, "Third", (void *) 3);
    newtListboxAppendEntry(lb, "Fourth", (void *) 4);
    newtListboxAppendEntry(lb, "Sixth", (void *) 6);
    newtListboxAppendEntry(lb, "Seventh", (void *) 7);
    newtListboxAppendEntry(lb, "Eighth", (void *) 8);
    newtListboxAppendEntry(lb, "Ninth", (void *) 9);
    newtListboxAppendEntry(lb, "Tenth", (void *) 10);

    newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
    newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
    newtListboxDeleteEntry(lb, (void *) 11);

    spinState = spinner;
    timeLabel = newtLabel(45, 8, "Spinner: -");

    t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");

    newtFormAddComponents(f, lb, timeLabel, t, NULL);
    newtRefresh();
    newtFormSetTimer(f, 200);

    do {
	newtFormRun(f, &es);

	if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
	    newtScaleSet(scale, atoi(scaleVal));
	    newtRefresh();
	    answer = NULL;
	} else if (es.reason == NEWT_EXIT_TIMER) {
	    spinState++;
	    if (!*spinState) spinState = spinner;
	    sprintf(buf, "Spinner: %c", *spinState);
	    newtLabelSetText(timeLabel, buf);
	}
    } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);

    scaleVal = strdup(scaleVal);
    enr2 = strdup(enr2);
    enr3 = strdup(enr3);

    selectedList = newtListboxGetSelection(lb, &numsel);

    newtFormDestroy(f);

    newtPopWindow();
    newtPopWindow();
    newtFinished();

    printf("got string 1: %s\n", scaleVal);
    printf("got string 2: %s\n", enr2);
    printf("got string 3: %s\n", enr3);

    if(selectedList) {
	printf("\nSelected listbox items:\n");
	for(i = 0; i < numsel; i++)
	    puts(selectedList[i]);
    }

    return 0;
}
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;
}
/**
 * nmt_newt_finished:
 *
 * Wrapper for newtFinished(). Should be called at the end of the program.
 */
void
nmt_newt_finished (void)
{
	newtFinished ();
	g_log_set_default_handler (g_log_default_handler, NULL);
}
Exemple #17
0
static int wtFinish(ClientData clientData, Tcl_Interp * interp, int argc,
                  char ** argv) {
    newtFinished();

    return TCL_OK;
}
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;
}
int main(void){
	newtComponent hForm, button1, button2;
	newtComponent astIpLabel, astPortLabel, astUserLabel, astPassLabel;
	newtComponent astIpEntry, astPortEntry, astUserEntry, astPassEntry;
	const char *astIpVal, *astPortVal, *astUserVal, *astPassVal;

	newtComponent humbugHostLabel, humbugPortLabel, humbugApiLabel;
	newtComponent humbugHostEntry, humbugPortEntry, humbugApiEntry;
	const char *humbugHostVal, *humbugPortVal, *humbugApiVal;

	int i, y;

	newtComponent eventsLabel, eventsChk[EVENTS_SIZE], chkList;
	newtComponent encChk, encLabel, encEntry, chkLog;
	char encVal, logVal;
	const char *encKey;
	char eventsList[EVENTS_SIZE][16];
	char eventsResults[EVENTS_SIZE];
	strcpy(eventsList[0], "CDR");
	strcpy(eventsList[1], "NewExten");
	strcpy(eventsList[2], "Reload");
	strcpy(eventsList[3], "Shutdown");
	strcpy(eventsList[4], "Alarm");
	strcpy(eventsList[5], "AlarmClear");
	strcpy(eventsList[6], "CollectorAlarm");

	struct newtExitStruct es;

	params = (parameters*) calloc(1, sizeof(parameters));

	if(readHumbugConfig() < 0) {
		exit(EXIT_FAILURE);
	}

	newtInit();
	newtCls();

	newtDrawRootText(1, 0, "Text Mode Setup for humbug-collector  (c) 2011 Humbug Telecom Labs, Ltd.");
	newtPushHelpLine(" <Tab>/<Alt-Tab> between elements | <ESC> exits without save | <F12> for help");

	newtCenteredWindow(66, 17, "Humbug Setup");

	astIpLabel   = newtLabel(1, 1, "      Manager IP:");
	astIpEntry   = newtEntry(19, 1, params->astIpVal, 20, &astIpVal, 0);
	astPortLabel = newtLabel(1, 2, "    Manager Port:");
	astPortEntry = newtEntry(19, 2, params->astPortVal, 20, &astPortVal, 0);
	astUserLabel = newtLabel(1, 3, "Manager Username:"******"Manager Password:"******"     Humbug Host:");
	humbugHostEntry = newtEntry(19, 6, params->humbugHost, 20, &humbugHostVal, 0);
	humbugPortLabel = newtLabel(1, 7, "     Humbug Port:");
	humbugPortEntry = newtEntry(19, 7, params->humbugPort, 20, &humbugPortVal, 0);
	humbugApiLabel  = newtLabel(1, 8, "  Humbug API key:");
	humbugApiEntry  = newtEntry(19, 8, params->humbugApikey, 20, &humbugApiVal, NEWT_FLAG_SCROLL);

	if(1 == params->encrypted){
		encChk = newtCheckbox(19, 10, "Encrypted", 'X', " X", &encVal);
	}else{
		encChk = newtCheckbox(19, 10, "Encrypted", ' ', " X", &encVal);
	}
	encLabel = newtLabel(1, 11, "  Encryption key:");
	encEntry = newtEntry(19, 11, params->humbugKey, 42, &encKey, NEWT_FLAG_SCROLL);

	if(strlen(params->log_file) > 0 ){
		chkLog = newtCheckbox(19, 13, "Log ON/OFF", 'X', " X", &logVal);
	}else{
		chkLog = newtCheckbox(19, 13, "Log ON/OFF", ' ', " X", &logVal);
	}

	eventsLabel  = newtLabel(42, 1, "Events for analyze:");

	button1 = newtButton(36, 13, "Save & Exit");
	button2 = newtButton(53, 13, "Quit");

	chkList = newtForm(NULL, NULL, 0);
	newtFormSetBackground(chkList, NEWT_COLORSET_CHECKBOX);

	for(i=0; i<EVENTS_SIZE; i++) {
		int selected = 0;
		for(y=0; y<params->eventsSize; y++){
			if(0 == strcasecmp(eventsList[i], params->events[y])){
				selected = 1;
				break;
			}
		}
		if (1 == selected) {
			eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], 'X', " X", &eventsResults[i]);
		} else {
			eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], ' ', " X", &eventsResults[i]);
		}
		newtFormAddComponent(chkList, eventsChk[i]);
	}

	hForm = newtForm(NULL, NULL, 0);

	newtFormAddComponents(hForm, button1, button2,
			astIpLabel, astPortLabel, astUserLabel, astPassLabel,
			astIpEntry, astPortEntry, astUserEntry, astPassEntry,
			humbugHostLabel, humbugPortLabel, humbugApiLabel,
			humbugHostEntry, humbugPortEntry, humbugApiEntry,
			eventsLabel, chkList, encChk, encLabel, encEntry, chkLog,
			NULL);

	for(;;){
		do{
			newtFormRun(hForm, &es);
		}while(es.reason == NEWT_EXIT_TIMER);
		if (es.reason == NEWT_EXIT_HOTKEY) {
			int done = 0;
			switch (es.u.key) {
				case NEWT_KEY_ESCAPE:
					done = 1;
					break;
				case NEWT_KEY_F12:
					show_help();
					break;
			}
			if(done)
				break;
		}else if (es.reason == NEWT_EXIT_COMPONENT) {
			if(es.u.co == button1){
				strcpy(params->astIpVal, astIpVal);
				strcpy(params->astPortVal, astPortVal);
				strcpy(params->astUserVal, astUserVal);
				strcpy(params->astPassVal, astPassVal);
				strcpy(params->humbugApikey, humbugApiVal);

				params->eventsSize = 0;
				for(i=0; i<EVENTS_SIZE; i++) {
					if(eventsResults[i] == 'X') {
						strcpy(params->events[params->eventsSize], eventsList[i]);
						params->eventsSize++;
					}
				}
				params->encrypted = (encVal == 'X') ? 1 : 0;
				strcpy(params->humbugKey, encKey);
				strcpy(params->log_file, HBG_LOG_FILE);
				saveHumbugConfig();
			}
			break;
		}
	}
	newtPopWindow();
	newtPopHelpLine();
	newtFinished();
	newtFormDestroy(hForm);
	free(params);
	return(EXIT_SUCCESS);
}