diff options
author | Mystery Man <unknown@mandriva.org> | 2005-08-31 06:46:48 +0000 |
---|---|---|
committer | Mystery Man <unknown@mandriva.org> | 2005-08-31 06:46:48 +0000 |
commit | 5844f1e0c17421240c559685a9b466c370204177 (patch) | |
tree | 8643044b4dd396b2b807b3a1dc27e3c8d555505a | |
parent | 3c26a6800291c2018dd456fafed226c3db868614 (diff) | |
download | drakpxelinux-5844f1e0c17421240c559685a9b466c370204177.tar drakpxelinux-5844f1e0c17421240c559685a9b466c370204177.tar.gz drakpxelinux-5844f1e0c17421240c559685a9b466c370204177.tar.bz2 drakpxelinux-5844f1e0c17421240c559685a9b466c370204177.tar.xz drakpxelinux-5844f1e0c17421240c559685a9b466c370204177.zip |
This commit was manufactured by cvs2svn to create tag 'V1_1_0_2mdk'.V1_1_0_2mdk
-rw-r--r-- | drakpxelinux.pl | 371 |
1 files changed, 76 insertions, 295 deletions
diff --git a/drakpxelinux.pl b/drakpxelinux.pl index 1850675..6104a61 100644 --- a/drakpxelinux.pl +++ b/drakpxelinux.pl @@ -38,18 +38,10 @@ use network::tools; use interactive; # must come *after* definition of textdomains for proper initialisation use ugtk2 qw(:ask :helpers :wrappers :create :dialogs); -use mygtk2 qw(gtknew); -use Gtk2::SimpleList; -use Gtk2::Helper; -use run_program; -use IO::Socket; -use Data::Dumper; use constant FALSE => 0; use constant TRUE => 1; -my ($treeview, $model); - # ie of entry menu in PXE: #label linux # KERNEL images/vmlinuz @@ -112,18 +104,6 @@ sub get_items { [ "/_PXE Server", undef, undef, undef, '<Branch>', ], [ "/_PXE Server/_Restart", undef, \&restart_dialog, 1, '<StockItem>', 'gtk-execute' ], - [ "/_PXE Server/_Reconfigure", undef, sub { - eval { wizard_pxe_server() }; - my $err = $@; - $::WizardWindow->destroy if defined $::WizardWindow; - undef $::WizardWindow; - if ($err && $err !~ /wizcancel/) { - err_dialog(N("Error"), N("The PXE server wizard has unexpectedly failed:") - . "\n\n" . $err); - } - }, 1, '<StockItem>', 'gtk-execute' ], - - [ "/_Help/Help", undef, \&show_help, 1, '<StockItem>', 'gtk-help' ], ); return @items; } @@ -180,11 +160,11 @@ foreach (@ARGV) { my ($config_file, $help_file) = $profile && $type ? network::pxe::get_pxelinux_profile_path($profile, $type) : ($network::pxe::pxelinux_config_file, $network::pxe::pxelinux_help_file); + my $pxelinux_conf = network::pxe::read_pxelinux_conf($config_file, $help_file); -sub write_conf { - my ($pxelinux_conf) = @_; - network::pxe::write_pxelinux_conf($pxelinux_conf, $config_file); +sub write_conf() { + network::pxe::write_pxelinux_conf($pxelinux_conf, $config_file); } sub set_pxelinux_entry_at_iter { @@ -209,27 +189,14 @@ sub set_pxelinux_entry_at_iter { sub create_model() { # my $model = Gtk2::ListStore->new(("Glib::String") x NUM_COLUMNS); - my $model = Gtk2::ListStore->new("Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String"); -# set_pxelinux_entry_at_iter($model, $model->append, $_) foreach @{$pxelinux_conf->{entries}}; - set_pxelinux_entry_at_iter($model, $model->append, $_) foreach @{$pxelinux_conf->{entries}}; - return $model; -} - -sub add_local_entry { - my ($_widget, $treeview, $pxelinux_conf) = @_; - my $model = $treeview->get_model; - if (test_similar_label("local", $pxelinux_conf)) { - my $entry = { - label => "local", - }; - push @{$pxelinux_conf->{entries}}, $entry; - set_pxelinux_entry_at_iter($model, $model->append, $entry); - } + my $model = Gtk2::ListStore->new("Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String", "Glib::String"); + set_pxelinux_entry_at_iter($model, $model->append, $_) foreach @{$pxelinux_conf->{entries}}; + return $model; } # wizard to add an entry in PXE menu sub wizard_add_entry { - my ($_widget, $treeview, $pxelinux_conf) = @_; + my ($_widget, $treeview) = @_; my $model = $treeview->get_model; local $::isEmbedded = 0; @@ -250,7 +217,6 @@ sub wizard_add_entry { welcome => { name => N("Add an all.rdz boot image") . "\n" . N("To boot through the network, the networked computer needs a boot image. Morever we need to name this image, so each boot image is related to a name in the PXE menu. Thus, the user can choose which image he wants to boot through PXE.") . "\n\n" . N("For technical reasons, in case of multiple boot images, it's simpler to boot the networked computer through a kernel (vmlinuz), and to provide one file with all needed drivers (in our case all.rdz)."), next => 'addimg', - no_back => 1, }, addimg => { name => N("When this wizard has finished, the all.rdz image and kernel vmlinuz will be copied into \n%s.\n\nThe PXE menu list will be updated with this new entry.", $network::pxe::pxelinux_images), @@ -265,7 +231,7 @@ sub wizard_add_entry { help => N("Provide the full path to vmlinuz kernel location") }, ], complete => sub { - test_similar_label($WPXENAME, $pxelinux_conf) or return 'addimg'; + test_similar_label($WPXENAME) or return 'addimg'; if (($WPXENAME) !~ /^\w+$/) { err_dialog(N("Error!"), N("PXE label should be an ASCII word/number without space. Please adjust")) and return 'addimg'; } @@ -316,7 +282,7 @@ sub wizard_add_entry { # remove an entry in PXE menu sub remove_item { - my ($_widget, $treeview, $pxelinux_conf) = @_; + my ($_widget, $treeview) = @_; $::isWizard = 0; my $model = $treeview->get_model; my $selection = $treeview->get_selection; @@ -326,13 +292,13 @@ sub remove_item { my $i = ($path->get_indices)[0]; my $entry = $pxelinux_conf->{entries}[$i]; - # $entry->{label} =~ /local/ and info_dialog(N("Local"), N("You can't remove local entry.")) and return 0; - ask_okcancel("Info", "Remove $entry->{label} PXE entry ?") or return; + $entry->{label} =~ /local/ and info_dialog(N("Local"), N("You can't remove local entry.")) and return 0; + ask_okcancel("Remove $entry->{label} PXE entry ?") or return; network::pxe::remove_in_help($entry->{label}); my $ke = $network::pxe::pxelinux_client_root . "/$entry->{kernel}"; my $initrdf = $network::pxe::pxelinux_client_root . "/$entry->{initrd}"; - if (basename($entry->{kernel} ne "memdisk")) { - print "kernel: $ke\n"; + if (basename($entry->{kernel} ne $network::pxe::pxelinux_client_root . "/memdisk")) { + print "k: $ke\n"; print "initrd: $initrdf\n"; system("rm -vf $ke"); system("rm -vf $initrdf"); @@ -342,11 +308,12 @@ sub remove_item { } $model->remove($iter); splice @{$pxelinux_conf->{entries}}, $i, 1; +# write_conf(); } } sub test_similar_label { - my ($label, $pxelinux_conf) = @_; + my ($label) = @_; if (any { $_->{label} eq $label } @{$pxelinux_conf->{entries}}) { err_dialog(N("Error!"), N("Found a similar entry in PXE list labeled: %s.\nChoose another label please", $label)) and return 0; } else { return 1 } @@ -354,7 +321,7 @@ sub test_similar_label { # dialog box to edit a PXE entry sub edit_box_item { - my ($_widget, $treeview, $pxelinux_conf) = @_; + my ($_widget, $treeview) = @_; $::isWizard = 0; my $model = $treeview->get_model; my $selection = $treeview->get_selection; @@ -568,6 +535,7 @@ sub edit_box_item { # update value in cells set_pxelinux_entry_at_iter($model, $iter, $entry); $dialog->destroy; +# write_conf(); network::pxe::add_in_help($entry->{label}, $entry->{info}); }, }, @@ -656,6 +624,7 @@ sub cell_edited { $entry->{option} = $new_text; $model->set($iter, $column, $entry->{option}); } +# write_conf(); } sub show_help() { info_dialog("help", @@ -820,152 +789,9 @@ sub add_columns { } -# drakdeploy code from blino -my $mac_regexp = '(?:[0-9a-f]{2}:){5}[0-9a-f]{2}'; -my $profiles_conf = network::pxe::read_profiles(); - -sub create_systems_list() { - my $systems = Gtk2::SimpleList->new( - N("MAC address") => 'text', - N("Installed") => 'bool', - N("Profil 1") => 'text', - N("Computer Name") => 'text', - ); - foreach ($systems->get_columns) { $_->set_resizable(1); } - $systems->set_headers_clickable(1); - $systems->get_selection->set_mode('multiple'); -# $systems->get_model->set_sort_column_id(0, 'ascending'); - foreach (0..2) { - $systems->get_column($_)->signal_connect('clicked', \&sort_by_column, $systems->get_model); - $systems->get_column($_)->set_sort_column_id($_ == 0 ? 1 : $_ + 2); - } - #- don't let the user modify the "Installed" state - $systems->get_column(1)->get_cell_renderers->set_property('mode', 'inert'); - $systems->set_column_editable(3, 1); - $systems->set_rules_hint(1); - return $systems; -} - -sub sort_by_column { - my ($column, $model) = @_; - my $col_id = $column->get_sort_column_id; - my ($old_id, $old_order) = $model->get_sort_column_id; - $model->set_sort_column_id($col_id, $old_id == $col_id && $old_order ne 'descending' ? 'ascending' : 'descending'); -} - -sub create_profiles_list() { - my $profiles = Gtk2::SimpleList->new("Profile name" => 'text'); - $profiles->set_headers_visible(1); - $profiles->get_selection->set_mode('browse'); - $profiles->get_selection->signal_connect(changed => sub { - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - update_treeview($pxelinux_conf); - }); - return $profiles; -} - -my $profiles = create_profiles_list; -my $systems = create_systems_list; -my $log_text = gtknew('TextView'); - -sub get_pxelinux_conf_from_profile() { - my $model_profiles = $profiles->get_model; - my $iter = $profiles->get_selection->get_selected; - if ($iter) { - ($config_file, $help_file) = network::pxe::get_pxelinux_profile_path($model_profiles->get($iter, 0), 'boot'); - my $pxelinux_conf = profile_selected($model_profiles->get($iter, 0)); - return $pxelinux_conf; - } -} - -sub system_entry_set_profile { my ($entry, $profile) = @_; $entry->[2] = $profile || N("None") } -sub system_entry_set_installed { my ($entry, $state) = @_; $entry->[1] = $state } - -sub find_system_entry_for_mac_address { - my ($mac_address) = @_; - find { $_->[0] eq $mac_address } @{$systems->{data}}; -} - -sub add_configured_mac_addresses() { - while (my ($mac_address, $conf) = each %{$profiles_conf->{per_mac}}) { - my $entry = [ $mac_address ]; - system_entry_set_profile($entry, $conf->{profile}); - system_entry_set_installed($entry, !$conf->{to_install}); - push @{$systems->{data}}, $entry; - gtktext_append($log_text, "Detected new system: $mac_address\n"); - } -} - -sub get_mac_addresses_from_dhcp_log() { - my %addresses; - foreach (cat_("/var/log/daemons/info")) { - /dhcpd:\s+DHCP(?:DISCOVER|REQUEST).*\s+from\s+($mac_regexp)\b/ and $addresses{$1} = 1; - } - foreach (difference2([ keys %addresses ], [ map { $_->[0] } @{$systems->{data}} ])) { - my $entry = [ $_ ]; - system_entry_set_profile($entry, ''); - push @{$systems->{data}}, $entry; - gtktext_append($log_text, "Detected new system: $_\n"); - } - 1; #- run callback on next timeout -} - -my ($profiles_combo, $install_button); - -sub refresh_profiles() { - my @profiles = network::pxe::list_profiles($profiles_conf); - mygtk2::gtkset($profiles_combo, list => [ '', @profiles ]); - # add default PXE menu - push @profiles, "default"; - @{$profiles->{data}} = @profiles; -} - -sub add_profile() { - my $w = ugtk2->new(N("Deployment center")); - my ($entry, $to_install); - $w->{ok_clicked} = sub { - my $profile = $entry->get_text; - network::pxe::profile_exists($profiles_conf, $profile) and err_dialog(N("Deployment center"), N("The %s profile already exists!", $profile)), return; - network::pxe::add_empty_profile($profiles_conf, $profile, $to_install->get_active); - refresh_profiles(); - Gtk2->main_quit; - }; - gtkadd($w->{window}, - gtknew('VBox', children_loose => [ - $entry = gtknew('Entry', text => network::pxe::find_next_profile_name($profiles_conf, 'profile')), - $to_install = gtknew('CheckButton', text => 'This profile needs an installation'), - create_okcancel($w), - ])); - $w->main; -} - ############### # Main Program ############### -# create model -our $model = create_model(); -our $treeview = Gtk2::TreeView->new_with_model($model); - -sub profile_selected { - my ($profile) = @_; - if ($profile eq 'default') { - ($config_file, $help_file) = ($network::pxe::pxelinux_config_file, $network::pxe::pxelinux_help_file); - } else { - # force type = boot - my $type = "boot"; - ($config_file, $help_file) = network::pxe::get_pxelinux_profile_path($profile, $type); - undef $pxelinux_conf; - } - my $pxelinux_conf = network::pxe::read_pxelinux_conf($config_file, $help_file); - return $pxelinux_conf; -} - -sub update_treeview { - my ($pxelinux_conf) = @_; - $model->clear; - set_pxelinux_entry_at_iter($model, $model->append, $_) foreach (@{$pxelinux_conf->{entries}}); -} - # check if first launch if (!-f ($network::pxe::pxelinux_client_root . "/drakwizard_pxe")) { @@ -986,11 +812,15 @@ sub launch_pxe_server() { # disable wizard $::isWizard = 0; +# create model +my $model = create_model(); -my $w = ugtk2->new(N("Drakpxelinux")); -#$w->{rwindow}->set_size_request(800, 500) unless $::isEmbedded; +my $window = ugtk2->new("Drakpxelinux $version"); +$window->{rwindow}->set_size_request(800, 500) unless $::isEmbedded; +my $W = $window->{window}; +$W->signal_connect(delete_event => sub { ugtk2->exit }); -#my $treeview = Gtk2::TreeView->new_with_model($model); +my $treeview = Gtk2::TreeView->new_with_model($model); $treeview->set_rules_hint(TRUE); $treeview->get_selection->set_mode('single'); add_columns($treeview); @@ -1002,6 +832,7 @@ my $defaultlabel = $pxelinux_conf->{default}; $labelscombo->entry->set_text($defaultlabel); $labelscombo->entry->signal_connect("changed", sub { $pxelinux_conf->{default} = $labelscombo->entry->get_text; +# write_conf(); }); my @o = network::pxe::list_pxelinux_labels($pxelinux_conf); @@ -1015,9 +846,9 @@ $treeview->signal_connect(button_press_event => sub { my $selection = $treeview->get_selection; my $iter = $selection->get_selected; if ($iter) { - # get pxelinux_conf file - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - edit_box_item($model, $treeview, $pxelinux_conf) if $event->type eq '2button-press'; + my $path = $model->get_path($iter); + my $i = ($path->get_indices)[0]; + edit_box_item($model, $treeview) if $event->type eq '2button-press'; } }); @@ -1028,107 +859,57 @@ my $menu = $factory->get_widget('<main>'); my $okcancel = create_okcancel({ cancel_clicked => sub { ugtk2->exit }, - ok_clicked => sub { - write_conf(get_pxelinux_conf_from_profile()); - ugtk2->exit }, + ok_clicked => sub { write_conf; ugtk2->exit }, }, ); # main interface -gtkpack($w->{window}, - $menu, - if_(!$::isEmbedded, Gtk2::Banner->new('drakgw', N("Drakpxelinux manage your PXE server"))), - if_($::isEmbedded, Gtk2::Label->new("Here you can manage your PXE server.")), - gtknew('Notebook', children => [ - gtknew('Label', text => N("PXE configuration file")), - gtknew('VBox', spacing => 0, children => [ - 1, gtknew('HBox', spacing => 1, children => [ - 1, gtknew('ScrolledWindow', width => 500, height => 300, child => $treeview), - 0, gtknew('VBox', children => [ - 0, gtknew('Label', text => N("Profiles list")), - 0, gtknew('ScrolledWindow', height => 260, child => $profiles), - 0, gtknew('VButtonBox', layout => 'start', children_loose => [ - gtksignal_connect(gtknew('Button', text => N("Add profile")), clicked => \&add_profile), - gtksignal_connect(gtknew('Button', text => N("Clone profile")), clicked => sub { - network::pxe::clone_profile($profiles_conf, $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices; - refresh_profiles(); - }), - gtksignal_connect(gtknew('Button', text => N("Remove profile")), clicked => sub { - network::pxe::remove_profile($profiles_conf, $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices; - refresh_profiles(); - }), - ]), - ]), - ] - ), - 0, gtknew('VBox', spacing => 1, children => [ - 0, gtknew('HButtonBox', layout => 'start', children => [ - 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add PXE entry")), 'addpxe'), clicked => sub { - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - eval { wizard_add_entry($model, $treeview, $pxelinux_conf); - write_conf($pxelinux_conf); - }; - my $err = $@; - $::WizardWindow->destroy if defined $::WizardWindow; - undef $::WizardWindow; - if ($err && $err !~ /wizcancel/) { - err_dialog(N("Error"), N("The PXE entry wizard has unexpectedly failed:") . "\n\n" . $err); - } - }), - 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add PXE local")), 'addpxe'), clicked => sub { - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - add_local_entry($model, $treeview, $pxelinux_conf) - }), - 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Remove")), 'removepxe'), clicked => sub { - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - remove_item($model, $treeview, $pxelinux_conf); - write_conf($pxelinux_conf); - }), - 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Edit")), 'editb'), clicked => sub { - my $pxelinux_conf = get_pxelinux_conf_from_profile(); - edit_box_item($model, $treeview, $pxelinux_conf); - write_conf($pxelinux_conf); - }), - #gtknew('Label', text => N("Default boot:")), - #1, $labelscombo, - ] - ), - ]), - ] +$W->add(gtkpack_(Gtk2::VBox->new(0,0), + 0, $menu, + if_(!$::isEmbedded, 0, Gtk2::Banner->new('drakgw', N("Drakpxelinux manage your PXE server"))), + if_($::isEmbedded, 0, Gtk2::Label->new("Here you can manage your PXE server.")), + 1, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3), + 1, create_scrolled_window($treeview), + 0, gtkpack_(create_vbox('start'), + 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add a PXE entry")), 'addpxe'), clicked => sub { + eval { wizard_add_entry($model, $treeview) }; + my $err = $@; + $::WizardWindow->destroy if defined $::WizardWindow; + undef $::WizardWindow; + if ($err && $err !~ /wizcancel/) { + err_dialog(N("Error"), N("The PXE entry wizard has unexpectedly failed:") + . "\n\n" . $err); + } + }), + 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Remove PXE entry")), 'removepxe'), clicked => sub { + remove_item($model, $treeview) } + ), + 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Edit PXE entry")), 'editb'), clicked => sub { + edit_box_item($model, $treeview) } + ), + 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Apply")), 'apply'), clicked => sub { + write_conf } + ), + 0, Gtk2::HSeparator->new, + 0, Gtk2::Label->new(N("Default boot:")), + 0, $labelscombo, + 0, Gtk2::HSeparator->new, + # create_vbox('end'), + 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Reconfigure PXE Server")), 'wizardsrv'), clicked => sub { + eval { wizard_pxe_server() }; + my $err = $@; + $::WizardWindow->destroy if defined $::WizardWindow; + undef $::WizardWindow; + if ($err && $err !~ /wizcancel/) { + err_dialog(N("Error"), N("The PXE server wizard has unexpectedly failed:") + . "\n\n" . $err); + } + }), + 0, gtksignal_connect(new Gtk2::Button(N("Help")), clicked => \&show_help), + ), ), - gtknew('Label', text => N("Systems")), - gtknew('VBox', spacing => 1, - children => [ - 1, gtknew('ScrolledWindow', child => $systems), - 0, gtknew('HBox', - children_loose => [ - # gtknew('Button', text => N("Scan for systems")), - gtksignal_connect(gtknew('Button', text => N("Set system")), clicked => sub { - my $profile = $profiles_combo->get_active_text; - my $to_install = exists $profiles_conf->{profiles}{install}{$profile}; - foreach ($systems->get_selected_indices) { - my $entry = $systems->{data}[$_]; - network::pxe::set_profile_for_mac_address($profile, $to_install, $entry->[0]); - system_entry_set_installed($entry, 0); - system_entry_set_profile($entry, $profile); - } - }), - $profiles_combo = gtknew('ComboBox'), - ]), - ]), - gtknew('Label', text => N("Log")), - gtknew('VBox', spacing => 1, children_loose => [ - gtknew('ScrolledWindow', width => 600, height => 400, child => $log_text), - ]), - ]), - $okcancel, + 0, $okcancel, + ), ); - -add_configured_mac_addresses(); -get_mac_addresses_from_dhcp_log(); -Glib::Timeout->add(60000, \&get_mac_addresses_from_dhcp_log); -refresh_profiles(); -$w->show; - -#$W->show_all; +$W->show_all; Gtk2->main; |