#!/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.1"; use lib qw(/usr/lib/libDrakX); use standalone; use strict; use common; use network::network; #use MDK::Common; use interactive; # i18n: IMPORTANT: to get correct namespace (drakpxelinux instead of libDrakX) BEGIN { unshift @::textdomains, 'drakpxelinux' } # 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; # 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 $conf = "/var/lib/tftpboot/X86PC/linux/pxelinux.cfg/default"; my $HOSTNAME = chomp_(`hostname`); my $TFTPDIR = "/var/lib/tftpboot"; my $CLIENTPATH = '/X86PC/linux'; my $X86 = $TFTPDIR . $CLIENTPATH; my $IMGPATH = $X86 . '/images'; my $PXEHELP = $X86 . '/help.txt'; my $PXEMESSAGE = $X86 . '/messages'; my $pxeconf = '/etc/pxe.conf'; my $SYSLINUXPATH = '/usr/lib/syslinux/'; my $MEMDISK = $SYSLINUXPATH . '/memdisk'; my $XINETDDIR = "/etc/xinetd.d"; my $interface = 'eth0'; my ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m; my $DOMAINNAME = chomp_(`dnsdomainname`); 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("the name to be displayed in the PXE menu (an ASCII word/number)"), '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})); } if (!-f $conf) { err_dialog(N("Error!"), N("missing %s\n\nPlease install the pxe package.",$conf)) and !$::testing && die; } else { save_config($conf); } my @listpxe; my @list_method = qw(nfs http); push @list_method, ""; my @list_ram = qw(32000 48000 64000 96000 128000); my @list_vga_resolution = qw(vga text automatic 640x480 800x600 1024x768 1280x1024); my %list_vga_code = ( 'vga' => "normal", 'text' => "text", '640x480' => "785", '800x600' => "788", '1024x768' => "791", '1280x1024' => "794", 'automatic' => "", ); my %list_vga_res = ( 'normal' => "vga", 'text' => "text", '785' => "640x480", '788' => "800x600", '791' => "1024x768", '794' => "1280x1024", ); 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; # get all values from default PXE file sub get_items() { my $info; my $label; my $kernel; my $initrd; foreach (cat_($conf)) { if (any { /^label/ } cat_($conf)) { if (/^label/) { ($label) = /^label\s(.*)/ } if (/KERNEL/) { ($kernel) = /KERNEL\s(.*)/ } my ($initrd, $automatic, $interface, $network, $server, $directory, $ramdisk, $vga, $display) = m!\s*APPEND\sinitrd=(.*?rdz)\s\bautomatic=method\b:(nfs|http),interface:(eth0|eth1|eth2),network:(dhcp|10.0.1.33),server:(.*?),directory:(.*?)\s\bramdisk_size\b=(.*?)\sroot=/dev/ram3\srw\svga=(.*?)\sdisplay=(.*?)\s!; # in case of parameter not on this order (previous pxe default file) $initrd or my ($init) = m!\s*APPEND\s\binitrd\b=(.*?)\s!; $ramdisk or my ($ramdis) = m!\bramdisk_size\b=(\d+)\s!; $automatic or my ($automati) = m!\bautomatic\b=method:(nfs|http)!; $vga or my ($vg) = m!\bvga\b=(.*?)\s!; $display or my ($displa) = m!\bdisplay\b=(.*?)\s!; $interface or my ($interfac) = m!\binterface\b:(eth0|eth1|eth2)!; $network or my ($networ) = m!\bnetwork\b:(dhcp|10.0.1.33)!; $server or my ($serve) = m!\bserver\b:(.*?),!; $directory or my ($director) = m!\bdirectory\b:(.*?)\s!; my $initall; my $ramdiskall; my $autoall; my $vgaall; my $displayall; my $interfaceall; my $networkall; my $serverall; my $directoryall; if ($initrd) { $initall = $initrd } else { $initall = $init } if ($ramdisk) { $ramdiskall = $ramdisk } else { $ramdiskall = $ramdis } if ($automatic) { $autoall = $automatic } else { $autoall = $automati } if ($vga) { $vgaall = $vga } else { $vgaall = $vg } if ($display) { $displayall = $display } else { $displayall = $displa } if ($interface) { $interfaceall = $interface } else { $interfaceall = $interfac } if ($network) { $networkall = $network } else { $networkall = $networ } if ($server) { $serverall = $server } else { $serverall = $serve } if ($directory) { $directoryall = $directory } else { $directoryall = $director } my ($allopt) = m!\s*APPEND\s(.*)!; my ($autocomp) = m!\bautomatic\b=(.*?)\s!; my ($devram) = m!root=(/dev/ram3\srw)!; $allopt and my $optionsall = join(' ', grep { ! /root=$devram/ && ! /initrd=$initall/ && !/display=$displayall/ && ! /ramdisk_size=$ramdiskall/ && ! /automatic=$autocomp/ && !/vga=$vgaall/ } split(' ', $allopt)); if ($label && $kernel && $initall) { my $information = get_information($label); # my $vgares = $list_vga_res{$vgaall}; # now push data in @ push @listpxe, { label => $label, info => $information, kernel => $kernel, initrd => $initall, automatic => $autoall, interface => $interfaceall, network => $networkall, server => $serverall, directory => $directoryall, ramdisk => $ramdiskall, vga => $vgaall, display => $displayall, option => $optionsall, },; } } } } # get info from help.txt sub get_information { my ($label) = @_; my $line = cat_($PXEHELP); my ($information) = $line =~ /\b$label\b\s: (.*)/; $information and return $information; } sub list_label_pxe() { my @labels; foreach (cat_($conf)) { my ($label) = /label\s(.*)/; $label and push @labels, $label; } @labels; } # set new default boot PXE sub set_new_default { my ($default) = @_; substInFile { s/^DEFAULT.*/DEFAULT $default/; } $conf; } sub get_default_pxe { my ($defaultpxe) = cat_($conf) =~ /DEFAULT\s+(\S+)/; return $defaultpxe; } sub get_default_prompt() { my $line = cat_($conf); my ($prompt) = $line =~ /^PROMPT\s(\d+)/; $prompt and return $prompt; } sub get_default_timeout() { my ($time) = cat_($conf) =~ /^TIMEOUT\s(\d+)/; return $time; } # write conf in default file sub write_conf_pxe { my $default = get_default_pxe; my $prompt = get_default_prompt; my $time = get_default_timeout; output($conf, <{interface} && !$a->{display}) { append_to_file($conf, " label $a->{label} KERNEL $a->{kernel} APPEND initrd=$a->{initrd} automatic=method:$a->{automatic},interface:$a->{interface},network:$a->{network},server:$a->{server},directory:$a->{directory} ramdisk_size=$a->{ramdisk} root=/dev/ram3 rw vga=$a->{vga} "); } elsif ($a->{interface} && $a->{display}) { append_to_file($conf, " label $a->{label} KERNEL $a->{kernel} APPEND initrd=$a->{initrd} automatic=method:$a->{automatic},interface:$a->{interface},network:$a->{network},server:$a->{server},directory:$a->{directory} ramdisk_size=$a->{ramdisk} root=/dev/ram3 rw vga=$a->{vga} display=$a->{display} "); # case of .img image } else { append_to_file($conf, " label $a->{label} KERNEL $a->{kernel} APPEND initrd=$a->{initrd} "); } } } sub create_model { get_items(); # my $model = Gtk2::ListStore->new(("Glib::String") x13); 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"); foreach my $a (@listpxe) { my $iter = $model->append; $model->set($iter, COLUMN_LABEL, $a->{label}, COLUMN_INFO, $a->{info}, COLUMN_KERNEL, $a->{kernel}, COLUMN_INITRD, $a->{initrd}, COLUMN_AUTOMATIC, $a->{automatic}, COLUMN_INTERFACE, $a->{interface}, COLUMN_NETWORK, $a->{network}, COLUMN_SERVER, $a->{server}, COLUMN_DIRECTORY, $a->{directory}, COLUMN_RAMDISK, $a->{ramdisk}, COLUMN_VGA, $a->{vga}, COLUMN_DISPLAY, $a->{display}, COLUMN_OPTION, $a->{option}, ), } 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; my $in = 'interactive'->vnew('su'); undef $::WizardTable; undef $::WizardWindow; $::isWizard = 1; use wizards; my $WPXENAME = "Mandrakeclustering"; my $WINFO = "install Mandrakeclustering"; my $WALLRDZ = "/home/nis/install/clic/isolinux/alt0/all.rdz"; # my $WALLRDZ = "/tmp/all.rdz"; my $WVMLINUZ = "/home/nis/install/clic/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.", $IMGPATH), 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 source") }, { 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_($PXEHELP)) { 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'; } }, next => 'endadd', post => sub { my $w = $in->wait_message(N("add a PXE entry"), N("add a PXE entry in your PXE server configuration...")); add_in_help($WPXENAME, $WINFO); my $vmlinuzpxe = basename($WVMLINUZ) . "-$WPXENAME"; cp_af($WVMLINUZ, "$IMGPATH/$vmlinuzpxe"); cp_af($WALLRDZ, "$IMGPATH/$WPXENAME.rdz"); push @listpxe, { label => $WPXENAME, info => $WINFO, kernel => "images/$vmlinuzpxe", initrd => "images/$WPXENAME.rdz", automatic => "", interface => "", network => "", server => "", directory => "", ramdisk => "128000", vga => "automatic", display => "", option => "root=/dev/ram3 rw", }; my $iter = $model->append; $model->set($iter, COLUMN_LABEL, $listpxe[-1]{label}, COLUMN_INFO, $listpxe[-1]{info}, COLUMN_KERNEL, $listpxe[-1]{kernel}, COLUMN_INITRD, $listpxe[-1]{initrd}, COLUMN_AUTOMATIC, $listpxe[-1]{automatic}, COLUMN_INTERFACE, $listpxe[-1]{interface}, COLUMN_NETWORK, $listpxe[-1]{network}, COLUMN_SERVER, $listpxe[-1]{server}, COLUMN_DIRECTORY, $listpxe[-1]{directory}, COLUMN_RAMDISK, $listpxe[-1]{ramdisk}, COLUMN_VGA, $listpxe[-1]{vga}, COLUMN_DISPLAY, $listpxe[-1]{display}, COLUMN_OPTION, $listpxe[-1]{option}, ); write_conf_pxe(); undef $w; return; }, no_back => 1, }, endadd => { name => N("Congratulations"), data => [ { label => N("The wizard successfully added the PXE boot image.") } ], post => sub { list_label_pxe() }, 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]; ask_okcancel("Remove $listpxe[$i]{label} PXE entry ?") or return; remove_in_help($listpxe[$i]{label}); my $ke = "$X86/$listpxe[$i]{kernel}"; my $initrdf = "$X86/$listpxe[$i]{initrd}"; if (basename($listpxe[$i]{kernel} ne "$X86/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 @listpxe, $i, 1; write_conf_pxe; } } 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\s$newlabel$/ } cat_($conf)) { 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 $dialog = new Gtk2::Dialog(); $dialog->set_modal(1); $dialog->set_resizable(FALSE); # my $label = Gtk2::Entry->new; my $label = Gtk2::Label->new($listpxe[$i]{label}); # $label->set_text($listpxe[$i]{label}); # my $oldlabel = $label; my $info = Gtk2::Entry->new; $info->set_text($listpxe[$i]{info}); set_help_tip($info, 'info'); # create file dialog widget, with file or directory selection my $fdwidget = sub { my ($data, $test, $filetotest) = @_; chdir($X86); 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; } elsif ($filetotest eq "initrd") { run_program::get_stdout("file $file") =~ /initrd/ or err_dialog(N("Error!"), N("Should be an initrd file")) and return; } my $d = dirname($file); if ($d =~ /images/) { print "here"; $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($listpxe[$i]{kernel}); set_help_tip($kernel, 'kernel'); my $file_dialogk = $fdwidget->($kernel, "", "kernel"); # 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($listpxe[$i]{initrd}); set_help_tip($initrd, 'initrd'); my $file_dialog = $fdwidget->($initrd, "", "initrd"); 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($listpxe[$i]{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($listpxe[$i]{interface}); set_help_tip($interface, 'interface'); # my $network = Gtk2::Entry->new; # $network->set_text($listpxe[$i]{network}); # set_help_tip($network, 'network'); my $server = Gtk2::Entry->new; $server->set_text($listpxe[$i]{server}); set_help_tip($server, 'server'); my $directory = Gtk2::Entry->new; $directory->set_text($listpxe[$i]{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 ($listpxe[$i]{ramdisk} eq "") { $listpxe[$i]{ramdisk} = "128000" } $ramdisk->entry->set_text($listpxe[$i]{ramdisk}); set_help_tip($ramdisk, 'ramsize'); my $vga = new Gtk2::OptionMenu(); $vga->set_popdown_strings(@list_vga_resolution); if ($listpxe[$i]{vga} eq "automatic") { $listpxe[$i]{vga} = "" } $vga->entry->set_text($list_vga_res{$listpxe[$i]{vga}}); set_help_tip($vga, 'vga'); my $display = Gtk2::Entry->new; $display->set_text($listpxe[$i]{display}); set_help_tip($display, 'display'); my $option = Gtk2::Entry->new; if ($listpxe[$i]{option} eq "") { $listpxe[$i]{option} = "root=/dev/ram3 rw" } $option->set_text($listpxe[$i]{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 ($listpxe[$i]{network} eq "dhcp") { $toggledhcp->set_active(1); $ipaddr->set_sensitive(0); } else { $toggledhcp->set_active(0); $ipaddr->set_sensitive(1); $ipaddr->set_text($listpxe[$i]{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"), $kernel, $buttonkernel), 0, $label_and_widgets->(N("Initrd image"), $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 = $list_vga_code{$vga->entry->get_text}; #ask_okcancel("are you sure you want to update all those values ?"); $listpxe[$i]{label} = $label->get_text; $listpxe[$i]{info} = $info->get_text; $listpxe[$i]{kernel} = $kernel->get_text; $listpxe[$i]{initrd} = $initrd->get_text; $listpxe[$i]{automatic} = $automatic->entry->get_text; $listpxe[$i]{interface} = $interface->entry->get_text; # check dhcp or ipaddress my $s = $toggledhcp->get_active; if ($toggledhcp->get_active eq "1") { $listpxe[$i]{network} = "dhcp"; } else { $listpxe[$i]{network} = $ipaddr->get_text; is_ip($listpxe[$i]{network}) or err_dialog(N("Error!"), N("Please enter a valid IP address.")) and return; } $listpxe[$i]{server} = $server->get_text; $listpxe[$i]{directory} = $directory->get_text; $listpxe[$i]{ramdisk} = $ramdisk->entry->get_text; $listpxe[$i]{vga} = $vgacode; $listpxe[$i]{display} = $display->get_text; $listpxe[$i]{option} = $option->get_text; # update value in cells $model->set($iter, COLUMN_LABEL, $listpxe[$i]{label}, COLUMN_INFO, $listpxe[$i]{info}, COLUMN_KERNEL, $listpxe[$i]{kernel}, COLUMN_INITRD, $listpxe[$i]{initrd}, COLUMN_AUTOMATIC, $listpxe[$i]{automatic}, COLUMN_INTERFACE, $listpxe[$i]{interface}, COLUMN_NETWORK, $listpxe[$i]{network}, COLUMN_SERVER, $listpxe[$i]{server}, COLUMN_DIRECTORY, $listpxe[$i]{directory}, COLUMN_RAMDISK, $listpxe[$i]{ramdisk}, COLUMN_VGA, $listpxe[$i]{vga}, COLUMN_DISPLAY, $listpxe[$i]{display}, COLUMN_OPTION, $listpxe[$i]{option}, ); $dialog->destroy; write_conf_pxe; add_in_help($listpxe[$i]{label}, $listpxe[$i]{info}); }, }, ), ); $dialog->show_all; } } # add in help.txt sub add_in_help { my ($NAME, $INFO) = @_; if (!any { /$NAME/ } cat_($PXEHELP)) { append_to_file($PXEHELP, <new_from_string($path_string); my $column = $cell->get_data("column"); my $iter = $model->get_iter($path); if ($column == COLUMN_LABEL) { my $i = ($path->get_indices)[0]; my $oldlabel = $listpxe[$i]{label}; my $newlabel = $new_text; if (test_similar_label($newlabel, $oldlabel) eq "1") { change_label_in_help($oldlabel, $newlabel); $listpxe[$i]{label} = $new_text; $model->set($iter, $column, $listpxe[$i]{label}); } } elsif ($column == COLUMN_INFO) { my $i = ($path->get_indices)[0]; $listpxe[$i]{info} = $new_text; $model->set($iter, $column, $listpxe[$i]{info}); } elsif ($column == COLUMN_KERNEL) { my $i = ($path->get_indices)[0]; if (-f $new_text) { $listpxe[$i]{kernel} = $new_text; $model->set($iter, $column, $listpxe[$i]{kernel}); } } elsif ($column == COLUMN_INITRD) { my $i = ($path->get_indices)[0]; if (-f $new_text) { $listpxe[$i]{initrd} = $new_text; $model->set($iter, $column, $listpxe[$i]{initrd}); } } elsif ($column == COLUMN_AUTOMATIC) { my $i = ($path->get_indices)[0]; if (!member($new_text, @list_method) || $listpxe[$i]{kernel} =~ /memdisk/) { return; } else { $listpxe[$i]{automatic} = $new_text; $model->set($iter, $column, $listpxe[$i]{automatic}); } } elsif ($column == COLUMN_INTERFACE) { my $i = ($path->get_indices)[0]; if (member($new_text, @list_eth) || $listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{interface} = $new_text; $model->set($iter, $column, $listpxe[$i]{interface}); } } elsif ($column == COLUMN_NETWORK) { my $i = ($path->get_indices)[0]; if ($listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{network} = $new_text; $model->set($iter, $column, $listpxe[$i]{network}); } } elsif ($column == COLUMN_SERVER) { my $i = ($path->get_indices)[0]; if ($listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{server} = $new_text; $model->set($iter, $column, $listpxe[$i]{server}); } } elsif ($column == COLUMN_DIRECTORY) { my $i = ($path->get_indices)[0]; if (-d $new_text || $listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{directory} = $new_text; $model->set($iter, $column, $listpxe[$i]{directory}); } } elsif ($column == COLUMN_RAMDISK) { my $i = ($path->get_indices)[0]; if (member($new_text, @list_ram) || $listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{ramdisk} = $new_text; $model->set($iter, $column, $listpxe[$i]{ramdisk}); } } elsif ($column == COLUMN_VGA) { my $i = ($path->get_indices)[0]; if (member($new_text, @list_vga_resolution) || $listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{vga} = $new_text; $model->set($iter, $column, $listpxe[$i]{vga}); } } elsif ($column == COLUMN_DISPLAY) { my $i = ($path->get_indices)[0]; if ($listpxe[$i]{kernel} !~ /memdisk/) { $listpxe[$i]{display} = $new_text; $model->set($iter, $column, $listpxe[$i]{display}); } } elsif ($column == COLUMN_OPTION) { my $i = ($path->get_indices)[0]; $listpxe[$i]{option} = $new_text; $model->set($iter, $column, $listpxe[$i]{option}); } write_conf_pxe; } 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 { local *F; open(F, "mozilla http://clic.mandrakesoft.com/documentation/pxe/ |") } ), ), ) } # adjust pxe confi with good value sub pxe_conf { if (!-f "$pxeconf.orig") { cp_af($pxeconf, "$pxeconf.orig") } substInFile { s/default_address.*/default_address=$IPSERVER/; s/mtftp_address.*/mtftp_address=$IPSERVER/; s/domain.*/domain=$DOMAINNAME/; } $pxeconf; } sub check_pxe_conf { if (! any { /default_address=$IPSERVER/ } cat_($pxeconf)) { # 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.", $pxeconf)) 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 $w = wizards->new; my $wiz = { name => N("PXE Wizard"), # init => sub { # if (($DOMAINNAME eq "") or ($HOSTNAME eq "localhost")) { # return 0, N("You need to readjust your domainname, not equal to localdomain or none. Please launch drakconnect to adjust it.") # } # 1}, 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 => 'summaryserver', }, summaryserver => { name => N("The wizard will now prepare all default files to set up your PXE server"), data => [ { label => N("TFTP directory: %s", $TFTPDIR) }, { label => N("Boot image path: %s", $IMGPATH) }, { label => N("PXE config file: %s", $pxeconf) }, { label => N("PXE help file: %s", $PXEHELP) }, ], 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); } } # set default PXE message sub default_pxe_messages { save_config($PXEMESSAGE); output($PXEMESSAGE, <vnew('su', 'PXE server'); my $w = $in->wait_message(N("PXE server"), N("Configuring a PXE server on your system...")); output("$X86/drakwizard_pxe", <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 "$X86/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 apppear 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 = get_default_pxe; $labelscombo->entry->set_text($defaultlabel); $labelscombo->entry->signal_connect("changed", sub { my $new_default = $labelscombo->entry->get_text; set_new_default($new_default); } ); my @o = list_label_pxe; $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 => &write_conf_pxe, }, ); # 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(new Gtk2::Button(N("Help")), clicked => sub { show_help } ), ), if_($::isEmbedded, 0, $okcancel), ), ); $W->show_all; Gtk2->main;