/[libconf]/libconf/applications/netconfig/netconfig
ViewVC logotype

Diff of /libconf/applications/netconfig/netconfig

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by dams, Tue Jun 3 14:43:25 2003 UTC revision 1.3 by dams, Fri Jun 6 21:33:41 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2    
3  # Netconfig  # Smbconfig
4    
5  # Copyright (C) 2003 Damien Krotkine (dams@tuxfamily.org)  # Copyright (C) 2003 Damien Krotkine (dams@tuxfamily.org)
6  #  #
# Line 18  Line 18 
18  # along with this program; if not, write to the Free Software  # along with this program; if not, write to the Free Software
19  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21    # DrakX includes
   
22  use lib qw(/usr/lib/libDrakX);  use lib qw(/usr/lib/libDrakX);
   
23  use interactive;  use interactive;
24  use common;  use common;
25  use ugtk2 qw(:helpers :wrappers :create);  use ugtk2 qw(:helpers :wrappers :create);
26    
27    # we include the Network Systemconf module
28  use Libconf::System::Network;  use Libconf::System::Network;
29    
30    # for debugging purpose
31  use Data::Dumper;  use Data::Dumper;
32    
33    # we ask systemconf to give us the structure representing the global network config
34  my $sys_network = new Libconf::System::Network();  my $sys_network = new Libconf::System::Network();
 print Data::Dumper->Dump([$sys_network], ['sys_network']) . "\n";  
35    
36  #use Libconf::Glueconf::Samba;  # we dump the content for debugging purpose
37  #use Data::Dumper;  print Data::Dumper->Dump([$sys_network], ['sys_network']) . "\n";
38    
39  #my $samba = new Libconf::Glueconf::Samba('/etc/samba/smb.conf');  # we build the GUI
 #print Data::Dumper->Dump([$samba], ['samba']) . "\n";  
40    
41    # a window
42  my $window = Gtk2::Window->new('toplevel');  my $window = Gtk2::Window->new('toplevel');
43  $window->signal_connect(delete_event => sub { ugtk2->exit(0) });  $window->signal_connect(delete_event => sub { ugtk2->exit(0) });
44  unless ($::isEmbedded) {  $window->set_position('center');
45      $window->set_position('center');  $window->set_title(N('netconfig - Network configuration'));
     $window->set_title(N('netconfig - Network configuration'));  
 #    $window->set_size_request(500, 400);  
 }  
46    
47    # in the window, we add the widget generated by libconf_generate_UI,
48    # an OK button that will save the modification in the network config files,
49    # an Cancel button that will leave without saving.
50  gtkadd($window,  gtkadd($window,
51         gtkpack_(Gtk2::VBox->new(0,10),         gtkpack_(Gtk2::VBox->new(0,10),
52                  1, gtkshow(libconf_generate_UI($sys_network #$samba                  1, gtkshow(libconf_generate_UI($sys_network)),
                                               )),  
53                  0, gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),                  0, gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),
54                            gtksignal_connect(new Gtk2::Button(N("OK")),                            gtksignal_connect(new Gtk2::Button(N("OK")),
55                                              clicked => sub { save_exit(); })                                              clicked => sub { save_exit(); }),
56                              gtksignal_connect(new Gtk2::Button(N("Cancel")),
57                                                clicked => sub { cancel_exit(); })
58                           )                           )
59                 ),                 ),
60        );        );
61    
62  #my $notebook = new Gtk2::Notebook  # we make everything visible in the window
 # $notebook->set_tab_pos('left');  
 # $notebook->append_page(my $notebook_general = new Gtk2::Notebook,  
 #                        new Gtk2::Label(N('General')),  
 #                       );  
 # $notebook->append_page(my $notebook_interfaces = new Gtk2::Notebook,  
 #                        new Gtk2::Label(N('Network interfaces')),  
 #                       );  
   
 # while (my ($key, $value) = each %{$sys_network->{interfaces}}) {  
 #     $notebook_interfaces->append_page(create_packtable({ col_spacings => 5, row_spacings => 5 },  
 #                                                        map { [ new Gtk2::Label(N($_)), $value->{$_} ] } keys %$value,  
 #                                                       ), new Gtk2::Label($key))  
 # }  
   
63  $window->show_all();  $window->show_all();
64    
65    #and we start the Gtk2 main loop.
66  Gtk2->main;  Gtk2->main;
67    
68    # After the user has clicked on one button, we dump the content of the sys_network structure for debugging purpose
69  print Data::Dumper->Dump([$sys_network], ['sys_network']) . "\n";  print Data::Dumper->Dump([$sys_network], ['sys_network']) . "\n";
 #print Data::Dumper->Dump([$samba], ['samba']) . "\n";  
 ugtk2->exit(0);  
70    
71  #  #and we exit the program.
72    ugtk2->exit(0);
73    
74    # the function called when the user clicks on the OK button
75  sub save_exit {  sub save_exit {
76      print "writeconf\n";  
77        # we ask the $sys_network object to write itself back to the real config file
78        # he knows everything about himself, so no need to give him any arg.
79        # the file is rewritten, without loosing any information or comments.
80        $sys_network->writeconf();
81    
82        # we exit the gtk2 main loop
83      Gtk2->main_quit();      Gtk2->main_quit();
84  }  }
85    
86    # the function called when the user clicks on the Cancel button
87    sub cancel_exit {
88    
89        # we exit the gtk2 main loop
90        Gtk2->main_quit();
91    }
92    
93    
94    
95    
96    
97    
98    
99    
100    
101    
102    
103    
104    
105    
106    
107    #####
108    # The followings are here because it has not yet been incorporated into libconf.
109    # In the final version you won't need this, it'll be in libconf.
110    #
111    # So the program source code should terminate here.
112    #####
113    
114  sub initialize_notebook {  sub initialize_notebook {
115      gtkpack_(shift, 0, my $notebook = new Gtk2::Notebook);      gtkpack_(shift, 0, my $notebook = new Gtk2::Notebook);
116      #        $notebook->set_tab_pos('left');      #        $notebook->set_tab_pos('left');
# Line 159  sub libconf_generate_UI { Line 185  sub libconf_generate_UI {
185          return $vbox;          return $vbox;
186      }      }
187      if (UNIVERSAL::isa($struct, 'ARRAY')) {      if (UNIVERSAL::isa($struct, 'ARRAY')) {
 #         my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->OBJECT, map { Gtk2::GType->STRING } 1);  
 #         my $list = Gtk2::TreeView->new_with_model($tree_model);  
 #         $list->append_column(Gtk2::TreeViewColumn->new_with_attributes('column name', Gtk2::CellRendererText->new, 'text' => 1));  
   
   
188          my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);          my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);
189          my $list = Gtk2::TreeView->new_with_model($tree_model);          my $list = Gtk2::TreeView->new_with_model($tree_model);
190          $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(N("list"), Gtk2::CellRendererText->new, 'text' => 0));          $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(N("list"), Gtk2::CellRendererText->new, 'text' => 0));
# Line 181  sub libconf_generate_UI { Line 202  sub libconf_generate_UI {
202  sub create_dialog {  sub create_dialog {
203      my ($label) = @_;      my ($label) = @_;
204      my $ret;      my $ret;
205      my $dialog = new_dialog();      my $dialog = new Gtk2::Dialog();
206      $dialog->set_position('center');      $dialog->set_position('center');
207        $dialog->set_position('center-on-parent');
208        $dialog->vbox->set_border_width(10);
209        $dialog->signal_connect(delete_event => sub { Gtk2->main_quit() });
210      $dialog->vbox->pack_start(new Gtk2::Label($label),1,1,0);      $dialog->vbox->pack_start(new Gtk2::Label($label),1,1,0);
211      my $bbox_dialog = new Gtk2::HButtonBox;      my $bbox_dialog = new Gtk2::HButtonBox;
212      $dialog->action_area->add($bbox_dialog);      $dialog->action_area->add($bbox_dialog);
# Line 206  sub create_dialog { Line 230  sub create_dialog {
230      $dialog->destroy;      $dialog->destroy;
231      $ret;      $ret;
232  }  }
                                                                           
                                                                           
   
   
   
   
   
   
   
   
   
   
 sub new_dialog {  
     my $dialog = new Gtk2::Dialog();  
     $dialog->set_position('center-on-parent');  
     $dialog->vbox->set_border_width(10);  
     $dialog->signal_connect(delete_event => sub { Gtk2->main_quit() });  
     $dialog;  
 }  
   
   
   
   
   
   
   
   
   
 sub my_create_packtable {  
     my ($options, @l) = @_;  
     my $w = Gtk2::Table->new(0, 0, 0);  
     each_index {  
         my ($i, $l) = ($_[0], $_);  
         each_index {  
             my ($j) = @_;  
             if ($_) {  
                 ref $_ or $_ = Gtk2::Label->new($_);  
                 $w->attach($_, $j, $j + 1, $i, $i + 1,  
                            ['expand', 'expand'],  
                            ['shrink', 'shrink'],  
                            0, 0);  
                 $_->show;  
             }  
         } @$l;  
     } @l;  
     $w->set_col_spacings($options->{col_spacings} || 0);  
     $w->set_row_spacings($options->{row_spacings} || 0);  
     $w  
 }  
       
 # $notebook->append_page(my $notebook_general = new Gtk2::Notebook,  
 #                        new Gtk2::Label(N('General')),  
 #                       );  
 # $notebook->append_page(my $notebook_interfaces = new Gtk2::Notebook,  
 #                        new Gtk2::Label(N('Network interfaces')),  
 #                       );  
   
 # while (my ($key, $value) = each %{$sys_network->{interfaces}}) {  
 #     $notebook_interfaces->append_page(create_packtable({ col_spacings => 5, row_spacings => 5 },  
 #                                                        map { [ new Gtk2::Label(N($_)), $value->{$_} ] } keys %$value,  
 #                                                       ), new Gtk2::Label($key))  
 # }  
       
   
   
   
   
   
 my $expert_mode = 0;  
 network::netconnect::read_net_conf('', $netcnx, $netc);  
 modules::load_category('net');  
 my @all_cards = network::ethernet::conf_network_card_backend($netc, $intf);  
 network::netconnect::load_conf($netcnx, $netc, $intf);  
 network::network::probe_netcnx_type('', $netc, $intf, $netcnx);  
   
 my $window1 = ugtk2->new('drakconnect');  
 $window1->{rwindow}->signal_connect(delete_event => sub { ugtk2->exit(0) });  
 unless ($::isEmbedded) {  
     $window1->{rwindow}->set_position('center');  
     $window1->{rwindow}->set_title(N("Network configuration (%d adapters)", @all_cards));  
     $window1->{rwindow}->set_size_request(500, 400);  
 }  
 $window1->{rwindow}->set_border_width(10);  
   
 my $combo1 = new Gtk2::Combo;  
 $combo1->set_popdown_strings(network::netconnect::get_profiles());  
 my $old_profile = $netcnx->{PROFILE};  
 $combo1->entry->set_text($netcnx->{PROFILE} || "default");  
 $combo1->entry->set_editable(0);  
 my $button_del = new Gtk2::Button(N("Del profile..."));  
 $button_del->signal_connect(clicked => sub {  
                                 my $dialog = new_dialog();  
                                 $dialog->vbox->pack_start(new Gtk2::Label(N("Profile to delete:")),1,1,0);  
                                 my $combo_dialog = new Gtk2::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 Gtk2::HButtonBox;  
                                 $dialog->action_area->add($bbox_dialog);  
                                 $bbox_dialog->set_layout('end');  
                                 my $button_ok = new Gtk2::Button(N("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";  
                                                                Gtk2->main_quit();  
                                                            });  
                                 $bbox_dialog->add($button_ok);  
                                 my $button_cancel = new Gtk2::Button(N("Cancel"));  
                                 $button_cancel->signal_connect(clicked => sub { Gtk2->main_quit() });  
                                 $bbox_dialog->add($button_cancel);  
                                 $dialog->show_all;  
                                 $dialog->set_modal(1);  
                                 Gtk2->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();  
                             });  
 $button_del->set_sensitive(network::netconnect::get_profiles() > 1);  
 my $button_new = new Gtk2::Button(N("New profile..."));  
 $button_new->signal_connect(clicked => sub {  
                                 my $dialog = new_dialog();  
                                 $dialog->vbox->pack_start(new Gtk2::Label(N("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 Gtk2::Entry;  
                                 $dialog->vbox->pack_start($entry_dialog,1,1,0);  
                                 my $bbox_dialog = new Gtk2::HButtonBox;  
                                 $dialog->action_area->add($bbox_dialog);  
                                 $bbox_dialog->set_layout('end');  
                                 my $button_ok = new Gtk2::Button(N("OK"));  
                                 $button_ok->signal_connect(clicked => sub {  
                                                                network::netconnect::add_profile($netcnx, $entry_dialog->get_text());  
                                                                $netcnx->{PROFILE} = $entry_dialog->get_text();  
                                                                Gtk2->main_quit();  
                                                            });  
                                 $bbox_dialog->add($button_ok);  
                                 my $button_cancel = new Gtk2::Button(N("Cancel"));  
                                 $button_cancel->signal_connect(clicked => sub { Gtk2->main_quit() });  
                                 $bbox_dialog->add($button_cancel);  
                                 $dialog->show_all;  
                                 $dialog->set_modal(1);  
                                 Gtk2->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());  
                             });  
 my $hostname = chomp_(`hostname`);  
   
 #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);  
 my $type_label = new Gtk2::Label($netcnx->{type});  
 my $int_label = new Gtk2::Label($netcnx->{type} eq 'lan' ? N("Gateway:") : N("Interface:"));  
 my $interface_name = new Gtk2::Label($netcnx->{type} eq 'lan' ? $netc->{GATEWAY} : $netcnx->{NET_INTERFACE});  
 my $isconnected = -1;  
 #-sub connected_local {  
 #-    print "in connected local\n";  
 #-    my $w = $in->wait_message('', N("Testing your connection..."), 1);  
 #-    gtkflush();  
 #-    $isconnected = connected();  
 #-}  
   
 my $warning_label1 = new Gtk2::Label("");  
 my $int_connect = new Gtk2::Button(N("Wait please"));  
 $int_connect->set_sensitive(0);  
 $int_connect->signal_connect(clicked => sub {  
     if (!$isconnected) {  
         if (cat_($connect_prog) =~ m|/usr/bin/kppp| && -e '/usr/bin/kppp') {  
             run_program::rooted($prefix, "/usr/bin/kppp &");  
           } else {  
               connect_backend();  
           }  
     } else {  
         disconnect_backend();  
     }  
     update2();  
 });  
   
   
 my $button_internet = gtksignal_connect(Gtk2::Button->new(N("Configure Internet Access...")),  
                                 clicked => sub { configure_net('', $netcnx, $netc, $intf) });  
   
   
 my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->OBJECT, map { Gtk2::GType->STRING } 2..6);  
 my $list = Gtk2::TreeView->new_with_model($tree_model);  
 $list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 0));  
 each_index { $list->append_column(Gtk2::TreeViewColumn->new_with_attributes($_, Gtk2::CellRendererText->new, 'text' => $::i + 1)) } (N("Interface"), N("IP address"), N("Protocol"), N("Driver"), N("State"));  
   
 #TV $list->set_column_auto_resize($_,1) foreach (0..4);  
 #TV $list->column_titles_passive();  
 #TV $list->set_shadow_type('etched_out');  
 #$scrolled1->add_with_viewport($table2);  
   
 my $ip_regexp = qr/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;  
   
 build_list();  
   
 my $button_lan = gtksignal_connect(Gtk2::Button->new(N("Configure Local Area Network...")),  
                                 clicked => sub { configure_lan('', $netcnx, $netc, $intf) });  
   
 my ($bbox0, $label_host, $int_state);  
   
 $window1->{window}->add(  
                         gtkpack_(Gtk2::VBox->new(0,10),  
                                  if_($activate_profile,  
                                      0, gtkpack_(Gtk2::HBox->new(0,0),  
                                                  0, new Gtk2::Label(N("Profile: ")),  
                                                  0, $combo1,  
                                                  0, $button_del,  
                                                  0, $button_new,  
                                                 ),  
                                  ),  
                                  0, gtkpack_(Gtk2::HBox->new(0,0),  
                                              0, new Gtk2::Label(N("Hostname: ")),  
                                              0, $label_host = new Gtk2::Label($hostname),  
                                              ),  
                                  0, gtkadd(Gtk2::Frame->new(N("Internet access")),  
                                            gtkpack_(gtkset_border_width(Gtk2::VBox->new(0,0), 5),  
                                                     1, gtkset_border_width(create_packtable({ col_spacings => 5, row_spacings => 5 },  
                                                                                             [ new Gtk2::Label(N("Type:")), $type_label ],  
                                                                                             [ $int_label, $interface_name ],  
                                                                                             [ Gtk2::Label->new(N("Status:")),  
                                                                                               $int_state = Gtk2::Label->new(N("Testing your connection...")),  
                                                                                               $int_connect, ] # $button_internet ]  
                                                                                             ),  
                                                                            5),  
                                                     0, $warning_label1,  
                                                     0, gtkpack_(new Gtk2::HBox(0, 0),  
                                                                 0, $button_internet),  
                                                     )  
                                            ),  
                                  1, gtkadd(Gtk2::Frame->new(N("LAN configuration")),  
                                            gtkpack_(gtkset_border_width(Gtk2::VBox->new(0,0), 5),  
                                                     0, $list,  
                                                     0, new Gtk2::HBox(0,0),  
                                                     0, gtkpack_(new Gtk2::HBox(0, 0),  
                                                                 0, $button_lan),  
                                                     )  
                                            ),  
                                  0, gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),  
                                            gtksignal_connect(Gtk2::Button->new(N("Wizard...")),  
                                                              clicked => sub {  
                                                                  $::isWizard = 1;  
                                                                  system("drakconnect --wizard");  
                                                                  #- reload everything...  
                                                                  $netcnx = {}; $netc = {}; $intf = {};  
                                                                  network::netconnect::read_net_conf('', $netcnx, $netc);  
                                                                  modules::load_category('net');  
                                                                  @all_cards = network::ethernet::conf_network_card_backend($netc, $intf);  
                                                                  network::netconnect::load_conf($netcnx, $netc, $intf);  
                                                                  network::network::probe_netcnx_type('', $netc, $intf, $netcnx);  
                                                                  $combo1->entry->set_text(-e "/etc/sysconfig/network-scripts/drakconnect_conf." . ($combo1->entry->get_text || "default"));  
                                                                  update();  
                                                              }),  
                                            Gtk2::Label->new(N("Click here to launch the wizard ->"))  
                                            ),  
                                  0, Gtk2::HSeparator->new,  
                                  0, gtkset_layout($bbox0 = new Gtk2::HButtonBox, 'end')  
                                  ),  
                         );  
   
   
 #$bbox0->set_border_width(5);  
   
 my $button_expert = new Gtk2::Button(N("Expert Mode"));  
 $button_expert->signal_connect(clicked => sub {  
                                      foreach ($button_internet, $button_lan) { $expert_mode ? $_->hide() : $_->show() }  
                                      $button_expert->child->set($expert_mode ? N("Expert Mode") : N("Normal Mode"));  
                                      $expert_mode = !$expert_mode;  
                                  });  
 $bbox0->add($button_expert);  
   
 my $button_apply = new Gtk2::Button(N("Apply"));  
 $button_apply->signal_connect(clicked => sub {  
                                  apply();  
                              });  
 $button_apply->set_sensitive(0);  
 $bbox0->add($button_apply);  
   
 my $button_cancel = new Gtk2::Button(N("Cancel"));  
 $button_cancel->signal_connect(clicked => sub {  
                                      $combo1->entry->set_text($old_profile);  
                                      update();  
                                      quit_global();  
                                  });  
 $bbox0->add($button_cancel);  
 my $button_ok = new Gtk2::Button(N("OK"));  
 $button_ok->signal_connect(clicked => sub {  
                                  my $dialog = new_dialog();  
                                  my $label = new Gtk2::Label(N("Please Wait... Applying the configuration"));  
                                  $dialog->vbox->pack_start($label,1,1,20);  
                                  $dialog->show_all;  
                                  gtkflush();  
                                  apply();  
                                  $dialog->destroy;  
                                  update();  
                                  quit_global();  
                              });  
 $bbox0->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->{rwindow}->show_all();  
 $_->hide foreach $button_internet, $button_lan;  
 gtkflush();  
 my $tag = Gtk2->timeout_add(4000, \&update2);  
 $window1->main;  
 ugtk2->exit(0);  
   
 dd:  
 network::netconnect::intro('', $netcnx, $in);  
 $in->exit(0);  
   
 sub build_list {  
     foreach my $i (0..$#all_cards) {  
         my ($ip, $state);  
         if (-x "/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$i"}{IPADDR};  
             $state = "n/a";  
         }  
         $tree_model->append_set(undef, [ map_index { $::i => $_ } (gtkcreate_pixbuf("eth_card_mini2.png"), "eth$i", $ip , $intf->{"eth$i"}{BOOTPROTO}, $all_cards[$i][1], $state) ])->free;  
 #TV     $list->set_selectable($i, 0);  
     }  
 }  
   
 sub apply {  
     $old_profile = $netcnx->{PROFILE} || "default";  
     network::netconnect::save_conf($netcnx, $netc, $intf);  
   
     $netcnx->{type} eq 'modem' and network::modem::ppp_configure($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 network::modem::ppp_configure($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);  
     $type_label->set($netcnx->{type});  
     $int_label->set($netcnx->{type} eq 'lan' ? N("Gateway:") : N("Interface:"));  
     $interface_name->set($netcnx->{type} eq 'lan' ? $netc->{GATEWAY} : $netcnx->{NET_INTERFACE});  
 #TV    $list->window->freeze();  
     $tree_model->clear;  
     build_list();  
 #TV    $list->window->thaw();  
     $button_del->set_sensitive(network::netconnect::get_profiles() > 1);  
     return 1 if $isconnected == -1;  
     $int_state->set($isconnected ? N("Connected") : N("Not connected"));  
     $int_connect->child->set($isconnected ? N("Disconnect...") : N("Connect..."));  
     $int_connect->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(N("Warning, another Internet connection has been detected, maybe using your network"));  
                 $isconnected = 0;  
             } else { $warning_label1->set("") }  
             $int_state->set($isconnected ? N("Connected") : N("Not connected"));  
             $int_connect->child->set($isconnected ? N("Disconnect...") : N("Connect..."));  
             $int_connect->set_sensitive(1);  
         }  
     }  
     update();  
     1;  
 }  
   
 sub quit_global {  
     ugtk2->exit(0);  
 }  
   
 sub configure_lan {  
     my ($prefix, $netcnx, undef, $intf) = @_;  
     my $window = Gtk2::Window->new('toplevel');  
   
     my @card_tab;  
   
     if (@all_cards < 1) {  
         my $dialog = new_dialog();  
         $dialog->vbox->pack_start(new Gtk2::Label(N("You don't have any configured interface.  
 Configure them first by clicking on 'Configure'")),1,1,0);  
         $dialog->action_area->add(gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),  
                                          gtksignal_connect(new Gtk2::Button(N("OK")),  
                                                            clicked => sub { Gtk2->main_quit() })  
                                          )  
                                   );  
         $dialog->show_all;  
         $dialog->set_modal(1);  
         Gtk2->main();  
         $dialog->destroy;  
         return;  
     }  
   
     $window->signal_connect(delete_event => sub { Gtk2->main_quit });  
     $window->set_position('center');  
     $window->set_title(N("LAN configuration"));  
     $window->set_border_width(10);  
     my $vbox0 = new Gtk2::VBox(0,0);  
     $window->add($vbox0);  
     $vbox0->pack_start(new Gtk2::Label(N("LAN Configuration")),0,1,0);  
     my $notebook = new Gtk2::Notebook;  
     $vbox0->pack_start($notebook,0,1,0);  
     foreach (0..$#all_cards) {  
         my @infos;  
         my @conf_data;  
         $card_tab[2*$_] = \@infos;  
         $card_tab[2*$_+1] = \@conf_data;  
         my $vbox_local = new Gtk2::VBox(0,0);  
         $vbox_local->set_border_width(10);  
         $vbox_local->pack_start(new Gtk2::Label(N("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 = ([N("IP address"), \$intf->{"eth$_"}{IPADDR}],  
                          [N("Netmask"), \$intf->{"eth$_"}{NETMASK}],  
                          [N("Boot Protocol"), \$intf->{"eth$_"}{BOOTPROTO}, ["static", "dhcp", "bootp"]],  
                          [N("Started on boot"), \$intf->{"eth$_"}{ONBOOT} , ["yes", "no"]],  
                          [N("DHCP client"), \$netcnx->{dhcp_client}]  
                         );  
         my $i = 0;  
         foreach my $j (@conf_data) {  
             $infos[2*$i] = new Gtk2::HBox(0,0);  
             my $l = new Gtk2::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 Gtk2::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 Gtk2::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 Gtk2::Button(ethisup($c) ? N("deactivate now") : N("activate now")),  
                                              clicked => sub {  
                                                  system("/sbin/if" . (ethisup($c) ? "down" : "up") . " eth$c");  
                                                  gtkbuttonset($_[0], ethisup($c) ? N("deactivate now") : N("activate now"));  
                                              });  
         } else {  
             $widget_temp = N("This interface has not been configured yet.\nLaunch the configuration wizard in the main window");  
         }  
         $vbox_local->pack_start(gtkpack__(new Gtk2::HBox(0,0),  
                                           $widget_temp  
                                          ),0,0,0);  
         #       $list->append($_+1, "eth$_", $intf->{"eth$_"}{IPADDR}, $intf->{"eth$_"}{BOOTPROTO}, $all_cards[$_]->[1]);  
         #       $list->set_selectable($_, 0);  
         my $hbox_local = new Gtk2::HBox(0,0);  
         my $pix = gtkcreate_img("/usr/share/libDrakX/pixmaps/eth_card_mini.png");  
         $hbox_local->pack_start($pix,0,0,0);  
         $hbox_local->pack_start(new Gtk2::Label("eth$_"),0,0,0);  
         $hbox_local->show_all;  
         $notebook->append_page($vbox_local, $hbox_local);  
     }  
     my $bbox8 = new Gtk2::HButtonBox;  
     $vbox0->pack_start($bbox8,0,0,10);  
     $bbox8->set_layout('end');  
     my $button_ok = new Gtk2::Button(N("OK"));  
     $button_ok->signal_connect(clicked => sub {  
         foreach (0..$#all_cards) {  
             my @infos = @{$card_tab[2*$_]};  
             each_index {  
                 ${$_->[1]} = $infos[2*$::i+1]->get_text();  
             } @{$card_tab[2*$_+1]};  
             if ($intf->{"eth$_"}{BOOTPROTO} eq "dhcp") {  
                 my $entry = $intf->{"eth$_"};  
                 delete @{$intf->{"eth$_"}}{qw(IPADDR NETWORK NETMASK BROADCAST)};  
             }  
         }  
         update();  
         $button_apply->set_sensitive(1);  
         $window->destroy(); Gtk2->main_quit;  
     });  
     $bbox8->add($button_ok);  
   
     my $button_cancel = new Gtk2::Button(N("Cancel"));  
     $button_cancel->signal_connect(clicked => sub { $window->destroy(); Gtk2->main_quit });  
     $bbox8->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');  
     Gtk2->main;  
 }  
   
   
 sub configure_net {  
     my ($_prefix, $netcnx, $netc, $_intf) = @_;  
     if (!$netcnx->{type}) {  
         my $dialog = new_dialog();  
         $dialog->vbox->pack_start(new Gtk2::Label(N("You don't have an Internet connection.  
 Create one first by clicking on 'Configure'")),1,1,0);  
         my $bbox_dialog = new Gtk2::HButtonBox;  
         $dialog->action_area->add($bbox_dialog);  
         $bbox_dialog->set_layout('end');  
         my $button_ok = new Gtk2::Button(N("OK"));  
         $button_ok->signal_connect(clicked => sub {  
                                          Gtk2->main_quit();  
                                      });  
         $bbox_dialog->add($button_ok);  
         $dialog->show_all;  
         $dialog->set_modal(1);  
         Gtk2->main();  
         $dialog->destroy;  
         return;  
     }  
     my $cnx = {};  
     $cnx = $netcnx->{$netcnx->{type}};  
     my $window = Gtk2::Window->new('toplevel');  
     $window->signal_connect(delete_event => sub { Gtk2->main_quit });  
     $window->set_position('center');  
     $window->set_title(N("Internet connection configuration"));  
     $window->set_border_width(10);  
     my $table1 = new Gtk2::Table(2, 4, 0);  
     $table1->set_row_spacings(5);  
     $table1->set_col_spacings(5);  
     $table1->attach(new Gtk2::Label(N("Profile: ")), 0, 1, 0, 1, 'fill', 'fill',0,0);  
     $table1->attach(new Gtk2::Label(translate($netcnx->{PROFILE})), 1, 2, 0, 1, 'fill', 'fill',0,0);  
     $table1->attach(new Gtk2::Label(N("Connection type: ")), 0, 1, 1, 2, 'fill', 'fill',0,0);  
     $table1->attach(new Gtk2::Label(translate($netcnx->{type})), 1, 2, 1, 2, 'fill', 'fill',0,0);  
 #    my $button_internet = new Gtk2::Button(N("Reconfigure using wizard..."));  
 #    $table1->attach($button_internet, 2, 4, 0, 2, 'fill', 'fill',0,0);  
   
     my $vbox2 = new Gtk2::VBox(0,0);  
     my $i = 0;  
     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';  
   
     #- duplicated code (waiting for 9.1 to be out to merge everything correctly, avoid bug elsewhere).  
     if ($netcnx->{type} =~ /adsl/) {  
         require network::adsl;  
         network::adsl::adsl_probe_info($cnx, $netc, $intf, undef);  
     }  
     my @conf_data = ([ N("Card IRQ"), \$cnx->{irq} ],  
                      [ N("Card mem (DMA)"), \$cnx->{mem} ],  
                      [ N("Card IO"), \$cnx->{io} ],  
                      [ N("Card IO_0"), \$cnx->{io0} ],  
                      [ N("Card IO_1"), \$cnx->{io1} ],  
                      [ N("Your personal phone number"), \$cnx->{phone_in} ],  
                      [ N("Provider name (ex provider.net)"), \$netc->{DOMAINNAME2} ],  
                      [ N("Provider phone number"), \$cnx->{phone_out} ],  
                      [ N("Provider dns 1 (optional)"), \$netc->{dnsServer2} ],  
                      [ N("Provider dns 2 (optional)"), \$netc->{dnsServer3} ],  
                      [ N("Account Login (user name)"), \$cnx->{login} ],  
                      [ N("Account Password"), \$cnx->{passwd} ],  
                      [ N("Dialing mode"), \$cnx->{dialing_mode}, [ "auto", "manual" ] ],  
                      [ N("Gateway"), \$netc->{GATEWAY} ],  
                      [ N("Connection name"), \$cnx->{connection} ],  
                      [ N("Phone number"), \$cnx->{phone} ],  
                      [ N("Login ID"), \$cnx->{login} ],  
                      [ N("Password"), \$cnx->{passwd} ],  
                      [ N("Authentication"), \$cnx->{auth}, [ N("PAP"), N("Terminal-based"), N("Script-based"), N_("CHAP") ] ],  
                      [ N("Domain name"), \$cnx->{domain} ],  
                      [ N("First DNS Server (optional)"), \$cnx->{dns1} ],  
                      [ N("Second DNS Server (optional)"), \$cnx->{dns2} ],  
                      [ N("Ethernet Card"), \$netc->{NET_DEVICE}, [ 'eth0', 'eth1', 'eth2', 'eth3', 'eth4', 'eth5', 'eth6', 'eth7', 'eth8', 'eth9' ] ],  
                      [ N("DHCP Client"), \$netcnx->{dhcp_client}, ["dhcp-client", "dhcpcd", "dhcpxd"] ],  
                      [ N("Connection speed"), \$cnx->{speed}, ["64 Kb/s", "128 Kb/s"] ],  
                      [ N("Connection timeout (in sec)"), \$cnx->{huptimeout} ]  
 );  
     my @infos;  
     foreach (@conf_data) {  
         if (!$mask[$i]) {  
             $i++;  
             next;  
         }  
         $infos[2*$i] = new Gtk2::HBox(0,0);  
         my $l = new Gtk2::Label($_->[0]);  
         $l->set_justify('left');  
         $infos[2*$i]->pack_start($l, 0, 0, 0);  
         $vbox2->pack_start($infos[2*$i], 0, 0, 0);  
         if (defined $_->[2]) {  
             my $c = new Gtk2::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 Gtk2::Entry();  
             $infos[2*$i]->pack_start($infos[2*$i+1], 0, 0, 0);  
             #hide password if Entry Password  
             if ($_->[0] eq N("Account Password") || $_->[0] eq N("Password")) { $infos[2*$i+1]->set_visibility(0) };  
         }  
         $infos[2*$i+1]->set_text(${$_->[1]});  
         $i++;  
     }  
   
     my $button_ok = new Gtk2::Button(N("OK"));  
     $button_ok->signal_connect(clicked => sub {  
                                      each_index {  
                                             ${$conf_data[$::i][1]} = $infos[2*$::i+1]->get_text() if $_;  
                                      } @mask;  
                                      update();  
                                      $button_apply->set_sensitive(1);  
                                      $window->destroy(); Gtk2->main_quit;  
                                  });  
     my $button_cancel = new Gtk2::Button(N("Cancel"));  
     $button_cancel->signal_connect(clicked => sub { $window->destroy(); Gtk2->main_quit });  
   
     $window->set_modal(1);  
   
     gtkadd($window,  
            gtkpack__(new Gtk2::VBox(0, 0),  
                      new Gtk2::Label(N("Internet Connection Configuration")),  
                      new Gtk2::HSeparator,  
                      $table1,  
                      new Gtk2::HSeparator,  
                      gtkadd(Gtk2::Frame->new(N("Parameters")), $vbox2),  
                      new Gtk2::HSeparator,  
                      gtkadd(gtkset_layout(Gtk2::HButtonBox->new, 'end'),  
                             $button_ok,  
                             $button_cancel,  
                            ),  
                     ),  
           );  
   
     $window->show_all();  
     Gtk2->main;  
 }  
   
 sub new_dialog {  
     my $dialog = new Gtk2::Dialog();  
     $dialog->set_position('center-on-parent');  
     $dialog->vbox->set_border_width(10);  
     $dialog->signal_connect(delete_event => sub { Gtk2->main_quit() });  
     $dialog;  
 }  

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26