#!/usr/bin/perl # # Copyright (C) 2004 by Mandrakesoft aginies _ateuh_ 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. # Quick configuration of PXE menu parameters # use with care developement release.... # thx R1 for test and some debug # cvs.mandrakesoft.com module: /soft/drakpxelinux my $version = "1.0.2"; # i18n: IMPORTANT: to get correct namespace (drakpxelinux instead of libDrakX) BEGIN { unshift @::textdomains, 'drakpxelinux' } use lib qw(/usr/lib/libDrakX); use standalone; use strict; use common; use network::network; use network::pxe; use network::tools; use interactive; # must come *after* definition of textdomains for proper initialisation use ugtk2 qw(:ask :helpers :wrappers :create :dialogs); use constant FALSE => 0; use constant TRUE => 1; unless ($> == 0) { err_dialog(N("Error!"), N("You are not root. Exiting...")); die unless $::testing; } # ie of entry menu in PXE: #label linux # KERNEL images/vmlinuz # APPEND initrd=images/all.rdz automatic=method:http,interface:eth0,network:dhcp,server:10.0.1.33,directory:/install/ ramdisk_size=64000 root=/dev/ram3 rw vga=788 display=:0 # default VAR my $SYSLINUXPATH = '/usr/lib/syslinux/'; my $MEMDISK = $SYSLINUXPATH . '/memdisk'; my $XINETDDIR = "/etc/xinetd.d"; my $net; network::network::read_net_conf($net); my $sys_wizard_pxe = "/etc/sysconfig/drak_pxe"; my ($interface) = cat_($sys_wizard_pxe) =~ /INTERFACE=(.*)/; $interface ||= $net->{net_interface}; my $help = "" . N("PXE Label: the name to be displayed in the PXE menu (an ASCII word/number)") . "\n" . N("Server: IP address of server, that contains the installation directory") . "\n" . N("Kernel: memdisk or vmlinuz") . "\n" . N("Initrd: network boot image (network.img) or all.rdz") . "\n" . N("Interface: network interface used for the installation process") . "\n" . N("Network: DHCP or an IP address") . "\n" . N("Directory: full path to Mandrakelinux install server directory") . "\n" . N("Installation method: NFS or HTTP") . "\n" . N("Ramsize: ramsize parameter on boot image") . "\n" . N("Display: export display to another computer (e.g.: 10.0.1.33:0)") . "\n" . N("VGA: if you encounter any problem with VGA, please adjust") . "\n" . ""; my %help = ( 'initrd' => N("network boot image (network.img) or all.rdz"), 'kernel' => N("memdisk in case of network.img, or vmlinuz"), 'vga' => N("if you encounter any problem with VGA, please adjust"), 'interface' => N("network interface used for the installation process"), 'info' => N("Information displayed in PXE help (F1 key)"), 'network' => N("DHCP or an IP address"), 'directory' => N("full path to Mandrakelinux install server directory"), 'automatic' => N("installation method: choose NFS or HTTP"), 'ramsize' => N("ramsize parameter on boot image"), 'display' => N("export display on another computer (e.g.: 10.0.1.33:0)"), 'option' => "apic nolapic acpi=off initrd=/bin/shell", 'server' => N("IP address of server, that contains the installation directory"), 'labels' => N("lists all PXE entries, the default boot is the selected one"), 'wizardsrv' => N("launches a wizard to setup a PXE server"), 'editb' => N("edits the PXE entry selected with a dialog box"), 'removepxe' => N("removes the selected PXE entry"), 'addpxe' => N("launches a wizard to add a PXE entry "), 'helponline' => N("get help from online documentation"), ); sub set_help_tip { my ($entry, $key) = @_; gtkset_tip(new Gtk2::Tooltips, $entry, formatAlaTeX($help{$key})); } my $in = 'interactive'->vnew('su'); if (!$::testing && !$in->do_pkgs->ensure_is_installed('pxe', $network::pxe::pxe_config_file)) { err_dialog(N("Error!"), N("missing %s\n\nPlease install the pxe package.", $network::pxe::pxe_config_file)); $in->exit(-1); } save_config($network::pxe::pxelinux_config_file); my @list_method = qw(nfs http ka); push @list_method, ""; my @list_ram = qw(32000 48000 64000 96000 128000); my @list_eth = qw(eth0 eth1 eth2); push @list_eth, ""; use constant COLUMN_LABEL => 0; use constant COLUMN_INFO => 1; use constant COLUMN_KERNEL => 2; use constant COLUMN_INITRD => 3; use constant COLUMN_AUTOMATIC => 4; use constant COLUMN_INTERFACE => 5; use constant COLUMN_NETWORK => 6; use constant COLUMN_SERVER => 7; use constant COLUMN_DIRECTORY => 8; use constant COLUMN_RAMDISK => 9; use constant COLUMN_VGA => 10; use constant COLUMN_DISPLAY => 11; use constant COLUMN_OPTION => 12; use constant NUM_COLUMNS => 13; my $pxelinux_conf = network::pxe::read_pxelinux_conf(); sub set_pxelinux_entry_at_iter { my ($model, $iter, $entry) = @_; $model->set($iter, COLUMN_LABEL, $entry->{label}, COLUMN_INFO, $entry->{info}, COLUMN_KERNEL, $entry->{kernel}, COLUMN_INITRD, $entry->{initrd}, COLUMN_AUTOMATIC, $entry->{automatic}, COLUMN_INTERFACE, $entry->{interface}, COLUMN_NETWORK, $entry->{network}, COLUMN_SERVER, $entry->{server}, COLUMN_DIRECTORY, $entry->{directory}, COLUMN_RAMDISK, $entry->{ramdisk}, COLUMN_VGA, $entry->{vga}, COLUMN_DISPLAY, $entry->{display}, COLUMN_OPTION, $entry->{option}, ); } 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}}; return $model; } # wizard to add an entry in PXE menu sub wizard_add_entry { my ($widget, $treeview) = @_; my $model = $treeview->get_model; local $::isEmbedded = 0; undef $::WizardTable; undef $::WizardWindow; $::isWizard = 1; use wizards; my $WPXENAME = "Mandrakelinux"; my $WINFO = "install Mandrakelinux"; my $WALLRDZ = "/mnt/10.1/isolinux/alt0/all.rdz"; # my $WALLRDZ = "/tmp/all.rdz"; my $WVMLINUZ = "/mnt/10.1/isolinux/alt0/vmlinuz"; # my $WVMLINUZ = "/tmp/vmlinuz"; my $w = wizards->new; my $wiz = { name => N("Add a PXE entry"), pages => { 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', }, 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), data => [ { label => N("PXE label:"), val => \$WPXENAME, help => N("name displayed in PXE menu (please provide an ASCII word or a number, without spaces)") }, { label => N("PXE information:"), val => \$WINFO, help => N("The PXE information is used to explain the role of the boot image,\ne.g.:\nMandrakelinux 10 rescue disk\nMandrakelinux cooker install via http") }, { label => N("Full path to all.rdz image source:"), val => \$WALLRDZ, help => N("Provide the full path to all.rdz image location") }, { label => N("Full path to vmlinuz source:"), val => \$WVMLINUZ, help => N("Provide the full path to vmlinuz kernel location") }, ], complete => sub { if (any { /^$WPXENAME :/ } cat_($network::pxe::pxelinux_help_file)) { err_dialog(N("Error!"), N("Found a similar entry in PXE list labeled: %s.\nChoose another label please", $WPXENAME)) and 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'; } if (! -f $WALLRDZ) { err_dialog(N("Error!"), N("Please enter a correct path to all.rdz")) and return 'addimg'; } if (! -f $WVMLINUZ) { err_dialog(N("Error!"), N("Please enter a correct path to vmlinuz")) and return 'addimg'; } }, next => 'endadd', post => sub { my $w = $in->wait_message(N("add a PXE entry"), N("add a PXE entry in your PXE server configuration...")); network::pxe::add_in_help($WPXENAME, $WINFO); my $vmlinuzpxe = basename($WVMLINUZ) . "-$WPXENAME"; cp_af($WVMLINUZ, $network::pxe::pxelinux_images . "/$vmlinuzpxe"); cp_af($WALLRDZ, $network::pxe::pxelinux_images . "/$WPXENAME.rdz"); my $entry = { label => $WPXENAME, info => $WINFO, kernel => "images/$vmlinuzpxe", initrd => "images/$WPXENAME.rdz", ramdisk => "128000", vga => "automatic", others => "root=/dev/ram3 rw", }; push @{$pxelinux_conf->{entries}}, $entry; set_pxelinux_entry_at_iter($model, $model->append, $entry); network::pxe::write_pxelinux_conf($pxelinux_conf); undef $w; return; }, no_back => 1, }, endadd => { name => N("Congratulations"), data => [ { label => N("The wizard successfully added the PXE boot image.") } ], post => sub { network::pxe::list_pxelinux_labels() }, no_back => 1, end => 1, next => 0, }, } }; $w->process($wiz, $in); $::isWizard = 0; gtkset_mousecursor_normal(); } # remove an entry in PXE menu sub remove_item { my ($widget, $treeview) = @_; $::isWizard = 0; my $model = $treeview->get_model; my $selection = $treeview->get_selection; my $iter = $selection->get_selected; if ($iter) { my $path = $model->get_path($iter); my $i = ($path->get_indices)[0]; my $entry = $pxelinux_conf->{entries}[$i]; 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 $network::pxe::pxelinux_client_root . "/memdisk")) { print "k: $ke\n"; print "initrd: $initrdf\n"; system("rm -vf $ke"); system("rm -vf $initrdf"); } else { print "initrd: $initrdf\n"; system("rm -vf $initrdf"); } $model->remove($iter); splice @{$pxelinux_conf->{entries}}, $i, 1; network::pxe::write_pxelinux_conf($pxelinux_conf); } } sub test_similar_label { my ($newlabel, $oldlabel) = @_; # if ($newlabel eq $oldlabel) { # err_dialog(N("hmm.."), N("You should provide a new label name.")) and return 0; # } els if (any { $_->{label} eq $newlabel } @{$pxelinux_conf->{entries}}) { err_dialog(N("Error!"), N("Found a similar entry in PXE list labeled: %s.\nChoose another label please", $newlabel)) and return 0; } else { return 1 } } # dialog box to edit a PXE entry sub edit_box_item { my ($widget, $treeview) = @_; $::isWizard = 0; my $model = $treeview->get_model; my $selection = $treeview->get_selection; my $iter = $selection->get_selected; if ($iter) { my $path = $model->get_path($iter); my $i = ($path->get_indices)[0]; my $entry = $pxelinux_conf->{entries}[$i]; my $dialog = new Gtk2::Dialog(); $dialog->set_modal(1); $dialog->set_resizable(FALSE); # my $label = Gtk2::Entry->new; my $label = Gtk2::Label->new($entry->{label}); # $label->set_text($entry->{label}); # my $oldlabel = $label; my $info = Gtk2::Entry->new; $info->set_text($entry->{info}); set_help_tip($info, 'info'); # create file dialog widget, with file or directory selection my $fdwidget = sub { my ($data, $test, $filetotest, $label) = @_; chdir($network::pxe::pxelinux_client_root); my $fd = new Gtk2::FileSelection(N("Selection")); $fd->set_modal(TRUE); $fd->signal_connect("destroy", sub { $fd->hide }); $fd->ok_button->signal_connect(clicked => sub { my $file = $fd->get_filename; my $filesel = basename($file); if ($test eq "dir") { -d $file or err_dialog(N("Error!"), N("Should be a directory.")) and return; } else { -f $file or err_dialog(N("Error!"), N("Should be a file")) and return; } if ($filetotest eq "kernel") { run_program::get_stdout("file $file") =~ /boot sector/ or err_dialog(N("Error!"), N("Should be a boot sector file")) and return; run_program::get_stdout("cp -avf $file " . $network::pxe::pxelinux_images . "/vmlinuz-$label"); $data->set_text("images/vmlinuz-$label"); } elsif ($filetotest eq "initrd") { run_program::get_stdout("file $file") =~ /initrd/ or err_dialog(N("Error!"), N("Should be an initrd file")) and return; system("cp -avf $file " . $network::pxe::pxelinux_images . "/$label.rdz"); $data->set_text("images/$label.rdz"); } # my $d = dirname($file); # if ($d =~ /images/) { $filesel = "images/" . $filesel } # print "$filesel\n"; # $data->set_text($filesel); $fd->hide; }, $fd); $fd->cancel_button->signal_connect(clicked => sub { $fd->hide }); return $fd; }; my $kernel = Gtk2::Entry->new; $kernel->set_text($entry->{kernel}); set_help_tip($kernel, 'kernel'); my $file_dialogk = $fdwidget->($kernel, "", "kernel", $entry->{label}); # button kernel my $buttonkernel = Gtk2::Button->new(N("Select kernel to boot")); $buttonkernel->signal_connect(clicked => sub { $file_dialogk->show }); my $initrd = Gtk2::Entry->new; $initrd->set_text($entry->{initrd}); set_help_tip($initrd, 'initrd'); my $file_dialog = $fdwidget->($initrd, "", "initrd", $entry->{label}); my $buttoninitrd = Gtk2::Button->new(N("Select associated initrd")); $buttoninitrd->signal_connect(clicked => sub { $file_dialog->show }); # combo box to pop down automatic installation my $automatic = Gtk2::OptionMenu->new; $automatic->set_popdown_strings(@list_method); $automatic->entry->set_text($entry->{automatic}); set_help_tip($automatic, 'automatic'); # combo box to pop down list of network interface my $interface = new Gtk2::OptionMenu(); $interface->set_popdown_strings(@list_eth); $interface->entry->set_text($entry->{interface}); set_help_tip($interface, 'interface'); # my $network = Gtk2::Entry->new; # $network->set_text($entry->{network}); # set_help_tip($network, 'network'); my $server = Gtk2::Entry->new; $server->set_text($entry->{server}); set_help_tip($server, 'server'); my $directory = Gtk2::Entry->new; $directory->set_text($entry->{directory}); set_help_tip($directory, 'directory'); my $file_dialogd = $fdwidget->($directory, "dir"); my $buttondir = Gtk2::Button->new(N("Select directory")); $buttondir->signal_connect(clicked => sub { $file_dialogd->show }); my $ramdisk = new Gtk2::OptionMenu(); $ramdisk->set_popdown_strings(@list_ram); if ($entry->{ramdisk} eq "") { $entry->{ramdisk} = "128000" } $ramdisk->entry->set_text($entry->{ramdisk}); set_help_tip($ramdisk, 'ramsize'); my $vga = new Gtk2::OptionMenu(); $vga->set_popdown_strings(keys %network::pxe::vga_bios_to_resolution); # if ($entry->{vga} eq "automatic") { $entry->{vga} = "" } # $vga->entry->set_text($list_vga_res{$entry->{vga}}); $vga->entry->set_text($entry->{vga}); set_help_tip($vga, 'vga'); my $display = Gtk2::Entry->new; $display->set_text($entry->{display}); set_help_tip($display, 'display'); my $option = Gtk2::Entry->new; if ($entry->{option} eq "") { $entry->{option} = "root=/dev/ram3 rw" } $option->set_text($entry->{option}); set_help_tip($option, 'option'); my %size_groups = map { $_ => Gtk2::SizeGroup->new('horizontal') } qw(label widget button); my $label_and_widgets = sub { my ($label, $widget, $button) = @_; gtkpack_(Gtk2::HBox->new(0,5), 0, gtkadd_widget($size_groups{label}, $label), 1, gtkadd_widget($size_groups{widget}, $widget), 2, gtkadd_widget($size_groups{button}, $button), ); }; # display IPADDRESS only if dhcp is not selected my $ipaddr = Gtk2::Entry->new; my $toggledhcp = Gtk2::CheckButton->new(N("DHCP or IP address")); if ($entry->{network} eq "dhcp") { $toggledhcp->set_active(1); $ipaddr->set_sensitive(0); } else { $toggledhcp->set_active(0); $ipaddr->set_sensitive(1); $ipaddr->set_text($entry->{network}); } $toggledhcp->signal_connect(clicked => sub { my $s = $toggledhcp->get_active; if ($s eq "1") { $ipaddr->set_sensitive(0); } else { $ipaddr->set_sensitive(1); } }); # ok, lets create the dialog box :-) gtkpack_($dialog->vbox, 0, gtkadd(Gtk2::Frame->new(N("PXE entry")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 5), 0, $label_and_widgets->(N("Label"), $label, ""), 0, $label_and_widgets->(N("Entry description"), $info, ""), 0, Gtk2::VSeparator->new, 0, $label_and_widgets->(N("Kernel image: ") . $network::pxe::pxelinux_client_root . "/", $kernel, $buttonkernel), 0, $label_and_widgets->(N("Initrd image: ") . $network::pxe::pxelinux_client_root . "/", $initrd, $buttoninitrd), ), ), 0, gtkadd(Gtk2::Frame->new(N("Mandrakelinux installer options")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 5), 0, $label_and_widgets->(N("Ramdisk size"), $ramdisk, ""), 0, $label_and_widgets->(N("Custom options"), $option, ""), 0, $label_and_widgets->(N("Frame buffer resolution"), $vga, ""), 0, $label_and_widgets->(N("Remote IP of X server"), $display, ""), 0, gtkadd(Gtk2::Frame->new(N("Automatic Options")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 5), 0, $label_and_widgets->(N("Installation method"), $automatic, ""), 0, $label_and_widgets->(N("Network interface"), $interface, ""), 0, gtkpack_(Gtk2::HBox->new(0,5), 0, gtkadd_widget($size_groups{label}, $toggledhcp), 1, gtkadd_widget($size_groups{widget}, $ipaddr), 2, gtkadd_widget($size_groups{button}, ""), ), 0, $label_and_widgets->(N("Remote server name"), $server, ""), 0, $label_and_widgets->(N("Remote installation directory"), $directory, ""), ), ), ), ), 0, create_okcancel({ cancel_clicked => sub { $dialog->destroy }, ok_clicked => sub { my $vgacode = $network::pxe::vga_resolution_to_bios{$vga->entry->get_text}; #ask_okcancel("are you sure you want to update all those values ?"); $entry->{label} = $label->get_text; $entry->{info} = $info->get_text; $entry->{kernel} = $kernel->get_text; $entry->{initrd} = $initrd->get_text; $entry->{automatic} = $automatic->entry->get_text; $entry->{interface} = $interface->entry->get_text; # check dhcp or ipaddress my $s = $toggledhcp->get_active; if ($toggledhcp->get_active eq "1") { $entry->{network} = "dhcp"; } else { $entry->{network} = $ipaddr->get_text; if ($entry->{kernel} !~ /memdisk/) { is_ip($entry->{network}) or err_dialog(N("Error!"), N("Please enter a valid IP address.")) and return; } } $entry->{server} = $server->get_text; $entry->{directory} = $directory->get_text; $entry->{ramdisk} = $ramdisk->entry->get_text; $entry->{vga} = $vga->entry->get_text; #$vgacode; $entry->{display} = $display->get_text; $entry->{option} = $option->get_text; # update value in cells set_pxelinux_entry_at_iter($model, $iter, $entry); $dialog->destroy; network::pxe::write_pxelinux_conf($pxelinux_conf); network::pxe::add_in_help($entry->{label}, $entry->{info}); }, }, ), ); $dialog->show_all; } } # edit cell direct on main interface # disable due to bug in "cell edit placement" :-( sub cell_edited { my ($cell, $path_string, $new_text, $model) = @_; my $path = Gtk2::TreePath->new_from_string($path_string); my $column = $cell->get_data("column"); my $iter = $model->get_iter($path); my $i = ($path->get_indices)[0]; my $entry = $pxelinux_conf->{entries}[$i]; if ($column == COLUMN_LABEL) { my $oldlabel = $entry->{label}; my $newlabel = $new_text; if (test_similar_label($newlabel, $oldlabel) eq "1") { network::pxe::change_label_in_help($oldlabel, $newlabel); $entry->{label} = $new_text; $model->set($iter, $column, $entry->{label}); } } elsif ($column == COLUMN_INFO) { $entry->{info} = $new_text; $model->set($iter, $column, $entry->{info}); } elsif ($column == COLUMN_KERNEL) { if (-f $new_text) { $entry->{kernel} = $new_text; $model->set($iter, $column, $entry->{kernel}); } } elsif ($column == COLUMN_INITRD) { if (-f $new_text) { $entry->{initrd} = $new_text; $model->set($iter, $column, $entry->{initrd}); } } elsif ($column == COLUMN_AUTOMATIC) { if (!member($new_text, @list_method) || $entry->{kernel} =~ /memdisk/) { return; } else { $entry->{automatic} = $new_text; $model->set($iter, $column, $entry->{automatic}); } } elsif ($column == COLUMN_INTERFACE) { if (member($new_text, @list_eth) || $entry->{kernel} !~ /memdisk/) { $entry->{interface} = $new_text; $model->set($iter, $column, $entry->{interface}); } } elsif ($column == COLUMN_NETWORK) { if ($entry->{kernel} !~ /memdisk/) { $entry->{network} = $new_text; $model->set($iter, $column, $entry->{network}); } } elsif ($column == COLUMN_SERVER) { if ($entry->{kernel} !~ /memdisk/) { $entry->{server} = $new_text; $model->set($iter, $column, $entry->{server}); } } elsif ($column == COLUMN_DIRECTORY) { if (-d $new_text || $entry->{kernel} !~ /memdisk/) { $entry->{directory} = $new_text; $model->set($iter, $column, $entry->{directory}); } } elsif ($column == COLUMN_RAMDISK) { if (member($new_text, @list_ram) || $entry->{kernel} !~ /memdisk/) { $entry->{ramdisk} = $new_text; $model->set($iter, $column, $entry->{ramdisk}); } } elsif ($column == COLUMN_VGA) { if (exists $network::pxe::vga_resolution_to_bios{$new_text} || $entry->{kernel} !~ /memdisk/) { $entry->{vga} = $new_text; $model->set($iter, $column, $entry->{vga}); } } elsif ($column == COLUMN_DISPLAY) { if ($entry->{kernel} !~ /memdisk/) { $entry->{display} = $new_text; $model->set($iter, $column, $entry->{display}); } } elsif ($column == COLUMN_OPTION) { $entry->{option} = $new_text; $model->set($iter, $column, $entry->{option}); } network::pxe::write_pxelinux_conf($pxelinux_conf); } sub show_help { info_dialog("help", gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, $help, 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("online PXE documentation")), 'helponline'), clicked => sub { system("/usr/bin/www-browser http://clic.mandrakesoft.com/documentation/pxe/ &") } ), ), ); } sub check_pxe_conf { my $ip_address = network::tools::get_interface_ip_address($net, $interface); if (! any { /default_address=$ip_address/ } cat_($network::pxe::pxe_config_file)) { # pxe.conf doesnt matche system, relaunch wizard_pxe_server err_dialog(N("Error!"), N("Your %s doesn't match your actual IP address configuration. Relaunching the PXE server wizard to readjust it.", $network::pxe::pxe_config_file)) and launch_pxe_server(); } } # launch wizard to setup a PXE server sub wizard_pxe_server { local $::isEmbedded = 0; my $in = 'interactive'->vnew('su'); undef $::WizardTable; undef $::WizardWindow; $::isWizard = 1; use wizards; my $interface; use MDK::Wizard::Wizcommon; my $wz = new MDK::Wizard::Wizcommon; my $w = wizards->new; my $wiz = { name => N("PXE Wizard"), needed => { "tftp-server", "pxe", "dhcpd" }, pages => { welcome => { name => N("PXE wizard") . "\n\n" . N("Set a PXE server.") . "\n" . N("This wizard will help you to configure the PXE server, and PXE boot image management. PXE (Pre-boot eXecution Environment) is a protocol designed by Intel that allows computers to boot through the network. PXE is stored in the ROM of new generation network cards. When the computer boots up, the BIOS loads the PXE ROM in the memory and executes it. A menu is displayed, allowing the computer to boot an operating system loaded through the network."), no_back => 1, next => 'pxeserver', }, pxeserver => { name => N("Set PXE server") . "\n\n" . N("We need to use a special dhcpd.conf file with PXE parameter. To set up such a DHCP server, launch the DHCP wizard and check the box 'Enable PXE'. If you don't do that, PXE query will not be answered by this server.") . "\n" . N("Now the wizard will configure all needed default configuration files to allow computers to boot through the network."), no_back => 1, next => 'interface', }, interface => { name => N("PXE server Interface"), data => [ { list => [ keys %{$wz->{net}{itf}} ], val => \$interface }, ], no_back => 1, next => 'summaryserver' }, summaryserver => { name => N("The wizard will now prepare all default files to set up your PXE server"), pre => sub { output($sys_wizard_pxe, "INTERFACE=$interface\n"); }, data => [ { label => N("TFTP directory: %s", $network::pxe::tftp_root) }, { label => N("Boot image path: %s", $network::pxe::pxelinux_images) }, { label => N("PXE config file: %s", $network::pxe::pxe_config_file) }, { label => N("PXE help file: %s", $network::pxe::pxelinux_help_file) }, ], post => \&do_it_pxe, no_back => 1, next => 'endserver', }, endserver => { name => N("End of PXE server configuration"), data => [ { label => N("The wizard successfully configured your PXE server. Now you can configure the PXE menu entry.") } ], no_back => 1, end => 1, next => 0 }, }, }; $w->process($wiz, $in); gtkset_mousecursor_normal(); } # save old config with date sub save_config { my ($old) = @_; my $DATE = chomp_(`date +%d-%m-20%y`); if (-f $old) { print " - Backup of $old configuration\n"; cp_af($old, $old . '.' . $DATE); } } # can adjust block size in tftp server (ita64) sub tftp_blksize { # $o should be with W or not N my ($o) = @_; if ($o =~ /W/) { substInFile { s/server_args.*/server_args = -r blksize -s $network::pxe::tftp_root/ } "$XINETDDIR/tftp"; } else { substInFile { s/server_args.*/server_args = -s $network::pxe::tftp_root/ } "$XINETDDIR/tftp"; } } # enable tftp server in xinetd conf sub enable_tftps { substInFile { s/disable.*/disable = no/ } "$XINETDDIR/tftp"; } sub memlinux_prep { if (!-f $network::pxe::pxelinux_client_root . "/memdisk") { cp_af($MEMDISK, $network::pxe::pxelinux_client_root); } } sub check_started { my ($service) = @_; my ($isrunning) = chomp_(`pidof $service`) =~ /(\d+)/m; if (!$isrunning) { return 1; } } # main procedure to setup PXE server sub do_it_pxe { return if $::testing; my $w = $in->wait_message(N("PXE server"), N("Configuring a PXE server on your system...")); output($network::pxe::pxelinux_client_root . "/drakwizard_pxe", < 1, 'default' => 'local', 'display' => 'messages', 'timeout' => '50', 'f1' => 'help.txt', }); network::pxe::write_pxelinux_conf($pxelinux_conf); save_config($network::pxe::pxelinux_help_file); network::pxe::write_default_pxe_help(); save_config($network::pxe::pxelinux_message_file); network::pxe::write_default_pxe_messages($net); network::pxe::write_pxe_conf($net, $interface); enable_tftps(); tftp_blksize('N'); system("service $_ restart") foreach qw(xinetd pxe); undef $w; check_started($_) foreach qw(xinetd pxe); } # add colum to model # fixed :-) sub add_columns { my $treeview = shift; my $model = $treeview->get_model; each_index { my $renderer = Gtk2::CellRendererText->new; $renderer->set(editable => 0); $renderer->signal_connect(edited => \&cell_edited, $model); $renderer->set_data(column => $::i); $treeview->insert_column_with_attributes(-1, $_, $renderer, 'text' => $::i); } N("Label"), N("Entry description"), N("Kernel image"), N("Initrd image"), N("Installation method"), N("Network interface"), N("DHCP or IP address"), N("Remote server name"), N("Remote installation directory"), N("Ramdisk size"), N("Frame buffer resolution"), N("Remote IP of X server"), N("Custom options"); } ############### # Main Program ############### # check if first launch if (! -f $network::pxe::pxelinux_client_root . "/drakwizard_pxe") { info_dialog(N("Please configure a PXE server"), N("It seems this is the first time you run this tool.\nA wizard will appear to configure your PXE server.")); launch_pxe_server(); } check_pxe_conf(); sub launch_pxe_server { 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); } } # disable wizard $::isWizard = 0; # create model my $model = create_model(); my $window = ugtk2->new("Drakpxelinux $version"); $window->{rwindow}->set_size_request(800, 400) unless $::isEmbedded; my $W = $window->{window}; $W->signal_connect(delete_event => sub { ugtk2->exit }); my $treeview = Gtk2::TreeView->new_with_model($model); $treeview->set_rules_hint(TRUE); $treeview->get_selection->set_mode('single'); add_columns($treeview); # labels that list pxe menu entry my $labelscombo = Gtk2::OptionMenu->new; #my @labelslist = list_label_pxe; my $defaultlabel = $pxelinux_conf->{default}; $labelscombo->entry->set_text($defaultlabel); $labelscombo->entry->signal_connect("changed", sub { $pxelinux_conf->{default} = $labelscombo->entry->get_text }); my @o = network::pxe::list_pxelinux_labels($pxelinux_conf); $labelscombo->set_popdown_strings("", sort(@o)); $labelscombo->entry->set_text($defaultlabel); set_help_tip($labelscombo, 'labels'); my $okcancel = create_okcancel({ cancel_clicked => sub { ugtk2->exit }, ok_clicked => sub { network::pxe::write_pxelinux_conf($pxelinux_conf) }, }, ); # main interface $W->add(gtkpack_(Gtk2::VBox->new(0,0), 1, create_scrolled_window($treeview), 0, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3), 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, Gtk2::Label->new(N("boot:")), 0, $labelscombo, 0, Gtk2::VSeparator->new, 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Reconfigure PXE Server")), 'wizardsrv'), clicked => sub { eval { wizard_pxe_server($model, $treeview) }; 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 => sub { show_help } ), ), if_($::isEmbedded, 0, $okcancel), ), ); $W->show_all; Gtk2->main;