#!/usr/bin/perl # DrakConnect # Copyright (C) 1999-2002 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 standalone; #- warning, standalone must be loaded very first, for 'explanations' use interactive; use common; use network::netconnect; use network::ethernet; use network::tools; use network; use c; use MDK::Common; use any; use network::isdn; use network::adsl; use MDK::Common::Globals "network", qw($in $prefix $disconnect_file $connect_prog $connect_file $disconnect_file); my $xpm_path = "/usr/share/libDrakX/pixmaps"; $::isWizard = "@ARGV" =~ /--wizard/; $::expert = "@ARGV" =~ /--expert/; local $_ = join '', @ARGV; #/-h/ and die "usage: drakconnect[--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 = 'interactive'->vnew('su', 'network'); !$::isEmbedded && $in->isa('interactive::gtk') and $::isWizard = 1; $::Wizard_pix_up = "wiz_drakconnect.png"; $::Wizard_title = "Network & Internet Configuration"; MDK::Common::Globals::init( in => $in, prefix => '', connect_file => "/etc/sysconfig/network-scripts/net_cnx_up", disconnect_file => "/etc/sysconfig/network-scripts/net_cnx_down", connect_prog => "/etc/sysconfig/network-scripts/net_cnx_pg" ); $::isEmbedded && ref($in) =~ /gtk/ or goto dd; require Gtk; init Gtk; require my_gtk; import my_gtk qw(:helpers :wrappers); my $expert_mode = 0; network::netconnect::read_net_conf('', $netcnx, $netc); any::load_category_no_message('net', undef); my @all_cards = network::ethernet::conf_network_card_backend ($netc, $intf, undef, undef, undef, undef); network::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,10); $window1->add($vbox1); my $hbox1 = new Gtk::HBox(0,0); $vbox1->pack_start($hbox1,0,0,0); $hbox1->pack_start(new Gtk::Label(_("Profile: ")),0,0,0); my $combo1 = new Gtk::Combo; $combo1->set_popdown_strings (network::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->signal_connect (delete_event => sub { Gtk->main_quit() }); $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/ } network::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 { network::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/drakconnect_conf." . $combo1->entry->get_text) ? $combo1->entry->get_text : "default"); $combo1->set_popdown_strings(network::netconnect::get_profiles()); apply(); }); $hbox1->pack_start($button_del,0,0,5); $button_del->set_sensitive(network::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->signal_connect (delete_event => sub { Gtk->main_quit() }); $dialog->vbox->pack_start(new Gtk::Label(_("Name of the profile to create (the new profile is created as a copy of the current one) :")),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 { network::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/drakconnect_conf." . $netcnx->{PROFILE}) ? $netcnx->{PROFILE} : "default"); $combo1->set_popdown_strings(network::netconnect::get_profiles()); }); $hbox1->pack_start($button_new,0,0,5); my $hbox2 = new Gtk::HBox(0,0); $vbox1->pack_start($hbox2,0,0,0); $hbox2->pack_start(new Gtk::Label(_("Hostname: ")),0,0,0); my $hostname = chomp_(`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} : $netcnx->{NET_INTERFACE}); $table1->attach($label6, 1, 2, 1, 2, 'fill', 'fill',0,0); my $isconnected = -1; #-sub connected_local { #- print "in connected local\n"; #- my $w = $in->wait_message('', _("Testing your connection..."), 1); #- Gtk->main_iteration while Gtk->events_pending; #- $isconnected = connected(); #-} my $label7 = new Gtk::Label(_("Status:")); $table1->attach($label7, 0, 1, 2, 3, 'fill', 'fill',0,0); my $label8 = new Gtk::Label(_("Testing your connection...")); $table1->attach($label8, 1, 2, 2, 3, 'fill', 'fill',0,0); my $warning_label1 = new Gtk::Label(""); $vbox_frame1->pack_start($warning_label1,0,0,0); my $button2 = new Gtk::Button(_("Wait please")); $button2->set_sensitive(0); $button2->signal_connect(clicked => sub { if (!$isconnected && cat_($connect_prog) =~ m|/usr/bin/kppp| && -e '/usr/bin/kppp') { run_program::rooted($prefix, "/usr/bin/kppp &"); } elsif (!$isconnected) { connect_backend(); } else { disconnect_backend(); } update2(); }); $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("", _("Interface"), _("IP address"), _("Protocol"), _("Driver"), _("State")); $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); my $ip_regexp = qr/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; build_clist(); 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,0,0,5); my $bbox0 = new Gtk::HButtonBox; $vbox1->pack_start($bbox0,0,0,0); $bbox0->set_layout(-end); $bbox0->add(new Gtk::Label(_("Click here to launch the wizard ->"))); my $button_wizard = new Gtk::Button _("Wizard..."); $button_wizard->signal_connect(clicked => sub { $::isWizard = 1; system("drakconnect --wizard"); # netconnect::intro('', $netcnx, $in); $combo1->entry->set_text((-e "/etc/sysconfig/network-scripts/drakconnect_conf." . $combo1->entry->get_text) ? $combo1->entry->get_text : "default"); network::netconnect::load_conf($netcnx, $netc, $intf); update(); }); $bbox0->add($button_wizard); $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); #$bbox1->set_border_width(5); 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; }); $bbox1->add($button_expert); 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); 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->signal_connect (delete_event => sub { Gtk->main_quit() }); $dialog->vbox->pack_start($label,1,1,20); $dialog->show_all; Gtk->main_iteration while Gtk->events_pending; apply(); $dialog->destroy; update(); quit_global(); }); $bbox1->add($button_ok); $combo1->entry->signal_connect('changed', sub { # connected() and disconnect_backend(); network::netconnect::set_profile($netcnx, $combo1->entry->get_text()); network::netconnect::load_conf($netcnx, $netc, $intf); $netcnx->{$_} = $netc->{$_} foreach qw(NET_DEVICE NET_INTERFACE); network::netconnect::set_net_conf($netcnx, $netc); 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; my $tag = Gtk->timeout_add(4000, \&update2); Gtk->main; Gtk->exit(0); dd: network::netconnect::intro('', $netcnx, $in); $in->exit(0); sub build_clist { foreach my $i (0..$#all_cards) { my $ip; if (-e "/sbin/ifconfig") { local $_ = `LC_ALL=C LANG=C LANGUAGE=C LC_MESSAGES=C /sbin/ifconfig "eth$i"`; /inet addr\:$ip_regexp/; $ip = if_($1 && $2 && $3, "$1.$2.$3.$4"); $_ = `LC_ALL=C LANG=C LANGUAGE=C LC_MESSAGES=C /sbin/ifconfig`; $state = /eth$i/ ? "up" : "down"; } else { $ip = $intf->{"eth$_"}{IPADDR}; $state = "n/a" } $clist1->append("", "eth$i", $ip , $intf->{"eth$i"}{BOOTPROTO}, $all_cards[$i]->[1], $state); $clist1->set_pixmap ($i, 0, gtkcreate_png("eth_card_mini2.png")); $clist1->set_selectable($i, 0); } } sub apply { $old_profile = $netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default"; network::netconnect::save_conf($netcnx, $netc, $intf); $netcnx->{type} eq 'modem' and any::pppConfig($in, $netcnx->{$netcnx->{type}}, ''); $netcnx->{type} eq 'isdn_internal' and network::isdn::isdn_write_config_backend($netcnx->{$netcnx->{type}}, 1, $netc, $netcnx); #$light $netcnx->{type} eq 'isdn_external' and any::pppConfig($in, $netcnx->{$netcnx->{type}}, ''); my $a = $netcnx->{type}; $a =~ s/adsl_//; $netcnx->{type} =~ 'adsl' and network::adsl::adsl_conf_backend($netcnx->{$netcnx->{type}}, $netc, $a, $netcnx); $netcnx->{dhcp_client} and $netc->{dhcp_client} = $netcnx->{dhcp_client}; network::configureNetwork2($in, $prefix, $netc, $intf); $netcnx->{type} =~ /adsl/ or system("/sbin/chkconfig --del adsl 2> /dev/null"); $netcnx->{type} !~ /adsl_p/ and system("$prefix/etc/rc.d/init.d/network restart"); $button_apply->set_sensitive(0); } sub ethisup { `LC_ALL=C LANG=C LANGUAGE=C LC_MESSAGES=C /sbin/ifconfig` =~ /eth$_[0]/ } my $to_update; sub update { my $h = chomp_(`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} : $netcnx->{NET_INTERFACE}); $clist1->freeze(); $clist1->clear(); build_clist(); $clist1->thaw(); $button_del->set_sensitive(network::netconnect::get_profiles() > 1); $isconnected !=-1 or return 1; $label8->set($isconnected ? _("Connected") : _("Not connected")); $button2->child->set($isconnected ? _("Disconnect...") : _("Connect...")); $button2->set_sensitive(1); 1; } sub in_ifconfig { my ($intf) = @_; -e '/sbin/ifconfig' or return 1; $intf eq '' and return 1; `/sbin/ifconfig` =~ /$intf/; } sub update2 { undef $to_update; connected_bg(\$to_update); if (defined $to_update) { $isconnected = $to_update; if ($isconnected != -1) { if ($isconnected && !in_ifconfig($netcnx->{NET_INTERFACE})) { $warning_label1->set(_("Warning, another Internet connection has been detected, maybe using your network")); $isconnected = 0; } else { $warning_label1->set("") } $label8->set($isconnected ? _("Connected") : _("Not connected")); $button2->child->set($isconnected ? _("Disconnect...") : _("Connect...")); $button2->set_sensitive(1); } } update(); 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 @card_tab; if (@all_cards < 1) { my $dialog = new Gtk::Dialog(); $dialog->set_position(1); $dialog->vbox->set_border_width(10); $dialog->signal_connect (delete_event => sub { Gtk->main_quit() }); $dialog->vbox->pack_start(new Gtk::Label(_("You don't have any configured interface. Configure them first by clicking on 'Configure'")),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 { Gtk->main_quit() }); $bbox_dialog->add($button_ok); $dialog->show_all; $dialog->set_modal(1); Gtk->main(); $dialog->destroy; return; } $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); my @eth_data; foreach (0..$#all_cards) { my @infos; my @conf_data; $card_tab[2*$_] = \@infos; $card_tab[2*$_+1] = \@conf_data; 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 my $j (@conf_data) { $infos[2*$i] = new Gtk::HBox(0,0); my $l = new Gtk::Label($j->[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 $j->[2]) { my $c = new Gtk::Combo(); $c->set_popdown_strings(@{$j->[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(${$j->[1]}); $i++; } my $c = $_; my $widget_temp; if (-e "$prefix/etc/sysconfig/network-scripts/ifcfg-eth$c") { $widget_temp = gtksignal_connect(new Gtk::Button(ethisup($c) ? _("deactivate now") : _("activate now")), clicked => sub { system("/sbin/if".(ethisup($c)?"down" : "up")." eth$c"); gtkbuttonset($_[0], ethisup($c)? _("deactivate now") : _("activate now")); }); } else { $widget_temp = _("This interface has not been configured yet.\nLaunch the configuration wizard in the main window"); } $vbox_local->pack_start(gtkpack__(new Gtk::HBox(0,0), $widget_temp ),0,0,0); # $clist1->append($_+1, "eth$_", $intf->{"eth$_"}{IPADDR}, $intf->{"eth$_"}{BOOTPROTO}, $all_cards[$_]->[1]); # $clist1->set_selectable($_, 0); # require Data::Dumper; # print "------------\n" . Data::Dumper->Dump([$b],['b']) . "\n"; my $hbox_local = new Gtk::HBox(0,0); my $pix = gtkpng("/usr/share/libDrakX/pixmaps/eth_card_mini.png"); $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 $button_ok = new Gtk::Button(_("OK")); $button_ok->signal_connect (clicked => sub { foreach (0..$#all_cards) { my $i = 0; my @infos = @{$card_tab[2*$_]}; my @conf_data = @{$card_tab[2*$_+1]}; foreach my $j (@conf_data) { ${$j->[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(); foreach (0..$#all_cards) { my @infos = @{$card_tab[2*$_]}; $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) = @_; if (!$netcnx->{type}) { my $dialog = new Gtk::Dialog(); $dialog->set_position(1); $dialog->vbox->set_border_width(10); $dialog->signal_connect (delete_event => sub { Gtk->main_quit() }); $dialog->vbox->pack_start(new Gtk::Label(_("You don't have any internet connection. Create one first by clicking on 'Configure'")),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 { Gtk->main_quit(); }); $bbox_dialog->add($button_ok); $dialog->show_all; $dialog->set_modal(1); Gtk->main(); $dialog->destroy; return; } 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"), __("CHAP") ] ], [_("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"] ], [_("Connection speed"), \$cnx->{speed}, ["64 Kb/s", "128 Kb/s"]], [_("Connection timeout (in sec)"), \$cnx->{huptimeout} ] ); 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]->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); #hide password if Entry Password if ($_->[0] eq _("Account Password") || $_->[0] eq _("Password")) { $infos[2*$i+1]->set_visibility(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,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,1,1) if $netcnx->{type} eq'isdn_internal'&& defined $cnx->{vendor} && defined $cnx->{id}; @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,1,1) if $netcnx->{type} eq'isdn_internal'&&(!defined $cnx->{vendor}||!defined $cnx->{id}); @mask = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,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,0,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,0,0) 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) { ${$conf_data[$i]->[1]} = $infos[2*$i+1]->get_text() if ($_); $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; } id='n629' href='#n629'>629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
#-########################################################################
#- Pixel's implementation of Perl-GTK :-) [DDX]
#-########################################################################
package my_gtk; # $Id$
use diagnostics;
use strict;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $border);
@ISA = qw(Exporter);
%EXPORT_TAGS = (
helpers => [ qw(create_okcancel createScrolledWindow create_menu create_notebook create_packtable create_hbox create_vbox create_adjustment create_box_with_title create_treeitem) ],
wrappers => [ qw(gtksignal_connect gtkradio gtkpack gtkpack_ gtkpack__ gtkpack2 gtkpack3 gtkpack2_ gtkpack2__ gtkpowerpack gtkset_editable gtksetstyle gtkset_tip gtkappenditems gtkappend gtkset_shadow_type gtkset_layout gtkset_relief gtkadd gtkput gtktext_insert gtkset_usize gtksize gtkset_justify gtkset_active gtkset_sensitive gtkset_modal gtkset_border_width gtkmove gtkresize gtkshow gtkhide gtkdestroy gtkcolor gtkset_mousecursor gtkset_mousecursor_normal gtkset_mousecursor_wait gtkset_background gtkset_default_fontset gtkctree_children gtkxpm gtkpng create_pix_text get_text_coord fill_tiled gtkicons_labels_widget write_on_pixmap gtkcreate_xpm gtkcreate_png gtkbuttonset) ],
ask => [ qw(ask_warn ask_okcancel ask_yesorno ask_from_entry) ],
);
$EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ];
@EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
use Gtk;
use Gtk::Gdk::ImlibImage;
use c;
use log;
use common;
my $forgetTime = 1000; #- in milli-seconds
$border = 5;
#-###############################################################################
#- OO stuff
#-###############################################################################
sub new {
my ($type, $title, %opts) = @_;
Gtk->init;
Gtk::Gdk::ImlibImage->init;
Gtk->set_locale;
my $o = bless { %opts }, $type;
$o->_create_window($title);
while (my $e = shift @tempory::objects) { $e->destroy }
foreach (@interactive::objects) {
$_->{rwindow}->set_modal(0) if $_->{rwindow}->can('set_modal');
}
push @interactive::objects, $o if !$opts{no_interactive_objects};
$o->{rwindow}->set_position('center_always') if $::isStandalone;
$o->{rwindow}->set_modal(1) if $my_gtk::grab || $o->{grab};
if ($::isWizard && !$my_gtk::pop_it) {
my $rc = "/etc/gtk/wizard.rc";
-r $rc or $rc = dirname(__FILE__) . "/wizard.rc";
Gtk::Rc->parse($rc);
$o->{window} = new Gtk::VBox(0,0);
$o->{window}->set_border_width($::Wizard_splash ? 0 : 10);
$o->{rwindow} = $o->{window};
if (!defined($::WizardWindow)) {
$::WizardWindow = new Gtk::Window;
$::WizardWindow->set_position('center_always');
$::WizardTable = new Gtk::Table(2, 2, 0);
$::WizardWindow->add($::WizardTable);
my $draw1 = new Gtk::DrawingArea;
$draw1->set_usize(540,100);
my $draw2 = new Gtk::DrawingArea;
$draw2->set_usize(100,300);
my ($im_up, $mask_up) = gtkcreate_png($::Wizard_pix_up || "wiz_default_up.png");
my ($y1, $x1) = $im_up->get_size;
my ($im_left, $mask_left) = gtkcreate_png($::Wizard_pix_left || "wiz_default_left.png");
my ($y2, $x2) = $im_left->get_size;
my $style= new Gtk::Style;
$style->font(Gtk::Gdk::Font->fontset_load("-adobe-times-bold-r-normal-*-25-*-100-100-p-*-iso8859-*"));
my $w = $style->font->string_width($::Wizard_title);
$draw1->signal_connect(expose_event => sub {
my $i;
for ($i=0;$i<(540/$y1);$i++) {
$draw1->window->draw_pixmap ($draw1->style->bg_gc('normal'),
$im_up, 0, 0, 0, $y1*$i,
$x1 , $y1 );
$draw1->window->draw_string(
$style->font,
$draw1->style->white_gc,
140+(380-$w)/2, 62,
($::Wizard_title) );
}
});
$draw2->signal_connect(expose_event => sub {
my $i;
for ($i=0;$i<(300/$y2);$i++) {
$draw2->window->draw_pixmap ($draw2->style->bg_gc('normal'),
$im_left, 0, 0, 0, $y2*$i,
$x2 , $y2 );
}
});
$::WizardTable->attach($draw1, 0, 2, 0, 1, 'fill', 'fill', 0, 0);
$::WizardTable->attach($draw2, 0, 1, 1, 2, 'fill', 'fill', 0, 0);
$::WizardTable->set_usize(540,400);
$::WizardWindow->show_all;
flush();
}
$::WizardTable->attach($o->{window}, 1, 2, 1, 2, [-fill, -expand], [-fill, -expand], 0, 0);
}
$::isEmbedded && !$my_gtk::pop_it or return $o;
$o->{window} = new Gtk::HBox(0,0);
$o->{rwindow} = $o->{window};
defined($::Plug) or $::Plug = new Gtk::Plug ($::XID);
$::Plug->show;
flush();
$::Plug->add($o->{window});
$::CCPID and kill "USR2", $::CCPID;
$o;
}
sub main {
my ($o, $completed, $canceled) = @_;
gtkset_mousecursor_normal();
my $timeout = Gtk->timeout_add(1000, sub { gtkset_mousecursor_normal(); 1 });
my $b = before_leaving { Gtk->timeout_remove($timeout) };
$o->{rwindow}->window->set_events(['key_press_mask', 'key_release_mask', 'exposure_mask']) if $o->{rwindow}->window;
$o->show;
do {
local $::setstep = 1;
Gtk->main;
} while ($o->{retval} ? $completed && !$completed->() : $canceled && !$canceled->());
$o->destroy;
$o->{retval}
}
sub show($) {
my ($o) = @_;
$o->{window}->show;
$o->{rwindow}->show;
}
sub destroy($) {
my ($o) = @_;
$o->{rwindow}->destroy;
gtkset_mousecursor_wait();
flush();
}
sub DESTROY { goto &destroy }
sub sync {
my ($o) = @_;
show($o);
flush();
}
sub flush {
Gtk->main_iteration while Gtk->events_pending;
}
sub gtkshow($) { $_[0]->show; $_[0] }
sub gtkhide($) { $_[0]->hide; $_[0] }
sub gtkdestroy($) { $_[0] and $_[0]->destroy }
sub gtkset_usize($$$) { $_[0]->set_usize($_[1],$_[2]); $_[0] }
sub gtksize($$$) { $_[0]->size($_[1],$_[2]); $_[0] }
sub gtkset_justify($$) { $_[0]->set_justify($_[1]); $_[0] }
sub gtkset_active($$) { $_[0]->set_active($_[1]); $_[0] }
sub gtkset_modal { $_[0]->set_modal($_[1]); $_[0] }
sub gtkset_sensitive { $_[0]->set_sensitive($_[1]); $_[0] }
sub gtkset_border_width{ $_[0]->set_border_width($_[1]); $_[0] }
sub gtkmove { $_[0]->window->move($_[1], $_[2]); $_[0] }
sub gtkresize { $_[0]->window->resize($_[1], $_[2]); $_[0] }
sub gtksignal_connect($@) {
my $w = shift;
$w->signal_connect(@_);
$w
}
sub gtkradio {
my $def = shift;
my $radio;
map { $radio = new Gtk::RadioButton($_, $radio ? $radio : ());
$radio->set_active($_ eq $def); $radio } @_;
}
sub gtkpack_($@) { gtkpowerpack('arg', 1, @_) }
sub gtkpack($@) { gtkpowerpack(1, 1, @_) }
sub gtkpack__($@) { gtkpowerpack(0, 1, @_) }
sub gtkpack2_($@) { gtkpowerpack('arg', 0, @_) }
sub gtkpack2($@) { gtkpowerpack(1, 0, @_) }
sub gtkpack2__($@) { gtkpowerpack(0, 0, @_) }
sub gtkpack3 { gtkpowerpack($a?1:0, 0, @_) }
sub gtkpowerpack {
#- Get Default Attributes (if any). 2 syntaxes allowed :
#- gtkpowerpack( {expand => 1, fill => 0}, $box...) : the attributes are picked from a specified hash ref
#- gtkpowerpack(1,0,1, $box, ...) : the attributes are picked from the non-ref list, in the order (expand, fill, padding, pack_end).
my $RefDefaultAttrs;
if (ref($_[0]) eq 'HASH') {
$RefDefaultAttrs = shift;
} elsif (!ref($_[0])) {
my %tmp;
foreach my $i ("expand", "fill", "padding", "pack_end") {
!ref($_[0]) ? $tmp{$i} = shift : last
}
$RefDefaultAttrs = \%tmp;
}
my $box = shift;
while (@_) {
#- Get attributes (if specified). 4 syntaxes allowed (default values are undef ie. false...) :
#- gtkpowerpack({defaultattrs}, $box, $widget1, $widget2, ...) : the attrs are picked from the default ones (if they exist)
#- gtkpowerpack($box, {fill=>1, expand=>0, ...}, $widget1, ...) : the attributes are picked from a specified hash ref
#- gtkpowerpack($box, [1,0,1], $widget1, ...) : the attributes are picked from the array ref, in the order (expand, fill, padding, pack_end).
#- gtkpowerpack({attr=>'arg'}, $box, 1, $widget1, 0, $widget2, etc...) : the 'arg' value will tell gtkpowerpack to always read the attr value directly in the arg list (avoiding confusion between value 0 and Gtk::Label("0"). That can simplify some writings but this arg(s) MUST then be present...
my %attr;
my $RefAttrs = shift if (ref($_[0]) eq 'HASH' or ref($_[0]) eq 'ARRAY');
foreach my $i ("expand", "fill", "padding", "pack_end") {
if (defined($RefDefaultAttrs->{$i}) and $RefDefaultAttrs->{$i} eq 'arg') {
if (!ref ($_[0])) {
$attr{$i} = shift;
shift @$RefAttrs if (ref($RefAttrs) eq 'ARRAY')
} else {
die "error in packing definition\n"
}
} elsif (ref($RefAttrs) eq 'HASH' and defined($RefAttrs->{$i})) {
$attr{$i} = $RefAttrs->{$i}
} elsif (ref($RefAttrs) eq 'ARRAY') {
$attr{$i} = shift @$RefAttrs
} elsif (defined($RefDefaultAttrs->{$i})) {
$attr{$i} = int $RefDefaultAttrs->{$i}
} else {
$attr{$i} = 0
}
}
#- Get and pack the widget (create it if necessary when it is a label...)
my $widget = ref($_[0]) ? shift : new Gtk::Label(shift);
if (! $attr{pack_end}) {
$box->pack_start($widget, $attr{expand}, $attr{fill}, $attr{padding});
} else {
$box->pack_end($widget, $attr{expand}, $attr{fill}, $attr{padding});
}
$widget->show;
}
$box
}
sub gtkset_editable {
my ($w, $e) = @_;