/**
 * File:	include/network/lan/dhcp.ycp
 * Package:	Network configuration
 * Summary:	Network card adresss configuration dialogs
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: dhcp.ycp 13783 2004-02-02 20:16:53Z msvec $
 */

{

textdomain "network";

import "Label";
import "NetworkConfig";
import "Popup";
import "Wizard";

include "network/routines.ycp";

/**
 * Dialog for DHCP client options
 * @return dialog result
 */
define any DHCPDialog() ``{

    ScreenName("lan-dhcp");

    /* DHCP dialog caption */
    string caption = _("DHCP Client Options");

    /* DHCP dialog help 1/8 */
    string help = _("<p>Configure the DHCP client options here.</p>") +

    /* DHCP dialog help 2/8 */
    _("<p><b>Request Broadcast Response</b> causes the DHCP client
to ask the server always to broadcast its responses. You may need this,
for example, if your machine is a mobile client moving between different
networks.</p>") +

    /* DHCP dialog help 3/8 */
    _("<p>The <b>DHCP Client Identifier</b>, if left empty, defaults to
the hardware address of the network interface. It must be different for each
DHCP client on a single network. Therefore, specify a unique free-form
identifier here if you have several (virtual) machines using the same
network interface and thus the same hardware address.</p>") +

    /* DHCP dialog help 4/8 */
    _("<p>The <b>Host Name to Send</b> specifies a string used for the
host name option field when dhcpcd sends DHCP messages. Some DHCP servers
update name server entries according to this host name (dynamic DNS).

Also, some DHCP servers require the <b>Host Name to Send</b> option field to
contain a specific string in the DHCP messages from clients. Leave <i>AUTO</i>
to send the current host name. Leave empty not to send a host name.</p>");

    boolean dhclient_broadcast = false;
    if(issubstring(NetworkConfig::DHCP["DHCLIENT_ADDITIONAL_OPTIONS"]:"", "-B"))
	dhclient_broadcast = true;

    /* Details dialog contents */
    term contents = `HBox(
	`HSpacing(6),
	/* Frame label */
	`Frame(_("DHCP Client Options"), `HBox(`HSpacing(2), `VBox(
	    `VSpacing(1),
	    /* CheckBox label */
	    `Left(`CheckBox(`id(`broadcast), _("Request Broad&cast Response"), dhclient_broadcast == true)),
	    `VSpacing(0.5),
	    /* TextEntry label */
	    `Left(`TextEntry(`id(`clientid), _("DHCP Client &Identifier"), NetworkConfig::DHCP["DHCLIENT_CLIENT_ID"]:"")),
	    `VSpacing(0.5),
	    /* TextEntry label */
	    `Left(`TextEntry(`id(`hostname), _("&Host Name to Send"), NetworkConfig::DHCP["DHCLIENT_HOSTNAME_OPTION"]:"AUTO")),
	    `VSpacing(1)
	    ), `HSpacing(2))),
	`HSpacing(6)
    );

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::OKButton());

    any ret = nil;
    while(true) {

	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	/* back */
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* check* */
	    break;
	}
	else {
	    y2error("Unexpected retcode: %1", ret);
	    continue;
	}

    }

    /* update the configuration */
    if(ret == `next) {
	NetworkConfig::DHCP["DHCLIENT_CLIENT_ID"] = UI::QueryWidget(`id(`clientid), `Value);
	NetworkConfig::DHCP["DHCLIENT_HOSTNAME_OPTION"] = UI::QueryWidget(`id(`hostname), `Value);
	dhclient_broadcast = UI::QueryWidget(`id(`broadcast), `Value) == true;

	/* DHCP data */
	string options = NetworkConfig::DHCP["DHCLIENT_ADDITIONAL_OPTIONS"]:"";
	if(options == nil) options = "";
	if(dhclient_broadcast && !issubstring(options, "-B")) {
	    NetworkConfig::DHCP["DHCLIENT_ADDITIONAL_OPTIONS"] = options + " -B";
	}
	else if(!dhclient_broadcast && issubstring(options, "-B")) {
	    NetworkConfig::DHCP["DHCLIENT_ADDITIONAL_OPTIONS"] = regexpsub(options, "(.*)-B(.*)", "\\1\\2");
	}
    }

    return ret;
}

/* EOF */
}
