Пример #1
0
// =======================================================
int CInterfaceNewt::askLogin(char *szLogin, char *szPasswd, WORD size)
{
  newtComponent editLoginText;
  newtComponent editPasswdText;
  newtComponent labelLoginText;
  newtComponent labelPasswdText;

  newtComponent form;
  newtComponent btnOk;
  newtComponent btnCancel;
  newtComponent temp;
 
  int nOk = 0; 
  
  while (!nOk)
    {
      newtCenteredWindow(65, 20, i18n("Password required"));
      
      labelLoginText = newtTextbox(1, 5, 60, 1, 0);
      newtTextboxSetText(labelLoginText, i18n("Enter your login"));
      editLoginText = newtEntry(1, 6, "", 55, NULL, NEWT_ENTRY_SCROLL);

      labelPasswdText = newtTextbox(1, 9, 60, 1, 0);
      newtTextboxSetText(labelPasswdText, i18n("Enter your password"));
      editPasswdText = newtEntry(1, 10, "", 55, NULL, NEWT_FLAG_HIDDEN);

      btnOk = newtButton(15, 14, i18n("Ok"));
      btnCancel = newtButton(40, 14, i18n("Cancel"));
      
      form = newtForm(NULL, NULL, 0);
      newtFormAddComponents(form, labelLoginText, editLoginText, 
         labelPasswdText, editPasswdText, btnOk, btnCancel, NULL);
      
      temp = newtRunForm(form);
      newtPopWindow();	
      if (temp == btnCancel)
	{	
	  newtFormDestroy(form);
	  RETURN_int(-1);
	}
      
      strncpy(szLogin, newtEntryGetValue(editLoginText), size-1);
      *(szLogin+size-1) = '\0';
      strncpy(szPasswd, newtEntryGetValue(editPasswdText), size-1);
      *(szPasswd+size-1) = '\0';
      
      if (!(*szLogin) || !(*szPasswd))
	msgBoxError(i18n("Text cannot be empty"));
      else
        nOk = 1;
      
      newtFormDestroy(form);
    }
  
  return 0;
}
int inputBox(const char * text, int height, int width, poptContext optCon, 
		int flags, char ** result) {
    newtComponent form, entry, okay, cancel, answer, tb;
    char * val;
    int rc = DLG_OKAY;
    int top;

    val = poptGetArg(optCon);
    tb = textbox(height - 3 - buttonHeight, width - 2,
			text, flags, &top);

    form = newtForm(NULL, NULL, 0);
    entry = newtEntry(1, top + 1, val, width - 2, &val, 
			NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);

    newtFormAddComponents(form, tb, entry, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    *result = val;

    return rc;
}
Пример #3
0
static int ui_entry__read(const char *title, char *bf, size_t size, int width)
{
	struct newtExitStruct es;
	newtComponent form, entry;
	const char *result;
	int err = -1;

	newtCenteredWindow(width, 1, title);
	form = newtForm(NULL, NULL, 0);
	if (form == NULL)
		return -1;

	entry = newtEntry(0, 0, "0x", width, &result, NEWT_FLAG_SCROLL);
	if (entry == NULL)
		goto out_free_form;

	newtFormAddComponent(form, entry);
	newtFormAddHotKey(form, NEWT_KEY_ENTER);
	newtFormAddHotKey(form, NEWT_KEY_ESCAPE);
	newtFormAddHotKey(form, NEWT_KEY_LEFT);
	newtFormAddHotKey(form, CTRL('c'));
	newtFormRun(form, &es);

	if (result != NULL) {
		strncpy(bf, result, size);
		err = 0;
	}
out_free_form:
	newtPopWindow();
	newtFormDestroy(form);
	return err;
}
static int get_user_input(char *msg, char *buf, int buflen)
{
	newtComponent form;
	newtComponent ok;
	newtComponent cancel;
	newtComponent inpfield;
	const char *input;
	int res = -1;
	struct newtExitStruct es;

	newtCenteredWindow(60,7, msg);

	inpfield = newtEntry(5, 2, "", 50, _NEWT_CAST &input, 0);
	ok = newtButton(22, 3, "OK");
	cancel = newtButton(32, 3, "Cancel");
	form = newtForm(NULL, NULL, 0);
	newtFormAddComponents(form, inpfield, ok, cancel, NULL);
	newtFormRun(form, &es);
	strncpy(buf, input, buflen - 1);
	if (es.u.co == ok) 
		res = 0;
	else
		res = -1;
	newtPopWindow();
	newtFormDestroy(form);
	return res;
}
Пример #5
0
int
do_dict()
{
	newtComponent form, label, entry, text;
	struct newtExitStruct es;
	char *entryValue, *wordlist;
	newtCenteredWindow(70, 20, NULL);

	newtPushHelpLine("输入要查找的词,回车确定,上下键滚动,^C退出");
	label = newtLabel(2, 1, "请输入要查找的词");
	entry = newtEntry(2, 2, "", 40, &entryValue,
			  NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
	text = newtTextbox(2, 3, 66, 17, NEWT_FLAG_WRAP | NEWT_FLAG_SCROLL);
	newtTextboxSetText(text, "");
	form = newtForm(NULL, NULL, 0);
	newtFormAddHotKey(form, Ctrl('c'));
	newtFormAddHotKey(form, Ctrl('\r'));
	newtFormAddHotKey(form, Ctrl('\n'));
	newtFormAddComponents(form, label, entry, text, NULL);
	while (1) {
		newtFormRun(form, &es);
		if ((es.u.key == Ctrl('c')
		     || es.u.key == NEWT_KEY_F12)
		    && es.reason == NEWT_EXIT_HOTKEY)
			break;
		wordlist = search_dict(entryValue);
		newtTextboxSetText(text, wordlist);
	}
	newtFormDestroy(form);
	newtPopHelpLine();
	newtPopWindow();
	return 0;
}
Пример #6
0
// ============================================================================
unsigned int CExceptionsGUI::windowError(char *szTitle, char *szText, char *szButton, char *szCurPath)
{
  BEGIN;
  //char szTemp[] = "/tmp/image";

  unsigned int nRes;
  newtComponent btnOther;
  
  newtComponent formMain = newtForm(NULL, NULL, 0);
  if (szButton)
    btnOther = newtButton(30, 15, szButton);
  else
    btnOther = newtButton(30, 15, "(none)");
  newtComponent btnOk = newtButton(10, 15, i18n("Change"));
  newtComponent btnCancel = newtButton(50, 15, i18n("Cancel"));
  newtComponent editFilename = newtEntry(5, 10, szCurPath, 45, NULL, 0);
  newtComponent labelFilename = newtLabel(5, 9, i18n("Enter new filename"));

  newtComponent labelText = newtTextbox(1, 1, 60, 7, 0);
  newtTextboxSetText(labelText, szText);

  newtComponent widgetTemp;

  newtCenteredWindow(67, 20, szTitle);
  if (szButton)
    newtFormAddComponents(formMain, editFilename, btnOk, btnOther, btnCancel,
       labelFilename, labelText, NULL);
  else
    newtFormAddComponents(formMain, editFilename, btnOk, btnCancel,
       labelFilename, labelText, NULL);

  widgetTemp = newtRunForm(formMain);

  if (widgetTemp == btnCancel)
    nRes = ERR_QUIT;
  else if (szButton && widgetTemp == btnOther)
    nRes = ERR_CONT;
  else
    {
      strncpy(szNewString, newtEntryGetValue(editFilename), 1023);
      *(szNewString+1023) = '\0';

      while (szNewString[strlen(szNewString)-1] == '/')
        szNewString[strlen(szNewString)-1] = '\0';

      nRes = ERR_RETRY;
    }
  newtFormDestroy(formMain);
  newtPopWindow();
  RETURN_WORD(nRes);
}
Пример #7
0
// =======================================================
int CSaveOptWindow::create(char *szImageFile, COptions options)
{
  BEGIN;

  char szTemp[2048];
  
  newtCenteredWindow(78, 20, i18n("save partition to image file"));
  
  m_labelCompression = newtLabel(1, 1, i18n("Compression level"));
  m_radioCompNone = newtRadiobutton(1, 2, i18n("None (very fast + very big file)"), options.dwCompression == COMPRESS_NONE, NULL);
  m_radioCompGzip = newtRadiobutton(1, 3, "Gzip (.gz: medium speed + small image file)", options.dwCompression == COMPRESS_GZIP, m_radioCompNone);
  m_radioCompBzip2 = newtRadiobutton(1, 4, "Bzip2 (.bz2: very slow + very small image file)", options.dwCompression == COMPRESS_BZIP2, m_radioCompGzip);

  m_labelOptions = newtLabel(1, 7, i18n("Options"));
  m_checkCheckBeforeSaving = newtCheckbox(1, 8, i18n("Check partition before saving"), (!!options.bCheckBeforeSaving ? 'X' : ' '), " X", NULL);
  m_checkAskDesc = newtCheckbox(1, 9, i18n("Enter description"), (!!options.bAskDesc ? 'X' : ' '), " X", NULL);
  m_checkOverwrite = newtCheckbox(1, 10, i18n("Overwrite without prompt"), (!!options.bOverwrite ? 'X' : ' '), " X", NULL);

  m_labelSplit = newtLabel(1, 12, i18n("Image split mode"));
  m_radioSplitAuto = newtRadiobutton(1, 13, i18n("Automatic split (when no space left)"), !options.qwSplitSize, NULL);
  m_radioSplitSize = newtRadiobutton(1, 14, i18n("Into files whose size is:............"), !!options.qwSplitSize, m_radioSplitAuto);
  SNPRINTF(szTemp, "%llu", (!!options.qwSplitSize) ? (options.qwSplitSize/1024/1024) : 2048);
  m_editSplitSize = newtEntry(43, 14, szTemp, 8, NULL, 0);
  m_labelSplitSizeKB = newtLabel(52, 14, i18n("MiB"));
  m_checkSplitWait = newtCheckbox(1, 15, i18n("Wait after each volume change"), (!!options.bSplitWait ? 'X' : ' '), " X", NULL);

  m_labelFinish = newtLabel(43, 7, i18n("If finished successfully:"));
  m_radioFinishWait = newtRadiobutton(43, 8, i18n("Wait"), options.dwFinish == FINISH_WAIT, NULL);
  m_radioFinishHalt = newtRadiobutton(43, 9, i18n("Halt"), options.dwFinish == FINISH_HALT, m_radioFinishWait);
  m_radioFinishReboot = newtRadiobutton(43, 10, i18n("Reboot"), options.dwFinish == FINISH_REBOOT, m_radioFinishHalt);
  m_radioFinishQuit = newtRadiobutton(43,11,i18n("Quit"), options.dwFinish == FINISH_QUIT, m_radioFinishReboot);
  m_radioFinishLast = newtRadiobutton(43,12,i18n("Last"), options.dwFinish == FINISH_LAST, m_radioFinishQuit);

  addButtons();
  
  m_formMain = newtForm(NULL, NULL, 0);
  newtFormAddComponents(m_formMain, m_labelCompression, m_labelOptions, m_labelSplit, NULL);
  newtFormAddComponents(m_formMain, m_radioCompNone, m_radioCompGzip, m_radioCompBzip2, m_checkCheckBeforeSaving, m_checkAskDesc, m_checkOverwrite, NULL);
  newtFormAddComponents(m_formMain, m_labelFinish, m_radioFinishWait, m_radioFinishHalt, m_radioFinishReboot, m_radioFinishQuit, m_radioFinishLast, NULL);	
  newtFormAddComponents(m_formMain, m_radioSplitAuto, m_radioSplitSize, m_labelSplitSizeKB, m_editSplitSize, m_checkSplitWait, NULL);
  addHotKeys();
  
  newtDrawForm(m_formMain);
  RETURN_int(0);	
}
Пример #8
0
// =======================================================
int CInterfaceNewt::askText(char *szMessage, char *szTitle, char *szDestText, WORD size)
{
  newtComponent editText;
  newtComponent labelText;
  newtComponent form;
  newtComponent btnOk;
  newtComponent btnCancel;
  newtComponent temp;
  
  *szDestText = 0;
  
  while (!*szDestText)
    {
      newtCenteredWindow(65, 20, szTitle);
      
      labelText = newtTextbox(1, 1, 60, 7, 0/*NEWT_TEXTBOX_SCROLL*/);
      newtTextboxSetText(labelText, szMessage);
      
      editText = newtEntry(1, 9, "", 55, NULL, NEWT_ENTRY_SCROLL);
      btnOk = newtButton(15, 14, i18n("Ok"));
      btnCancel = newtButton(40, 14, i18n("Cancel"));
      
      form = newtForm(NULL, NULL, 0);
      newtFormAddComponents(form, labelText, editText, btnOk, btnCancel, NULL);
      
      temp = newtRunForm(form);
      newtPopWindow();	
      if (temp == btnCancel)
	{	
	  newtFormDestroy(form);
	  RETURN_int(-1);
	}
      
      strncpy(szDestText, newtEntryGetValue(editText), size-1);
      *(szDestText+size-1) = '\0';
      
      if (*szDestText == 0)
	msgBoxError(i18n("Text cannot be empty"));
      
      newtFormDestroy(form);
    }
  
  return 0;
}
Пример #9
0
static char *newKickstartLocation(const char *origLocation) {
    const char *location;
    char *retval = NULL;
    newtComponent f, okay, cancel, answer, locationEntry;
    newtGrid grid, buttons;

    startNewt();

    locationEntry = newtEntry(-1, -1, NULL, 60, &location, NEWT_FLAG_SCROLL);
    newtEntrySet(locationEntry, origLocation, 1);

    /* button bar at the bottom of the window */
    buttons = newtButtonBar(_("OK"), &okay, _("Cancel"), &cancel, NULL);

    grid = newtCreateGrid(1, 3);

    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT,
                     newtTextboxReflowed(-1, -1, _("Unable to download the kickstart file.  Please modify the kickstart parameter below or press Cancel to proceed as an interactive installation."), 60, 0, 0, 0),
                     0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, locationEntry,
                     0, 1, 0, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons,
                     0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

    f = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, f, 1);
    newtGridWrappedWindow(grid, _("Error downloading kickstart file"));
    newtGridFree(grid, 1);

    /* run the form */
    answer = newtRunForm(f);

    if (answer != cancel)
        retval = strdup(location);

    newtFormDestroy(f);
    newtPopWindow();

    return retval;
}
Пример #10
0
static newtComponent
nmt_newt_entry_build_component (NmtNewtComponent *component,
                                gboolean          sensitive)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (component);
    newtComponent co;
    char *text_lc;
    int flags;

    flags = convert_flags (priv->flags);
    if (!sensitive)
        flags |= NEWT_FLAG_DISABLED;

    text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL;
    co = newtEntry (-1, -1, text_lc, priv->width, NULL, flags);
    g_free (text_lc);

    if (priv->last_cursor_pos != -1)
        newtEntrySetCursorPosition (co, priv->last_cursor_pos);

    newtEntrySetFilter (co, entry_filter, component);
    return co;
}
Пример #11
0
// =======================================================
void CInterfaceNewt::askDescription(char *szDescription, DWORD dwMaxLen)
{
  newtComponent editDesc;
  newtComponent labelText;
  newtComponent form;
  newtComponent btnOk;
  
  memset(szDescription, 0, dwMaxLen);
  
  newtCenteredWindow(65, 18, i18n("Partition description"));
  
  labelText = newtLabel(1, 1, i18n("You can enter a description of the saved partition:"));
  editDesc = newtEntry(1, 3, "", 60, NULL, NEWT_ENTRY_SCROLL);
  btnOk = newtButton(27, 13, i18n("Ok"));
  
  form = newtForm(NULL, NULL, 0);
  newtFormAddComponents(form, labelText, editDesc, btnOk, NULL);
  
  newtRunForm(form);
  newtPopWindow();	
  
  strncpy(szDescription, newtEntryGetValue(editDesc), dwMaxLen);
  newtFormDestroy(form);
}
Пример #12
0
int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol,
                      char * doSecondarySetup) {
    newtComponent form, okay, cancel, siteEntry, dirEntry;
    newtComponent answer, text;
    newtComponent cb = NULL;
    char * site, * dir;
    char * reflowedText = NULL;
    int width, height;
    newtGrid entryGrid, buttons, grid;
    char * chptr;
    char * buf = NULL;

    if (ui->address) {
        site = ui->address;
        dir = ui->prefix;
    } else {
        site = "";
        dir = "";
    }

    if (ui->login || ui->password || ui->proxy || ui->proxyPort)
        *doSecondarySetup = '*';
    else
        *doSecondarySetup = ' ';

    buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL);
    
    switch (protocol) {
    case URL_METHOD_FTP:
        buf = sdupprintf(_(netServerPrompt), _("FTP"), getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;
    case URL_METHOD_HTTP:
        buf = sdupprintf(_(netServerPrompt), _("Web"), getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;

#ifdef ROCKS
    case URL_METHOD_HTTPS:
        buf = sdupprintf(_(netServerPrompt), "Secure Web", getProductName());
        reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height);
        free(buf);
        break;
#endif /* ROCKS */
    }
    text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP);
    newtTextboxSetText(text, reflowedText);
    free(reflowedText);

    siteEntry = newtEntry(22, 8, site, 24, (const char **) &site, 
                          NEWT_ENTRY_SCROLL);
    dirEntry = newtEntry(22, 9, dir, 24, (const char **) &dir, 
                         NEWT_ENTRY_SCROLL);

    entryGrid = newtCreateGrid(2, 2);
    newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, (protocol == URL_METHOD_FTP) ?
                                        _("FTP site name:") :
                                        _("Web site name:")),
                     0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, 
                               sdupprintf(_("%s directory:"), 
                                          getProductName())),
                     0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0);
    newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, siteEntry,
                     0, 0, 0, 0, 0, 0);
    newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, dirEntry,
                     0, 0, 0, 0, 0, 0);

    grid = newtCreateGrid(1, 4);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
                     0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid,
                     0, 0, 0, 1, 0, 0);

    if (protocol == URL_METHOD_FTP) {
        cb = newtCheckbox(3, 11, _("Use non-anonymous ftp"),
                          *doSecondarySetup, NULL, doSecondarySetup);
        newtGridSetField(grid, 0, 2, NEWT_GRID_COMPONENT, cb,
                         0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0);
    }
        
    newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
                     0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);

    newtGridWrappedWindow(grid, (protocol == URL_METHOD_FTP) ? _("FTP Setup") :
                          _("HTTP Setup"));

    form = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, form, 1);    

    do {
        answer = newtRunForm(form);
        if (answer != cancel) {
            if (!strlen(site)) {
                newtWinMessage(_("Error"), _("OK"),
                               _("You must enter a server name."));
                continue;
            }
            if (!strlen(dir)) {
                newtWinMessage(_("Error"), _("OK"),
                               _("You must enter a directory."));
                continue;
            }

            if (!addrToIp(site)) {
                newtWinMessage(_("Unknown Host"), _("OK"),
                        _("%s is not a valid hostname."), site);
                continue;
            }
        }

        break;
    } while (1);
    
    if (answer == cancel) {
        newtFormDestroy(form);
        newtPopWindow();
        
        return LOADER_BACK;
    }

    if (ui->address) free(ui->address);
    ui->address = strdup(site);

    if (ui->prefix) free(ui->prefix);

    /* add a slash at the start of the dir if it is missing */
    if (*dir != '/') {
        if (asprintf(&(ui->prefix), "/%s", dir) == -1)
            ui->prefix = strdup(dir);
    } else {
        ui->prefix = strdup(dir);
    }

    /* Get rid of trailing /'s */
    chptr = ui->prefix + strlen(ui->prefix) - 1;
    while (chptr > ui->prefix && *chptr == '/') chptr--;
    chptr++;
    *chptr = '\0';

    if (*doSecondarySetup != '*') {
        if (ui->login)
            free(ui->login);
        if (ui->password)
            free(ui->password);
        if (ui->proxy)
            free(ui->proxy);
        if (ui->proxyPort)
            free(ui->proxyPort);
        ui->login = ui->password = ui->proxy = ui->proxyPort = NULL;
    }

    ui->protocol = protocol;

    newtFormDestroy(form);
    newtPopWindow();

    return 0;
}
static int login(char *hostname)
{
	newtComponent form;
	newtComponent cancel;
	newtComponent login;
	newtComponent username;
	newtComponent password;
	newtComponent label;
	newtComponent ulabel;
	newtComponent plabel;
	const char *user;
	const char *pass;
	struct message *m;
	struct newtExitStruct es;
	char tmp[55];
	struct hostent *hp;
	int res = -1;
	
	session.fd = socket(AF_INET, SOCK_STREAM, 0);
	if (session.fd < 0) {
		snprintf(tmp, sizeof(tmp), "socket() failed: %s\n", strerror(errno));
		show_message("Socket failed", tmp);
		return -1;
	}
	
	snprintf(tmp, sizeof(tmp), "Looking up %s\n", hostname);
	show_doing("Connecting....", tmp);
	
	
	hp = gethostbyname(hostname);
	if (!hp) {
		snprintf(tmp, sizeof(tmp), "No such address: %s\n", hostname);
		show_message("Host lookup failed", tmp);
		return -1;
	}
	hide_doing();
	snprintf(tmp, sizeof(tmp), "Connecting to %s", hostname);
	show_doing("Connecting...", tmp);

	session.sin.sin_family = AF_INET;
	session.sin.sin_port = htons(DEFAULT_MANAGER_PORT);
	memcpy(&session.sin.sin_addr, hp->h_addr, sizeof(session.sin.sin_addr));

	if (connect(session.fd,(struct sockaddr*)&session.sin, sizeof(session.sin))) {
		snprintf(tmp, sizeof(tmp), "%s failed: %s\n", hostname, strerror(errno));
		show_message("Connect Failed", tmp);
		return -1;
	}
	
	hide_doing();
	
	login = newtButton(5, 6, "Login");
	cancel = newtButton(25, 6, "Cancel");
	newtCenteredWindow(40, 10, "Asterisk Manager Login");
	snprintf(tmp, sizeof(tmp), "Host:     %s", hostname);
	label = newtLabel(4,1, tmp);
	
	ulabel = newtLabel(4,2,"Username:"******"Password:"******"", 20, _NEWT_CAST &user, 0);
	password = newtEntry(14, 3, "", 20, _NEWT_CAST &pass, NEWT_FLAG_HIDDEN);
	
	form = newtForm(NULL, NULL, 0);
	newtFormAddComponents(form, username, password, login, cancel, label, ulabel, plabel,NULL);
	newtFormRun(form, &es);
	if (es.reason == NEWT_EXIT_COMPONENT) {
		if (es.u.co == login) {
			snprintf(tmp, sizeof(tmp), "Logging in '%s'...", user);
			show_doing("Logging in", tmp);
			/* Check to see if the remote host supports MD5 Authentication */
			manager_action("Challenge", "AuthType: MD5\r\n");
			m = wait_for_response(10000);
			if (m && !strcasecmp(get_header(m, "Response"), "Success")) {
				char *challenge = get_header(m, "Challenge");
				int x;
				int len = 0;
				char md5key[256] = "";
				struct MD5Context md5;
				unsigned char digest[16];
				MD5Init(&md5);
				MD5Update(&md5, (unsigned char *)challenge, strlen(challenge));
				MD5Update(&md5, (unsigned char *)pass, strlen(pass));
				MD5Final(digest, &md5);
				for (x=0; x<16; x++)
					len += sprintf(md5key + len, "%2.2x", digest[x]);
				manager_action("Login",
						"AuthType: MD5\r\n"
						"Username: %s\r\n"
						"Key: %s\r\n",
						user, md5key);
				m = wait_for_response(10000);
				hide_doing();
				if (!strcasecmp(get_header(m, "Response"), "Success")) {
					res = 0;
				} else {
					show_message("Login Failed", get_header(m, "Message"));
				}
			} else {
				memset(m, 0, sizeof(m));
				manager_action("Login", 
					"Username: %s\r\n"
					"Secret: %s\r\n",
						user, pass);
				m = wait_for_response(10000);
				hide_doing();
				if (m) {
					if (!strcasecmp(get_header(m, "Response"), "Success")) {
						res = 0;
					} else {
						show_message("Login Failed", get_header(m, "Message"));
					}
				}
			}
		}
	}
	newtFormDestroy(form);
	return res;
}
Пример #14
0
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;
}
Пример #15
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;
}
Пример #16
0
int handledhcp(void)
{
	char *results[MAX_BOXES];
	char enabledresult;
	char startenabled;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent labels[MAX_BOXES];
	newtComponent ok, cancel;	
	char message[1000];
	char *labeltexts[MAX_BOXES] = {
		_("Start address:"),
		_("End address:"),
		_("Primary DNS:"),
		_("Secondary DNS:"),
		_("Default lease (mins):"),
		_("Max lease (mins):"),
		_("Domain name suffix:")
	};
	char *varnames[MAX_BOXES] = {
		"START_ADDR_GREEN",
		"END_ADDR_GREEN",
		"DNS1_GREEN",
		"DNS2_GREEN",
		"DEFAULT_LEASE_TIME_GREEN",
		"MAX_LEASE_TIME_GREEN",
		"DOMAIN_NAME_GREEN"
	};
	char defaults[MAX_BOXES][STRING_SIZE]; 
	int result;
	int c;
	char temp[STRING_SIZE];
	struct keyvalue *mainkv = initkeyvalues();
	struct keyvalue *dhcpkv = initkeyvalues();
	struct keyvalue *ethernetkv = initkeyvalues();
	int error;
	FILE *file;
	char greenaddress[STRING_SIZE];	
	char greennetaddress[STRING_SIZE];
	char greennetmask[STRING_SIZE];
	
 	memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES);
	
	if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	/* Set default values. */	
	findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]);
	findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]);
	strcpy(defaults[DEFAULT_LEASE_TIME], "60");
	strcpy(defaults[MAX_LEASE_TIME], "120");

	newtCenteredWindow(55, 18, _("DHCP server configuration"));

	dhcpform = newtForm(NULL, NULL, 0);

	header = newtTextboxReflowed(1, 1,
		_("Configure the DHCP server by entering the settings information."),
		52, 0, 0, 0);
	newtFormAddComponent(dhcpform, header);

	strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp);
	if (strcmp(temp, "on") == 0)
		startenabled = '*';
	else
		startenabled = ' ';
	enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult);
	newtFormAddComponent(dhcpform, enabledcheckbox);
	newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL);		

	for (c = 0; c < MAX_BOXES; c++)
	{
		labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0);
		newtTextboxSetText(labels[c], labeltexts[c]);
		newtFormAddComponent(dhcpform, labels[c]);				
		strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp);
		entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0);
		newtFormAddComponent(dhcpform, entries[c]);		
		if (startenabled == ' ')
			newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);			
		
	}
	
	ok = newtButton(10, c + 7, _("OK"));
	cancel = newtButton(34, c + 7, _("Cancel"));

	newtFormAddComponents(dhcpform, ok, cancel, NULL);
	
	do {
		error = 0;
		newtFormRun(dhcpform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */		
			if (enabledresult == '*')
			{
				strcpy(message, _("The following fields are invalid:\n\n"));
				if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("Start address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("End address"));
					strcat(message, "\n");
					error = 1;
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Primary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Secondary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (!(atol(results[DEFAULT_LEASE_TIME])))
				{
					strcat(message, _("Default lease time"));
					strcat(message, "\n");
					error = 1;
				}
				if (!(atol(results[MAX_LEASE_TIME])))
				{
					strcat(message, _("Max. lease time"));
					strcat(message, "\n");
					error = 1;
				}
			}				
			
			if (error)
				errorbox(message);
			else
			{
				for (c = 0; c < MAX_BOXES; c++)
					replacekeyvalue(dhcpkv, varnames[c], results[c]);
				if (enabledresult == '*')
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
					fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
					chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
				}
				else
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
					unlink(CONFIG_ROOT "/dhcp/enable_green");
					mysystem(NULL, "/usr/local/bin/dhcpctrl disable");
				}
				replacekeyvalue(dhcpkv, "VALID", "yes");
				writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
				
				findkey(ethernetkv, "GREEN_ADDRESS", greenaddress);				
				findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress);
				findkey(ethernetkv, "GREEN_NETMASK", greennetmask);
			
				file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w");
				fprintf(file, "ddns-update-style none;\n");
				fprintf(file, "authoritative;\n");
				fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask);
				fprintf(file, "{\n");
				fprintf(file, "\toption subnet-mask %s;\n", greennetmask);
				fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]);		
				fprintf(file, "\toption routers %s;\n", greenaddress);
				if (strlen(results[PRIMARY_DNS]))
				{
					fprintf(file, "\toption domain-name-servers ");
					fprintf(file, "%s", results[PRIMARY_DNS]);
					if (strlen(results[SECONDARY_DNS]))
						fprintf(file, ", %s", results[SECONDARY_DNS]);
					fprintf(file, ";\n");
				}
				
				fprintf(file, "\trange %s %s;\n",	results[START_ADDRESS], results[END_ADDRESS]);
				fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60);
				fprintf(file, "\tmax-lease-time %d;\n",	(int) atol(results[MAX_LEASE_TIME]) * 60);
				fprintf(file, "}\n");
				fclose(file);
				chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
				if (automode == 0)
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
			}
			result = 1;
		}
		else
			result = 0;
	} while (error);
	
	newtFormDestroy(dhcpform);
	newtPopWindow();
	
	freekeyvalues(dhcpkv);
	freekeyvalues(ethernetkv);
	freekeyvalues(mainkv);
	
	return result;
}
/**
 * Ask the user to enter a value.
 * @param title The title of the dialog box.
 * @param b The blurb (e.g. what you want the user to enter).
 * @param output The string to put the user's answer in. It has to be freed by the caller
 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
 */
	bool popup_and_get_string(char *title, char *b, char *output) {

		/*@ newt ************************************************************ */
		newtComponent myForm;
		newtComponent b_1;
		newtComponent b_2;
		newtComponent b_res;
		newtComponent text;
		newtComponent type_here;

		/*@ pointers ********************************************************* */
		char *entry_value = NULL;

		/*@ buffers ********************************************************** */
		char *blurb = NULL;
		size_t n = 0;
		bool ret = TRUE;

		assert_string_is_neither_NULL_nor_zerolength(title);
		assert(b != NULL);

		if (g_text_mode) {
			printf
				("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
				 title, b);
			paranoid_free(output);
			(void) getline(&output, &n, stdin);
			if (output[strlen(output) - 1] == '\n')
				output[strlen(output) - 1] = '\0';
			return (ret);
		}
		asprintf(&blurb, b);
		text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);

		type_here =
			newtEntry(2, newtTextboxGetNumLines(text) + 2,
					  output, 50,
					  &entry_value, NEWT_FLAG_RETURNEXIT
			);
		b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _("  OK  "));
		b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel"));
		newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
		/* BERLIOS: center_string is now broken replace it ! */
		//center_string(blurb, 80);
		newtPushHelpLine(blurb);
		paranoid_free(blurb);

		b_res = newtRunForm(myForm);
		newtPopHelpLine();
		if (b_res == b_2) {
			ret = FALSE;
		} else {
			// Copy entry_value before destroying the form
			// clearing potentially output before
			paranoid_alloc(output,entry_value);
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		return(ret);
	}
Пример #18
0
/* Small window to change IP and Netmask of some colour */
void changeaddress(char *colour, int *changed_flag)
{
    newtComponent networkform;
    newtComponent text;
    newtComponent ok, cancel;
    struct newtExitStruct exitstruct;
    char keyvalue[STRING_SIZE];
    char addresskey[STRING_SIZE];
    char netmaskkey[STRING_SIZE];
    char netaddresskey[STRING_SIZE];
    newtComponent addresslabel;
    newtComponent netmasklabel;
    newtComponent addressentry;
    newtComponent netmaskentry;
    const char *addressresult;
    const char *netmaskresult;
    char message[STRING_SIZE_LARGE];
    int error;
    int numLines;
    char *tmpstring;

    /* Build some key strings. */
    sprintf(addresskey, "%s_1_ADDRESS", colour);
    sprintf(netmaskkey, "%s_1_NETMASK", colour);
    sprintf(netaddresskey, "%s_1_NETADDRESS", colour);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_ENTER_THE_IP_ADDRESS_INFORMATION"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    text = newtTextboxReflowed(1, 1, message, 68, 0, 0, 0);
    numLines = newtTextboxGetNumLines(text);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_INTERFACE"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    newtCenteredWindow(72, 10 + numLines, message);
    networkform = newtForm(NULL, NULL, 0);
    newtFormAddComponent(networkform, text);

    /* Address */
    addresslabel = newtTextbox(2, 2 + numLines, 18, 1, 0);
    newtTextboxSetText(addresslabel, gettext("TR_IP_ADDRESS_PROMPT"));
    if (!strcmp(colour, "GREEN")) {
        /* green only for now */
        strcpy(keyvalue, DEFAULT_IP);
    }
    else {
        strcpy(keyvalue, "");
    }
    find_kv_default(eth_kv, addresskey, keyvalue);
    addressentry = newtEntry(20, 2 + numLines, keyvalue, 20, &addressresult, 0);
    newtEntrySetFilter(addressentry, filterip, NULL);
    newtFormAddComponent(networkform, addresslabel);
    newtFormAddComponent(networkform, addressentry);

    /* Netmask */
    netmasklabel = newtTextbox(2, 3 + numLines, 18, 1, 0);
    newtTextboxSetText(netmasklabel, gettext("TR_NETMASK_PROMPT"));
    strcpy(keyvalue, DEFAULT_NETMASK);
    find_kv_default(eth_kv, netmaskkey, keyvalue);
    netmaskentry = newtEntry(20, 3 + numLines, keyvalue, 20, &netmaskresult, 0);
    newtEntrySetFilter(netmaskentry, filterip, NULL);
    newtFormAddComponent(networkform, netmasklabel);
    newtFormAddComponent(networkform, netmaskentry);

    ok = newtButton(6, 5 + numLines, gettext("TR_OK"));
    /* In case of installer we need a valid address, no turning back */
    if (flag_is_state == setupchroot) {
        newtFormAddComponent(networkform, ok);
    }
    else {
        cancel = newtButton(26, 5 + numLines, gettext("TR_GO_BACK"));
        newtFormAddComponents(networkform, ok, cancel, NULL);
    }
    newtRefresh();
    newtDrawForm(networkform);

    do {
        error = 0;
        newtFormRun(networkform, &exitstruct);

        if (exitstruct.u.co == ok) {

            strcpy(message, gettext("TR_INVALID_FIELDS"));
            if (VALID_IP(addressresult) == FALSE) {
                strcat(message, gettext("TR_IP_ADDRESS_CR"));
                error = 1;
                newtFormSetCurrent(networkform, addressentry);
            }
            if (VALID_IP(netmaskresult) == FALSE) {
                strcat(message, gettext("TR_NETWORK_MASK_CR"));
                error = 1;
                newtFormSetCurrent(networkform, netmaskentry);
            }

            // TODO: additional network mask validation

            if (error) {
                errorbox(message);
            }
            else {
                /* all is well, calc netaddress and store everything */
                unsigned long int intaddress;
                unsigned long int intnetaddress;
                unsigned long int intnetmask;
                struct in_addr i_addr;
                char *netaddress;

                update_kv(&eth_kv, addresskey, (char *) addressresult);
                update_kv(&eth_kv, netmaskkey, (char *) netmaskresult);
                /* calculate netaddress */
                intaddress = inet_addr(addressresult);
                intnetmask = inet_addr(netmaskresult);
                intnetaddress = intaddress & intnetmask;
                i_addr.s_addr = intnetaddress;
                netaddress = inet_ntoa(i_addr);
                update_kv(&eth_kv, netaddresskey, (char *) netaddress);

                changed_config = 1;
                *changed_flag = 1;
            }
        }
    }
    while (error);

    newtFormDestroy(networkform);
    newtPopWindow();
}
Пример #19
0
static int getManualModuleArgs(struct moduleInfo * mod, char *** moduleArgs) {
    newtGrid grid, buttons;
    newtComponent text, f, ok, back, entry;
    struct newtExitStruct es;
    int done = 0, i;
    char * buf;
    char *argsEntry = "";

    if (*moduleArgs) {
        for (i = 0; (*moduleArgs)[i]; i++)
            argsEntry = strcat(argsEntry, (*moduleArgs)[i]);
    }

    f = newtForm(NULL, NULL, 0);
    if (asprintf(&buf,
                 _("Please enter any parameters which you wish to pass "
                   "to the %s module separated by spaces.  If you don't "
                   "know what parameters to supply, skip this screen "
                   "by pressing the \"OK\" button."), mod->moduleName) == -1) {
        logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
        abort();
    }

    text = newtTextboxReflowed(-1, -1, buf, 60, 0, 10, 0);
    entry = newtEntry(-1, -1, argsEntry, 50, (const char **) &argsEntry, 
                      NEWT_ENTRY_SCROLL);
    
    newtFormAddHotKey(f, NEWT_KEY_F12);
    
    buttons = newtButtonBar(_("OK"), &ok, _("Back"), &back, NULL);
    
    grid = newtCreateGrid(1, 3);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
                     0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, entry, 
                     0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons,
                     0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
    
    newtGridWrappedWindow(grid, _("Enter Module Parameters"));
    newtGridAddComponentsToForm(grid, f, 1);
    
    do {
        newtFormRun(f, &es);

        if (es.reason  == NEWT_EXIT_COMPONENT && es.u.co == back) {
            done = -1;
        } else {
            done = 1;
        }
    } while (done == 0);

    free(buf);
    newtGridFree(grid, 1);

    if (done == -1) {
        newtFormDestroy(f);
        newtPopWindow();

        return LOADER_BACK;
    }
    logMessage(INFO, "specified args of %s for %s", argsEntry, mod->moduleName);

    if (strlen(argsEntry) > 0) {
        int numAlloced = 5;
        char * start;
        char * end;

        i = 0;

        *moduleArgs = malloc((numAlloced + 1) * sizeof(*moduleArgs));
        start = argsEntry;
        while (start && *start) {
            end = start;
            while (!isspace(*end) && *end) end++;
            *end = '\0';
            (*moduleArgs)[i++] = strdup(start);
            start = end + 1;
            *end = ' ';
            start = strchr(end, ' ');
            if (start) start++;

            if (i >= numAlloced) {
                numAlloced += 5;
                *moduleArgs = realloc(*moduleArgs, 
                                      sizeof(*moduleArgs) * (numAlloced + 1));
            }
        }
        (*moduleArgs)[i] = NULL;
    }

    newtFormDestroy(f);
    newtPopWindow();

    return LOADER_OK;
}
Пример #20
0
/* only supports up to 50 buttons and entries -- shucks! */
static int mynewtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, 
			    int flexUp, int dataWidth, void (*callback_func)(char ** strings),
			    struct newtWinEntry * items, char * button1, ...) {
	newtComponent buttons[50], result, form, textw;
	newtGrid grid, buttonBar, subgrid;
	int numItems;
	int rc, i;
	int numButtons;
	char * buttonName;
	newtComponent entries[50];

	va_list args;
	
	textw = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
				    flexUp, 0);
	
	for (numItems = 0; items[numItems].text; numItems++); 
	
	buttonName = button1, numButtons = 0;
	va_start(args, button1);
	while (buttonName) {
		buttons[numButtons] = newtButton(-1, -1, buttonName);
		numButtons++;
		buttonName = va_arg(args, char *);
	}
	
	va_end(args);
	
	buttonBar = newtCreateGrid(numButtons, 1);
	for (i = 0; i < numButtons; i++) {
		newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT, 
				 buttons[i],
				 i ? 1 : 0, 0, 0, 0, 0, 0);
	}

	if (callback_func) {
		callback_real_function = callback_func;
		entries[numItems] = NULL;
	}
	else
		callback_real_function = NULL;
	
	subgrid = newtCreateGrid(2, numItems);
	for (i = 0; i < numItems; i++) {
		newtComponent entr = newtEntry(-1, -1, items[i].value ? 
					       *items[i].value : NULL, dataWidth,
					       (const char**)items[i].value, items[i].flags);

		newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT,
				 newtLabel(-1, -1, items[i].text),
				 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
		newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT,
				 entr,
				 1, 0, 0, 0, 0, 0);
		if (callback_func) {
			entries[i] = entr;
			newtComponentAddCallback(entr, default_callback, entries);
		}
	}
	
	
	grid = newtCreateGrid(1, 3);
	form = newtForm(NULL, 0, 0);
	newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, textw, 
			 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
	newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 
			 0, 1, 0, 0, 0, 0);
	newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonBar, 
			 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
	newtGridAddComponentsToForm(grid, form, 1);
	newtGridWrappedWindow(grid, title);
	newtGridFree(grid, 1);
	
	result = newtRunForm(form);
	
	for (rc = 0; rc < numItems; rc++)
		*items[rc].value = strdup(*items[rc].value);
	
	for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
	if (rc == numButtons) 
		rc = 0; /* F12 */
	else 
		rc++;
	
	newtFormDestroy(form);
	newtPopWindow();
	
	return rc;
}
Пример #21
0
// =======================================================
int CInterfaceNewt::guiInitMainWindow(char *szDevice, char *szImageFile, char *szNetworkIP, DWORD *dwServerPort, bool *bSsl)
{
  newtComponent formMain, btnContinue, btnExit, btnAbout;
  newtComponent labelPartition, labelImage, editPartition, editImage, btnImage;
  newtComponent widgetTemp, labelAction, radioSave, radioRestore, radioMbr;
  newtComponent checkNetwork, labelNetwork, labelPort, editNetwork, editPort, checkSsl;
  newtExitStruct event;
  char szTemp[1024];
  int nAction;
  int nRes;

  showDebug(8, "guiInitMainWindow\n");
  
  SNPRINTF(szTemp, "Partition Image %s", PACKAGE_VERSION);
  newtCenteredWindow(67, 20, szTemp);
  
  labelPartition = newtLabel(1, 0, i18n("* Partition to save/restore"));
  editPartition = newtListbox(3, 1, 7, NEWT_FLAG_SCROLL);
  labelImage = newtLabel(1, 9, i18n("* Image file to create/use"));
  editImage = newtEntry(3, 10, szImageFile, 59, NULL, NEWT_FLAG_SCROLL);
  btnImage = newtCompactButton(62, 10, "*");

  labelAction = newtLabel(1, 12, i18n("Action to be done:"));
  radioSave = newtRadiobutton(1, 13, i18n("Save partition into a new image file"), true, NULL);
  radioRestore = newtRadiobutton(1, 14, i18n("Restore partition from an image file"), false, radioSave);
  radioMbr = newtRadiobutton(1, 15, i18n("Restore an MBR from the image file"), false, radioRestore);
  
  checkNetwork = newtCheckbox(1, 17, i18n("Connect to server"), (!!(*szNetworkIP) ? 'X' : ' '), " X", NULL);
#ifdef HAVE_SSL
  checkSsl = newtCheckbox(5, 19, i18n("Encrypt data on the network with SSL"), (*bSsl ? 'X' : ' '), " X", NULL);
#else
  #ifdef MUST_LOGIN
    checkSsl = newtLabel(5, 19,i18n("SSL disabled at compile time"));
  #else
    checkSsl = newtLabel(5, 19,i18n("SSL&login disabled at compile time"));
  #endif
#endif
  labelNetwork = newtLabel(5, 18, i18n("IP/name of the server:"));
  editNetwork = newtEntry(28, 18, szNetworkIP, 25, NULL, 0);
  labelPort = newtLabel(54, 18, i18n("Port:"));
  SNPRINTF(szTemp, "%u", *dwServerPort);
  editPort = newtEntry(60, 18, szTemp, 6, NULL, 0);
  
  btnContinue = newtCompactButton(50, 12, i18n("Next (F5)"));
  btnAbout = newtCompactButton(50, 14, i18n("About"));
  btnExit = newtCompactButton(50, 16, i18n("Exit (F6)"));

  nRes = fillPartitionList(editPartition);
  if (nRes == -1)
    RETURN_int(-1);
  
  formMain = newtForm(NULL, NULL, 0);
  newtFormAddComponents(formMain, labelPartition, labelImage, editPartition, editImage,
                        btnImage, labelAction, radioSave, radioRestore, radioMbr, checkNetwork,
			labelNetwork, editNetwork, labelPort, editPort, checkSsl, 
			btnContinue, btnAbout, btnExit, NULL);
  newtFormAddHotKey(formMain, KEY_EXIT); // Exit
  newtFormAddHotKey(formMain, KEY_OKAY); // Okay

 begin:
  /*widgetTemp = */newtFormRun(formMain, &event);
  widgetTemp = newtFormGetCurrent(formMain);

  if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnExit))) 
  //if(widgetTemp == btnExit)
    return OPERATION_EXIT;

  if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnAbout))
    {	
      showAboutDialog();
      goto begin;
    }

  if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnImage))
    {	
      char *fs_;
      fs_=filesel(newtEntryGetValue(editImage));
      if(fs_) {
        newtEntrySet(editImage, fs_, 1);
//        free(fs_);
        }
      
      goto begin;
    }

  
  if (strcmp(newtEntryGetValue(editImage), "") == 0) // if "image" field empty
    {	
      msgBoxError(i18n("The \"Image\" field is empty. Cannot continue"));
      goto begin;
    }
  
  if (newtCheckboxGetValue(checkNetwork) == 'X')
    {
      if (!(*newtEntryGetValue(editNetwork)))	
	{
	  msgBoxError(i18n("The \"Server IP/Name\" field is empty. Cannot continue"));
	  goto begin;
	}
      
      if (!atoi((char*)newtEntryGetValue(editPort)))
	{
	  msgBoxError(i18n("The \"Server Port\" field is not a valid integer. Cannot continue"));
	  goto begin;
	}
      
    }
  
  // get device
  strcpy(szDevice, (char*)newtListboxGetCurrent(editPartition));
  
  // image file
  strcpy(szImageFile, newtEntryGetValue(editImage));
  
  // network
  if (newtCheckboxGetValue(checkNetwork) == 'X') // If network is activated
    {
      strcpy(szNetworkIP, (char*)newtEntryGetValue(editNetwork));
      *dwServerPort = atoi((char*)newtEntryGetValue(editPort));
#ifdef HAVE_SSL
      *bSsl = (newtCheckboxGetValue(checkSsl) == 'X');
#endif
    }
  else // no network
    {
      *szNetworkIP = 0;
      *dwServerPort = OPTIONS_DEFAULT_SERVERPORT;	
    }
  
  nAction = 0;
  
  if (newtRadioGetCurrent(radioRestore) == radioSave)
    {	
      nAction = OPERATION_SAVE;
    }
  else if (newtRadioGetCurrent(radioRestore) == radioRestore)
    {
      nAction = OPERATION_RESTORE;
    }
  else if (newtRadioGetCurrent(radioRestore) == radioMbr)
    {
      nAction = OPERATION_RESTMBR;
    }
  
  newtFormDestroy(formMain);
  newtPopWindow();
  
  return nAction;
}
Пример #22
0
// return a malloc()ed path
char *filesel(char *dr)
{
	newtComponent	lb, b1, b2, b3, l1, l2, f;
	const char	*enr2, *enr3;
	char		*curv;
	char		curvv[PATH_MAX]; // stupid, but who cares...
	int		i, cnt;
	fde		*sel, *sela;
	char		cwd[PATH_MAX], cwdcd[PATH_MAX], *ret=NULL;
	struct		newtExitStruct es;
	struct		stat st;
	
	newtCenteredWindow(65, 15, i18n("Select path"));
	
	f = newtForm(NULL, NULL, 0);
	
	b1 = newtCompactButton(59, 14, i18n("Ok"));
	b3 = newtCompactButton(45, 14, i18n("Cancel"));
	
	l2 = newtEntry(1, 14, "", 25, &enr3, NEWT_FLAG_SCROLL);
	b2 = newtCompactButton(26, 14, i18n("Create dir"));
	
	lb = newtListbox(1, 2, 12, /*NEWT_FLAG_MULTIPLE |*/ /*NEWT_FLAG_BORDER | */
		NEWT_FLAG_RETURNEXIT |
		NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
	
	if(dr && strlen(dr) > 0) 
	{
		// let it show the file or dir at any case
		l1 = newtEntry(1, 0, dr, 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED);
		stat(dr,&st);
		if(S_ISDIR(st.st_mode)) 
		{
			dir_here(lb,dr);
			strcpy(cwd,dr);
		} else
		{
			dir_here(lb,dirname(dr));
			strcpy(cwd,dirname(dr));
		}
	}
	else
	{
		// if NULL, show the current dir
		l1 = newtEntry(1, 0, get_current_dir_name(), 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED);
		dir_here(lb,get_current_dir_name());
		strcpy(cwd,get_current_dir_name());
	}
	
	newtListboxSetWidth(lb,63);
	newtFormAddComponents(f, lb,l1, l2, b2, b1, b3, NULL);
	newtRefresh();
	newtFormSetTimer(f, 200);
	
	do
	{
		newtFormRun(f, &es);
		
		if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == lb) 
		{
			sel=(fde*)newtListboxGetCurrent(lb);
			if (sel && S_ISDIR(sel->st.st_mode))
			{
				cnt=newtListboxItemCount(lb);
				// delete items there:
				for(i=0; i < cnt; i++) 
				{
					newtListboxGetEntry(lb, i, &curv, (void**)&sela);
					if(sela != sel) 
					{
						free(sela->name);
						free(sela);
					}
					else
					{
						strcpy(curvv, curv);
					}
				}
				
				newtListboxClear(lb);
				
				dir_here(lb,sel->name);
				if(strcmp(curvv,"..") == 0) set_lb_cursor(lb,cwdcd);
				strcpy(cwd,sel->name);
				strcpy(cwdcd,sel->name);
				newtEntrySet(l1, sel->name, 1);
				if(sel)
				{
						free(sel->name);
						free(sel);
				}
			} 
			if(sel && S_ISREG(sel->st.st_mode)) // is a directory
			{
				newtEntrySet(l1, sel->name, 1);
			}
		}
		else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b2) 
		{
			if(strlen(enr3) > 0) 
			{
				strcpy(cwdcd,cwd);
				strcat(cwdcd,"/");
				strcat(cwdcd,enr3);
				if(mkdir(cwdcd,0755) == 0) 
				{
					newtListboxClear(lb);
					dir_here(lb,cwd);
					set_lb_cursor(lb,cwdcd);
					newtEntrySet(l2, "", 1);
				}
			}
		}
		else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b1)
		{
			ret=strdup(enr2);
		}
	}
	while (es.reason != es.NEWT_EXIT_COMPONENT || es.u.co == lb || es.u.co == b2);
	
	newtFormDestroy(f);
	newtPopWindow();
	
	return ret;
}
Пример #23
0
/* This is a groovie dialog for showing network info.  Takes a keyvalue list,
 * a colour and a dhcp flag.  Shows the current settings, and rewrites them
 * if necessary.  DHCP flag sets wether to show the dhcp checkbox. */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
	char *defaultdhcphostname)
{
	char *addressresult;
	char *netmaskresult;
	char *dhcphostnameresult;
	char *dhcpforcemturesult;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent addresslabel;
	newtComponent netmasklabel;
	newtComponent dhcphostnamelabel;
	newtComponent dhcpforcemtulabel;
	newtComponent ok, cancel;	
	char message[1000];
	char temp[STRING_SIZE];
	char addressfield[STRING_SIZE];
	char netmaskfield[STRING_SIZE];
	char typefield[STRING_SIZE];
	char dhcphostnamefield[STRING_SIZE];
	char dhcpforcemtufield[STRING_SIZE];
	int error;
	int result = 0;
	char type[STRING_SIZE];
	int startstatictype = 0;
	int startdhcptype = 0;
	int startpppoetype = 0;
		
	/* Build some key strings. */
	sprintf(addressfield, "%s_ADDRESS", colour);
	sprintf(netmaskfield, "%s_NETMASK", colour);
	sprintf(typefield, "%s_TYPE", colour);
	sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
	sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
		
	sprintf(message, _("Interface - %s"), colour);
	newtCenteredWindow(44, (typeflag ? 18 : 12), message);
	
	networkform = newtForm(NULL, NULL, 0);

	sprintf(message, _("Enter the IP address information for the %s interface."), colour);
	header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);
	newtFormAddComponent(networkform, header);

	/* See if we need a dhcp checkbox.  If we do, then we shift the contents
	 * of the window down two rows to make room. */
	if (typeflag)
	{
		strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
		if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
		if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
		if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
		statictyperadio = newtRadiobutton(2, 4, _("Static"), startstatictype, NULL);
		dhcptyperadio = newtRadiobutton(2, 5, _("DHCP"), startdhcptype, statictyperadio);
		pppoetyperadio = newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"),
			startpppoetype, dhcptyperadio);
		newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, 
			pppoetyperadio, NULL);
		newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
		newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
		newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
		dhcphostnamelabel = newtTextbox(2, 8, 18, 1, 0);
		newtTextboxSetText(dhcphostnamelabel, _("DHCP Hostname:"));
		dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0);
		newtTextboxSetText(dhcpforcemtulabel, _("Force DHCP MTU:"));
		strcpy(temp, defaultdhcphostname);
		findkey(kv, dhcphostnamefield, temp);
		dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0);
		strcpy(temp, "");
		findkey(kv, dhcpforcemtufield, temp);
		dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0);
		newtFormAddComponent(networkform, dhcphostnamelabel);
		newtFormAddComponent(networkform, dhcphostnameentry);
		newtFormAddComponent(networkform, dhcpforcemtulabel);
		newtFormAddComponent(networkform, dhcpforcemtuentry);
		if (startdhcptype == 0)
			{
				newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
				newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
			}
	}
	/* Address */
	addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
	newtTextboxSetText(addresslabel, _("IP address:"));
	strcpy(temp, "");
	findkey(kv, addressfield, temp);
	addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
	newtEntrySetFilter(addressentry, ip_input_filter, NULL);
	if (typeflag == 1 && startstatictype == 0)
		newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
	newtFormAddComponent(networkform, addresslabel);
	newtFormAddComponent(networkform, addressentry);
	
	/* Netmask */
	netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
	newtTextboxSetText(netmasklabel, _("Network mask:"));
	strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
	netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
	newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
	if (typeflag == 1 && startstatictype == 0) 
		newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);

	newtFormAddComponent(networkform, netmasklabel);
	newtFormAddComponent(networkform, netmaskentry);

	/* Buttons. */
	ok = newtButton(8, (typeflag ? 14 : 7), _("OK"));
	cancel = newtButton(26, (typeflag ? 14 : 7), _("Cancel"));

	newtFormAddComponents(networkform, ok, cancel, NULL);

	newtRefresh();
	newtDrawForm(networkform);

	do
	{
		error = 0;
		newtFormRun(networkform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */
			strcpy(message, _("The following fields are invalid:"));
			strcat(message, "\n\n");
			
			strcpy(type, "STATIC");
			if (typeflag)
				gettype(type);
			if (strcmp(type, "STATIC") == 0)
			{		
				if (inet_addr(addressresult) == INADDR_NONE)
				{
					strcat(message, _("IP address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(netmaskresult) == INADDR_NONE)
				{
					strcat(message, _("Network mask"));
					strcat(message, "\n");
					error = 1;
				}
			}
			if (strcmp(type, "DHCP") == 0)
			{
				if (!strlen(dhcphostnameresult))
				{
					strcat(message, _("DHCP hostname"));
					strcat(message, "\n");
					error = 1;
				}
			}
			if (error)
				errorbox(message);
			else
			{
				/* No errors!  Set new values, depending on dhcp flag etc. */
				if (typeflag)
				{
					replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
					replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult);
					if (strcmp(type, "STATIC") != 0)
					{
						replacekeyvalue(kv, addressfield, "0.0.0.0");
						replacekeyvalue(kv, netmaskfield, "0.0.0.0");
					}
					else
					{
						replacekeyvalue(kv, addressfield, addressresult);
						replacekeyvalue(kv, netmaskfield, netmaskresult);
					}
					replacekeyvalue(kv, typefield, type);					
				}
				else
				{
					replacekeyvalue(kv, addressfield, addressresult);
					replacekeyvalue(kv, netmaskfield, netmaskresult);
				}
				
				setnetaddress(kv, colour);
				result = 1;
			}
		}
		/* Workaround for a bug that dhcp radiobutton also end the dialog at arm
		*/
		else {
			if (es.u.co != cancel) {
				error = 1;
			}
		}
	}
	while (error);

	newtFormDestroy(networkform);
	newtPopWindow();
		
	return result;
}
Пример #24
0
int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) {
    newtComponent form, okay, cancel, answer, text, accountEntry = NULL;
    newtComponent passwordEntry = NULL, proxyEntry = NULL;
    newtComponent proxyPortEntry = NULL;
    char * account, * password, * proxy, * proxyPort;
    newtGrid buttons, entryGrid, grid;
    char * reflowedText = NULL;
    int width, height;

    if (protocol == URL_METHOD_FTP) {
        reflowedText = newtReflowText(
        _("If you are using non anonymous ftp, enter the account name and "
          "password you wish to use below."),
        47, 5, 5, &width, &height);
    } else {
        reflowedText = newtReflowText(
        _("If you are using a HTTP proxy server "
          "enter the name of the HTTP proxy server to use."),
        47, 5, 5, &width, &height);
    }
    text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP);
    newtTextboxSetText(text, reflowedText);
    free(reflowedText);

    if (protocol == URL_METHOD_FTP) {
        accountEntry = newtEntry(-1, -1, NULL, 24, (const char **) &account, 
                                 NEWT_FLAG_SCROLL);
        passwordEntry = newtEntry(-1, -1, NULL, 24, (const char **) &password, 
                                  NEWT_FLAG_SCROLL | NEWT_FLAG_PASSWORD);
    }
    proxyEntry = newtEntry(-1, -1, ui->proxy, 24, (const char **) &proxy, 
                           NEWT_ENTRY_SCROLL);
    proxyPortEntry = newtEntry(-1, -1, ui->proxyPort, 6, 
                               (const char **) &proxyPort, NEWT_FLAG_SCROLL);

    entryGrid = newtCreateGrid(2, 4);
    if (protocol == URL_METHOD_FTP) {
        newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Account name:")),
                     0, 0, 2, 0, NEWT_ANCHOR_LEFT, 0);
        newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Password:"******"OK"), &okay, _("Back"), &cancel, NULL);

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

    if (protocol == URL_METHOD_FTP) {
        newtGridWrappedWindow(grid, _("Further FTP Setup"));
    } else {
        if (protocol == URL_METHOD_HTTP)
            newtGridWrappedWindow(grid, _("Further HTTP Setup"));
    }

    form = newtForm(NULL, NULL, 0);
    newtGridAddComponentsToForm(grid, form, 1);
    newtGridFree(grid, 1);

    answer = newtRunForm(form);
    if (answer == cancel) {
        newtFormDestroy(form);
        newtPopWindow();
        
        return LOADER_BACK;
    }
 
    if (protocol == URL_METHOD_FTP) {
        if (ui->login) free(ui->login);
        if (strlen(account))
            ui->login = strdup(account);
        else
            ui->login = NULL;
        
        if (ui->password) free(ui->password);
        if (strlen(password))
            ui->password = strdup(password);
        else
            ui->password = NULL;
    }
    
    newtFormDestroy(form);
    newtPopWindow();

    return 0;
}
Пример #25
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);
}