#!/usr/bin/perl

# DrakNet

# Copyright (C) 1999 MandrakeSoft (damien@mandrakesoft.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use lib qw(/usr/lib/libDrakX);

use interactive;
use standalone;
use netconnect;
use c;

my $xpm_path="/usr/share/libDrakX/pixmaps";
$::isEmbedded = ($::XID, $::CCPID) = "@ARGV" =~ /--embedded (\w+) (\w+)/;
$::isWizard = "@ARGV" =~ /--wizard/;
$::isEmbedded or $::isWizard=1;
$::Wizard_pix_up = "wiz_draknet.png";

local $_ = join '', @ARGV;

#/-h/ and die "usage: draknet[--xf3] [--beginner] [--expert] [--auto] [--noauto] [--skiptest] [--testing]\n";

my $netcnx = {};
my $netc = {};
my $intf = {};
my @conx_type = ('modem', 'isdn_internal', 'isdn_external', 'adsl', 'cable', 'lan' );

#$::wizard_xpm = "/usr/share/pixmaps/internet.xpm";

my $in = vnew interactive('su');

$::isEmbedded && ref($in) =~ /gtk/ or goto dd;
require Gtk;
init Gtk;
my $expert_mode=0;
netconnect::read_net_conf('', $netcnx, $netc);
any::setup_thiskind_backend('net', undef);
my @all_cards = netconnect::conf_network_card_backend ('', $netc, $intf, undef, undef, undef, undef);
netconnect::load_conf('', $netcnx, $netc, $intf);

my $window1 = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
$window1->signal_connect ( delete_event => sub { Gtk->exit(0); });
$window1->set_position(1);
$window1->set_title(_("Network configuration (%d adapters)", @all_cards));
$window1->border_width(10);
$::isEmbedded or $window1->set_usize(500, 400);
my $vbox1 = new Gtk::VBox(0,0);
$window1->add($vbox1);
my $hbox1 = new Gtk::HBox(0,0);
$vbox1->pack_start($hbox1,1,1,0);
$hbox1->pack_start(new Gtk::Label(_("Profile: ")),0,0,0);

my $combo1 = new Gtk::Combo;
$combo1->set_popdown_strings (netconnect::get_profiles() );
my $old_profile=$netcnx->{PROFILE};
$combo1->entry->set_text($netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default");
$combo1->entry->set_editable(0);
$hbox1->pack_start($combo1,0,0,0);
my $button_del = new Gtk::Button(_("Del profile..."));
$button_del->signal_connect( clicked => sub {
				 my $dialog = new Gtk::Dialog();
				 $dialog->set_position(1);
				 $dialog->vbox->set_border_width(10);
				 $dialog->vbox->pack_start(new Gtk::Label(_("Profile to delete:")),1,1,0);
				 my $combo_dialog = new Gtk::Combo;
				 $combo_dialog->set_popdown_strings ( grep { ! /default/ } netconnect::get_profiles() );
				 $combo_dialog->entry->set_editable(0);
				 $dialog->vbox->pack_start($combo_dialog,1,1,0);
				 my $bbox_dialog = new Gtk::HButtonBox;
				 $dialog->action_area->add($bbox_dialog);
				 $bbox_dialog->set_layout(-end);
				 my $button_ok = new Gtk::Button _("OK");
				 $button_ok->signal_connect ( clicked => sub {
								  netconnect::del_profile('', $netcnx, $combo_dialog->entry->get_text());
								  $netcnx->{PROFILE} eq $combo_dialog->entry->get_text() and $netcnx->{PROFILE}="default";
								  Gtk->main_quit();
							      });
				 $bbox_dialog->add($button_ok );
				 my $button_cancel = new Gtk::Button _("Cancel");
				 $button_cancel->signal_connect ( clicked => sub { Gtk->main_quit(); });
				 $bbox_dialog->add($button_cancel);
				 $dialog->show_all;
				 $dialog->set_modal(1);
				 Gtk->main();
				 $dialog->destroy;
				 $combo1->entry->set_text((-e "/etc/sysconfig/network-scripts/draknet_conf." . $combo1->entry->get_text) ? $combo1->entry->get_text : "default");
				 $combo1->set_popdown_strings(netconnect::get_profiles());
				 apply();
			     });
$hbox1->pack_start($button_del,0,0,5);
$button_del->set_sensitive(netconnect::get_profiles() > 1);
my $button_new = new Gtk::Button(_("New profile..."));
$button_new->signal_connect( clicked => sub {
				 my $dialog = new Gtk::Dialog();
				 $dialog->set_position(1);
				 $dialog->vbox->set_border_width(10);
				 $dialog->vbox->pack_start(new Gtk::Label(_("Name of the profile to create:")),1,1,0);
				 my $entry_dialog = new Gtk::Entry;
				 $dialog->vbox->pack_start($entry_dialog,1,1,0);
				 my $bbox_dialog = new Gtk::HButtonBox;
				 $dialog->action_area->add($bbox_dialog);
				 $bbox_dialog->set_layout(-end);
				 my $button_ok = new Gtk::Button _("OK");
				 $button_ok->signal_connect ( clicked => sub {
								  netconnect::add_profile('', $netcnx, $entry_dialog->get_text());
								  $netcnx->{PROFILE} = $entry_dialog->get_text();
								  Gtk->main_quit();
							      });
				 $bbox_dialog->add($button_ok );
				 my $button_cancel = new Gtk::Button _("Cancel");
				 $button_cancel->signal_connect ( clicked => sub { Gtk->main_quit(); });
				 $bbox_dialog->add($button_cancel);
				 $dialog->show_all;
				 $dialog->set_modal(1);
				 Gtk->main();
				 $dialog->destroy;
				 $combo1->entry->set_text((-e "/etc/sysconfig/network-scripts/draknet_conf." . $netcnx->{PROFILE}) ? $netcnx->{PROFILE} : "default");
				 $combo1->set_popdown_strings(netconnect::get_profiles());
});
$hbox1->pack_start($button_new,0,0,5);
my $hbox2 = new Gtk::HBox(0,0);
$vbox1->pack_start($hbox2,1,1,0);
$hbox2->pack_start(new Gtk::Label(_("Hostname: ")),0,0,0);
chop (my $hostname = `hostname`);
my $label_host = new Gtk::Label($hostname);
$hbox2->pack_start($label_host,0,0,0);

$vbox1->pack_start(new Gtk::HSeparator,1,1,5);

my $frame1 = new Gtk::Frame (_("Internet access"));
$vbox1->pack_start($frame1,1,1,0);
my $vbox_frame1 = new Gtk::VBox(0,0);
$vbox_frame1->set_border_width(5);
$frame1->add($vbox_frame1);
my $table1 = new Gtk::Table (3,3, 0);
$table1->set_border_width(5);
$table1->set_row_spacings(5);
$table1->set_col_spacings(5);
#$table1->border_width(10);
$vbox_frame1->pack_start($table1,1,1,0);
#attach (table, child, left_attach, right_attach, top_attach, bottom_attach, xoptions, yoptions, xpadding, ypadding)
#$table->attach($button[0], 0, 1, 0, 1, {expand=>1,fill=>1}, {expand=>1,fill=>1},0,0);
$table1->attach(new Gtk::Label(_("Type:")), 0, 1, 0, 1, 'fill', 'fill',0,0);
my $label4 = new Gtk::Label($netcnx->{type});
$table1->attach($label4, 1, 2, 0, 1, 'fill', 'fill',0,0);
my $label5 = new Gtk::Label($netcnx->{type} eq 'lan' ? _("Gateway:") : _("Interface:"));
$table1->attach($label5, 0, 1, 1, 2, 'fill', 'fill',0,0);
my $label6 = new Gtk::Label($netcnx->{type} eq 'lan' ? $netc->{GATEWAY} : $netc->{NET_INTERFACE});
$table1->attach($label6, 1, 2, 1, 2, 'fill', 'fill',0,0);
my $c=netconnect::connected('',$netc);
my $label7 = new Gtk::Label(_("Status:"));
$table1->attach($label7, 0, 1, 2, 3, 'fill', 'fill',0,0);
my $label8 = new Gtk::Label($c ? _("Connected") : _("Not connected"));
$table1->attach($label8, 1, 2, 2, 3, 'fill', 'fill',0,0);

my $button2 = new Gtk::Button($c ? _("Disconnect...") : _("Connect..."));
$button2->signal_connect (clicked => sub {
			      if (!netconnect::connected('', $netc)) {
				  my $up;
				  {
				      my $w = $in->wait_message('', _("Openning your connection..."), 1);
				      netconnect::connect_backend($prefix);
				      sleep 5;
				      $up=netconnect::connected($prefix, $netc);
				  }
				  $in->ask_warn('', $up ? _("The system is now connected to Internet.") : _("The system doesn't seem to be connected to internet.
Try to reconfigure your connection.") );
			      } else {
				  my $up;
				      {
					  my $w = $in->wait_message('', _("Closing your connection..."), 1);
					  netconnect::disconnect_backend($prefix);
					  sleep 5;
					  $up=netconnect::connected($prefix, $netc);
				      }
				  $in->ask_warn('', $up ? _("The connection is not closed. Try to do it manually by running /etc/sysconfig/network-scripts/net_cnx_down in root.") : _("The system is now disconnected.") );
			      }
			      update();
			  });
$table1->attach($button2, 2, 3, 2, 3, 'fill', 'fill',0,0);

#$table1->attach($button1, 2, 3, 1, 2, 'fill', 'fill',0,0);

my $hbox_frame1_button = new Gtk::HBox(0,0);
my $button1 = new Gtk::Button(_("Configure Internet Access..."));
$button1->signal_connect( clicked => [ \&configure_net, '', $netcnx, $netc, $intf]);
$hbox_frame1_button->pack_start($button1, 0, 0, 0);
$vbox_frame1->pack_start($hbox_frame1_button,0,0,0);

$vbox1->pack_start(new Gtk::HSeparator,1,1,5);

my $frame2 = new Gtk::Frame (_("LAN configuration"));
$vbox1->pack_start($frame2,1,1,0);
my $vbox2 = new Gtk::VBox(0,0);
$vbox2->set_border_width(5);
$frame2->add($vbox2);
my $clist1 = new_with_titles Gtk::CList(_("Adapter"), _("Interface"), _("IP address"), _("Protocol"), _("Driver"));
$clist1->set_column_auto_resize($_,1) foreach (0..4);
$clist1->column_titles_passive();
$clist1->set_shadow_type('etched_out');
$vbox2->pack_start($clist1, 0, 0, 5);
#$scrolled1->add_with_viewport($table2);

foreach (0..$#all_cards) {
$clist1->append($_+1, "eth$_", $intf->{"eth$_"}{IPADDR}, $intf->{"eth$_"}{BOOTPROTO}, $all_cards[$_]->[1]);
$clist1->set_selectable($_, 0);
}

my $hbox3 = new Gtk::HBox(0,0);
my $button3 = new Gtk::Button(_("Configure Local Area Network..."));
$button3->signal_connect( clicked => [ \&configure_lan, '', $netcnx, $netc, $intf]);
$hbox3->pack_start($button3, 0, 0, 0);
$vbox2->pack_start($hbox3, 0, 0, 0);

$vbox1->pack_start(new Gtk::HSeparator,1,1,5);

my $bbox0 = new Gtk::HButtonBox;
$vbox1->pack_start($bbox0,0,0,0);
$bbox0->set_layout(-end);


my $button_wizard = new Gtk::Button _("Configure...");
$button_wizard->signal_connect ( clicked => sub {
				     $::isWizard = 1;
				     system("draknet --wizard");
# netconnect::intro('', $netcnx, $in, sub { $in->standalone::pkgs_install(@_) });
				     $combo1->entry->set_text((-e "/etc/sysconfig/network-scripts/draknet_conf." . $combo1->entry->get_text) ? $combo1->entry->get_text : "default");
				     netconnect::load_conf('', $netcnx, $netc, $intf);
				     update();
				 });
$bbox0->add($button_wizard );

my $button_expert = new Gtk::Button _("Expert Mode");
$button_expert->signal_connect ( clicked => sub {
				     foreach($button1, $button3) { $expert_mode ? $_->hide() : $_->show() }
				     $button_expert->child->set($expert_mode ? _("Expert Mode") : _("Normal Mode"));
				     $expert_mode = !$expert_mode;
				 });
$bbox0->add($button_expert );

$vbox1->pack_start(new Gtk::HSeparator,1,1,5);

my $bbox1 = new Gtk::HButtonBox;
$vbox1->pack_start($bbox1,0,0,0);
$bbox1->set_layout(-end);
#$bbox1->set_border_width(5);

my $button_ok = new Gtk::Button _("OK");
$button_ok->signal_connect ( clicked => sub {
				 my $dialog = new Gtk::Dialog();
				 $dialog->set_position(1);
				 $dialog->vbox->set_border_width(10);
				 my $label = new Gtk::Label(_("Please Wait... Applying the configuration"));
				 $dialog->vbox->pack_start($label,1,1,20);
				 $dialog->show_all;
				 Gtk->main_iteration while Gtk->events_pending;
				 apply();
				 system("$prefix/etc/rc.d/init.d/network $_") foreach "stop", "start";
				 $dialog->destroy;
				 update();
				 quit_global();
			     });
$bbox1->add($button_ok);
my $button_apply = new Gtk::Button _("Apply");
$button_apply->signal_connect ( clicked => sub {
				 apply();
			     });
$button_apply->set_sensitive(0);
$bbox1->add($button_apply);
my $button_cancel = new Gtk::Button _("Cancel");
$button_cancel->signal_connect ( clicked => sub {
				     $combo1->entry->set_text($old_profile);
				     update();
				     quit_global();
				 });
$bbox1->add($button_cancel);
$combo1->entry->signal_connect( 'changed', sub {
				    netconnect::set_profile('', $netcnx, $combo1->entry->get_text());
				    netconnect::load_conf('', $netcnx, $netc, $intf);
				    $netcnx->{$_}=$netc->{$_} foreach qw(NET_DEVICE NET_INTERFACE);
				    netconnect::set_net_conf('', $netcnx, $netc, $intf);
				    update();
				    $button_apply->set_sensitive(1);
				});

$window1->show_all();
$_->hide foreach ($button1, $button3);
Gtk->main_iteration while Gtk->events_pending;
$::isEmbedded and kill USR2, $::CCPID;
Gtk->main;
Gtk->exit(0);

dd:
netconnect::intro('', $netcnx, $in, sub { $in->standalone::pkgs_install(@_) });
$in->exit(0);


sub apply {

    $old_profile=$netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default";
    netconnect::save_conf('', $netcnx, $netc, $intf);
    network::configureNetwork2($prefix, $netc, $intf, \&standalone::pkgs_install);
    $netcnx->{type} =~ /adsl/ or system("/sbin/chkconfig --del adsl 2> /dev/null");
    $button_apply->set_sensitive(0);
}

sub update {
    chop (my $h = `hostname`);
    $label_host->set ($h);
    $label4->set($netcnx->{type});
    $label5->set($netcnx->{type} eq 'lan' ? _("Gateway:") : _("Interface:"));
    $label6->set($netcnx->{type} eq 'lan' ? $netc->{GATEWAY} : $netc->{NET_INTERFACE});
    my $c = netconnect::connected('', $netc);
    $label8->set($c ? _("Connected") : _("Not connected"));
    $button2->child->set($c ? _("Disconnect...") : _("Connect..."));
    $clist1->freeze();
    $clist1->clear();
    foreach (0..$#all_cards) {
	$clist1->append($_+1, "eth$_", $intf->{"eth$_"}{IPADDR}, $intf->{"eth$_"}{BOOTPROTO}, $all_cards[$_]->[1]);
	$clist1->set_selectable($_, 0);
    }
    $clist1->thaw();
    $button_del->set_sensitive(netconnect::get_profiles() > 1);
}

sub quit_global {
    $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0);
}

sub configure_lan {
    my (undef, $prefix, $netcnx, $netc, $intf) = @_;
    my $window = new Gtk::Window -toplevel;
    my @infos;
    my @conf_data;
    $window->set_policy (1, 1, 1);
    $window->signal_connect ( delete_event => sub { Gtk->main_quit; });
    $window->set_position(1);
    $window->set_title(_("LAN configuration"));
    $window->border_width(10);
    my $vbox1 = new Gtk::VBox(0,0);
    $window->add($vbox1);
    $vbox1->pack_start(new Gtk::Label(_("LAN Configuration")),0,1,0);
    my $notebook = new Gtk::Notebook;
    $vbox1->pack_start($notebook,0,1,0);
    $notebook->set_sensitive($netc->{NETWORKING} eq "yes");
    my @eth_data;
    foreach (0..$#all_cards) {
	my $vbox_local=new Gtk::VBox(0,0);
	$vbox_local->set_border_width(10);
	$vbox_local->pack_start(new Gtk::Label( _("Adapter %s: %s", $_+1 , "eth$_")),1,1,0);
	#	Eth${_}Hostname=$netc->{HOSTNAME}
	#       Eth${_}HostAlias=" . do { $netc->{HOSTNAME} =~ /([^\.]*)\./; $1 } . "
	#	Eth${_}Driver=$all_cards[$_]->[1]
        @conf_data = ([_("IP address"), \$intf->{"eth$_"}->{IPADDR}],
			 [_("Netmask"), \$intf->{"eth$_"}{NETMASK}],
			 [_("Boot Protocol"), \$intf->{"eth$_"}{BOOTPROTO}, ["static", "dhcp", "bootp"]],
			 [_("Started on boot"), \$intf->{"eth$_"}{ONBOOT} , ["yes", "no"]],
			 [_("DHCP client"), \$netcnx->{dhcp_client}]
			);
	my $i=0;
	foreach (@conf_data) {
	    $infos[2*$i]=new Gtk::HBox(0,0);
	    my $l=new Gtk::Label($_->[0]);
	    $l->set_justify('left');
	    $infos[2*$i]->pack_start($l,1,1,0);
	    $vbox_local->pack_start($infos[2*$i],0,0,0);
	    if (defined $_->[2]) {
		my $c=new Gtk::Combo();
		$c->set_popdown_strings(@{$_->[2]});
		$infos[2*$i+1]=$c->entry;
		$infos[2*$i+1]->set_editable(0);
		$infos[2*$i]->pack_start($c,0,0,0);
	    } else {
		$infos[2*$i+1]=new Gtk::Entry();
		$infos[2*$i]->pack_start($infos[2*$i+1],0,0,0);
	    }
	    $infos[2*$i+1]->set_text(${$_->[1]});
	    $i++;
	}
	#	$clist1->append($_+1, "eth$_", $intf->{"eth$_"}{IPADDR}, $intf->{"eth$_"}{BOOTPROTO}, $all_cards[$_]->[1]);
	#	$clist1->set_selectable($_, 0);
	my $hbox_local = new Gtk::HBox(0,0);
	my $pix = my_gtk::gtkxpm ("/usr/share/libDrakX/pixmaps/eth_card_mini.xpm");
	$hbox_local->pack_start($pix,0,0,0);
	$hbox_local->pack_start(new Gtk::Label("eth$_"),0,0,0);
	$hbox_local->show_all;
	$notebook->append_page($vbox_local, $hbox_local);
    }
    my $bbox1 = new Gtk::HButtonBox;
    $vbox1->pack_start($bbox1,0,0,10);
    $bbox1->set_layout(-end);
    my $old_networking = $netc->{NETWORKING};
    my $button_able = new Gtk::Button $netc->{NETWORKING} eq "yes" ? _("Disable") : _("Enable");
    $button_able->signal_connect ( clicked => sub {
				       $netc->{NETWORKING} eq "yes" ? ($netc->{NETWORKING} = "no") : ($netc->{NETWORKING} = "yes");
				       $notebook->set_sensitive($netc->{NETWORKING} eq "yes");
				       $button_able->child->set($netc->{NETWORKING} eq "yes" ? _("Disable") : _("Enable"));
				   } );
    $bbox1->add($button_able);
    my $button_ok = new Gtk::Button( _("OK") );
    $button_ok->signal_connect ( clicked => sub {
				     my $i=0;
				     foreach (@conf_data) {
					 ${$_->[1]}=$infos[2*$i+1]->get_text();
					 $i++;
				     }
				     update();
				     $button_apply->set_sensitive(1);
				     $window->destroy(); Gtk->main_quit;
				 });
    $bbox1->add($button_ok);
    my $button_cancel = new Gtk::Button( _("Cancel") );
    $button_cancel->signal_connect ( clicked => sub { $netc->{NETWORKING}=$old_networking; $window->destroy(); Gtk->main_quit });
    $bbox1->add($button_cancel);

    $window->set_modal(1);
    $window->show_all();
    $intf->{"eth$_"}{BOOTPROTO} eq dhcp or $infos[8]->hide;
    $window->set_position('center_always');
    Gtk->main;
}


sub configure_net {
    my (undef, $prefix, $netcnx, $netc, $intf) = @_;
    my $cnx={};
    my @infos;
    $cnx=$netcnx->{$netcnx->{type}};
    my $auto_detect={};
    my $window = new Gtk::Window -toplevel;
    $window->set_policy (1, 1, 1);
    $window->signal_connect ( delete_event => sub { Gtk->main_quit; });
    $window->set_position(1);
    $window->set_title(_("Internet connection configuration"));
    $window->border_width(10);
    my $vbox1 = new Gtk::VBox(0,0);
    $window->add($vbox1);
    $vbox1->pack_start(new Gtk::Label(_("Internet Connection Configuration")),0,1,0);

    $vbox1->pack_start(new Gtk::HSeparator,0,0,5);
    my $table1 = new Gtk::Table (2, 4, 0);
    $table1->set_row_spacings(5);
    $table1->set_col_spacings(5);
    $vbox1->pack_start($table1,0,0,0);
    $table1->attach(new Gtk::Label(_("Profile: ")), 0, 1, 0, 1, 'fill', 'fill',0,0);
    $table1->attach(new Gtk::Label(_($netcnx->{PROFILE})), 1, 2, 0, 1, 'fill', 'fill',0,0);
    $table1->attach(new Gtk::Label(_("Connection type: ")), 0, 1, 1, 2, 'fill', 'fill',0,0);
    $table1->attach(new Gtk::Label(_($netcnx->{type})), 1, 2, 1, 2, 'fill', 'fill',0,0);
#    my $button1 = new Gtk::Button(_("Reconfigure using wizard..."));
#    $table1->attach($button1, 2, 4, 0, 2, 'fill', 'fill',0,0);
    $vbox1->pack_start(new Gtk::HSeparator,0,0,5);

    my $frame1 = new Gtk::Frame (_("Parameters"));
    $vbox1->pack_start($frame1,1,1,0);
    my $vbox2 = new Gtk::VBox(0,0);
    $frame1->add($vbox2);
    my $i=0;
    my @conf_data = ([_("Card IRQ"), \$cnx->{irq}],
		     [_("Card mem (DMA)"), \$cnx->{mem}],
		     [_("Card IO"), \$cnx->{io}],
		     [_("Card IO_0"), \$cnx->{io0} ],
		     [_("Card IO_1"), \$cnx->{io1}],
		     [_("Your personal phone number"), \$cnx->{phone_in}],
		     [_("Provider name (ex provider.net)"), \$netc->{DOMAINNAME2}],
		     [_("Provider phone number"), \$cnx->{phone_out}],
		     [_("Provider dns 1 (optional)"), \$netc->{dnsServer2}],
		     [_("Provider dns 2 (optional)"), \$netc->{dnsServer3}],
		     [_("Account Login (user name)"), \$cnx->{login}],
		     [_("Account Password"), \$cnx->{passwd}],
		     [_("Dialing mode"), $cnx->{dialing_mode}, [ "auto", "manual"] ],
		     [_("Gateway"), \$netc->{GATEWAY}],
		     [_("Connection name"), \$cnx->{connection} ],
		     [_("Phone number"), \$cnx->{phone} ],
		     [_("Login ID"), \$cnx->{login} ],
		     [_("Password"), \$cnx->{passwd} ],
		     [_("Authentication"), \$cnx->{auth}, [ _("PAP"), _("Terminal-based"), _("Script-based") ] ],
		     [_("Domain name"), \$cnx->{domain} ],
		     [_("First DNS Server (optional)"), \$cnx->{dns1} ],
		     [_("Second DNS Server (optional)"), \$cnx->{dns2} ],
		     [_("Ethernet Card"), \$netc->{NET_DEVICE}, [ 'eth0', 'eth1', 'eth2', 'eth3', 'eth4', 'eth5','eth6', 'eth7', 'eth8', 'eth9' ]],
		     [_("DHCP Client"), \$netcnx->{dhcp_client}, ["dhcpcd", "dhcpxd", "dhcp-client"] ]
);
    foreach (@conf_data) {
	$infos[2*$i]=new Gtk::HBox(0,0);
	my $l=new Gtk::Label($_->[0]);
	$l->set_justify('left');
	$infos[2*$i]->pack_start($l,1,1,0);
	$vbox2->pack_start($infos[2*$i],0,0,0);
  	if (defined $_->[2]) {
	    my $c=new Gtk::Combo();
	    $c->set_popdown_strings(@{$_->[2]});
	    $infos[2*$i+1]=$c->entry;
	    $infos[2*$i+1]->set_editable(0);
	    $infos[2*$i]->pack_start($c,0,0,0);
	} else {
	    $infos[2*$i+1]=new Gtk::Entry();
	    $infos[2*$i]->pack_start($infos[2*$i+1],0,0,0);
	}
	$infos[2*$i+1]->set_text(${$_->[1]});
  	$i++;
    }
    my @mask;
@mask=(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) if $netcnx->{type}eq'lan';
@mask=(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) if $netcnx->{type}eq'isdn_internal' && $cnx->{card_type} eq 'pci';
@mask=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) if $netcnx->{type}eq'isdn_internal' && $cnx->{card_type} ne 'pci';
@mask=(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0) if ($netcnx->{type}eq'modem'||$netcnx->{type} eq 'isdn_external');
@mask=(0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0) if $netcnx->{type} =~ 'adsl';
@mask=(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1) if $netcnx->{type} eq 'cable';
    $vbox1->pack_start(new Gtk::HSeparator,0,0,5);


    my $bbox1 = new Gtk::HButtonBox;
    $vbox1->pack_start($bbox1,0,0,0);
    $bbox1->set_layout(-end);
    my $button_ok = new Gtk::Button _("OK");
    $button_ok->signal_connect ( clicked => sub {
				     $i=0;
				     foreach (@mask) {
					 if ($_) {
					     ${$conf_data[$i]->[1]}=$infos[2*$i+1]->get_text();
					 }
					 $i++;
				     }
				     update();
				     $button_apply->set_sensitive(1);
				     $window->destroy(); Gtk->main_quit;
				 });
    $bbox1->add($button_ok);
    my $button_cancel = new Gtk::Button _("Cancel");
    $button_cancel->signal_connect ( clicked => sub { $window->destroy(); Gtk->main_quit });
    $bbox1->add($button_cancel);

    $window->set_modal(1);
    $window->show_all();
    $i=0;
    foreach (@mask) {
	if ($_) { $infos[2*$i]->show }
	else { $infos[2*$i]->hide; }
	$i++;
    }
    $window->set_position('center_always');
    Gtk->main;
}