#!/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 my $version = "0.9"; use lib qw(/usr/lib/libDrakX); use standalone; use strict; use common; use MDK::Common; use ugtk2 qw(:ask :helpers :wrappers :create :dialogs); use interactive; # i18n: IMPORTANT: to get correct namespace (drakconf instead of libDrakX) BEGIN { unshift @::textdomains, 'drakpxelinux' } 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 $conf = "/tmp/tr"; 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 displayed in PXE menu (a word/number)") . "\n" . N("Server: IP address of server, which contains 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 MDK install server directory") . "\n" . N("Method: installation method: choose NFS or HTTP") . "\n" . N("Ramsize: ramsize parameter on boot disk") . "\n" . N("Display: export display on another computer (ie: 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 displayed in PXE menu (a word/number)"), 'network' => N("dhcp or an IP address"), 'directory' => N("full path to MDK install server directory"), 'automatic' => N("installation method: choose NFS or HTTP"), 'ramsize' => N("ramsize parameter on boot disk"), 'display' => N("export display on another computer (ie: 10.0.1.33:0)"), 'option' => N("apic nolapic acpi=off initrd=/bin/shell"), 'server' => N("IP address of server, which contains installation directory"), 'labels' => N("list all PXE entry, selected one is the default boot"), 'wizardsrv' => N("Launch a wizard to setup a PXE server"), 'editb' => N("Edit the PXE entry selected with a dialog box"), 'removepxe' => N("Remove the PXE entry selected"), 'addpxe' => N("Launch 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 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 1280000); push @list_ram, ""; my @list_vga = qw(normal 785 788 791 794 text); push @list_vga, ""; 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!; my $optionsall = join(' ', grep { ! /$devram/ && ! /initrd=$initall/ && !/display=$displayall/ && ! /ramdisk_size=$ramdiskall/ && ! /automatic=$autocomp/ && !/vga=$vgaall/ } split(' ', $allopt)); if ($label && $kernel && $initall) { my $information = get_information($label); # 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); 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 = "/mnt/ken/dis/10.0/i586/isolinux/alt0/all.rdz"; # my $WVMLINUZ = "/home/nis/install/clic/isolinux/alt0/vmlinuz"; my $WVMLINUZ = "/mnt/ken/dis/10.0/i586/isolinux/alt0/vmlinuz"; my $w = wizards->new; my $wiz = { name => N("Add PXE entry"), pages => { welcome => { name => N("Add an all.rdz boot image") . "\n" . N("To boot through network, network computer need a boot image. Morever we need to name this image, so each boot image is related to a name in PXE menu. So user can choose wich image he wants to boot through PXE.") . "\n\n" . N("For technical reason, in case of multiple boot image, it's more simple to boot network computer through a kernel (vmlinuz), and provide one file with all drivers needed (in our case all.rdz).") , next => 'addimg', }, addimg => { name => N("At the end of this wizard, the all.rdz image and kernel vmlinuz will be copied into \n%s.\n\nPXE 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 a word or a number, with no space)") }, { label => N("PXE information:"), val => \$WINFO, help => N("PXE information is used to explain the rule of the boot image,\nie:\nMandrake 10 rescue disk\nMandrake 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 source") }, ], 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 != /^\d+$/) { err_dialog(N("Error!"), N("PXE label should be a name/number without space. Please adjust")); return 'addimg'; } }, next => 'endadd', post => sub { my $w = $in->wait_message(N("add a PXE entry"), N("ad 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 => "", display => "", option => "", }; 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; } # 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) = @_; 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; 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; $file = "images/" . basename($file); } $data->set_text($file); $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, ""); # button kernel my $buttonkernel = Gtk2::Button->new(N("Select kernel")); $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, ""); my $buttoninitrd = Gtk2::Button->new(N("Select 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); $ramdisk->entry->set_text($listpxe[$i]{ramdisk}); set_help_tip($ramdisk, 'ramsize'); my $vga = new Gtk2::OptionMenu(); $vga->set_popdown_strings(@list_vga); $vga->entry->set_text($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; $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), ); }; # ok, lets create the dialog box :-) gtkpack_($dialog->vbox, 0, gtkadd(Gtk2::Frame->new(N("Descrition")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, $label_and_widgets->(N("Label"), $label, ""), 0, $label_and_widgets->(N("Info"), $info, ""), ), ), 0, gtkadd(Gtk2::Frame->new(N("Boot image")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, Gtk2::Label->new(N("Path are relative to %s, file out of this directory\ncould not be downloaded via tftp, because tftp server is chrooted", $X86)), 0, $label_and_widgets->(N("Kernel"), $kernel, $buttonkernel), 0, $label_and_widgets->(N("Initrd"), $initrd, $buttoninitrd), ), ), 0, gtkadd(Gtk2::Frame->new(N("Automatic Options")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, $label_and_widgets->(N("Automatic"), $automatic, ""), 0, $label_and_widgets->(N("Interface"), $interface, ""), 0, $label_and_widgets->(N("Network"), $network, ""), 0, $label_and_widgets->(N("Server"), $server, ""), 0, $label_and_widgets->(N("Directory"), $directory, $buttondir), ), ), 0, gtkadd(Gtk2::Frame->new(N("Display")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, $label_and_widgets->(N("Vga"), $vga, ""), 0, $label_and_widgets->(N("Display"), $display, ""), ), ), 0, gtkadd(Gtk2::Frame->new(N("Other options")), gtkpack_(gtkset_border_width(Gtk2::VBox->new, 3), 0, $label_and_widgets->(N("Ramdisk"), $ramdisk, ""), 0, $label_and_widgets->(N("Option"), $option, ""), ), ), 0, create_okcancel({ cancel_clicked => sub { $dialog->destroy }, ok_clicked => sub { #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; $listpxe[$i]{network} = $network->get_text; $listpxe[$i]{server} = $server->get_text; $listpxe[$i]{directory} = $directory->get_text; $listpxe[$i]{ramdisk} = $ramdisk->entry->get_text; $listpxe[$i]{vga} = $vga->entry->get_text; $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) || ($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'), # FIXME: we lacks a web programe here: clicked => sub { open(F, "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; } # 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 configuring 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 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("Congratulations"), data => [ { label => N("The wizard successfully configured your PXE server.") } ], no_back => 1, end => 1, next => 0 }, }, }; $w->process($wiz, $in); } # 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); } return($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 PXE server on your system...")); output("$X86/drakwizard_pxe", <get_model; # horrible hack to avoid: GLib-GObject-CRITICAL **: file gobject.c: line 1019 (g_object_set_property): assertion `G_IS_VALUE (value)' failed at drakpxe2.pl line 640. my $t = "0"; my @j = qw(Label Info Kernel Initrd Method Interface Network Server Directory Ramdisk vga Display Extra Options); 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, $j[$t], $renderer, 'text' => $::i); $t++; } (qw(x x x x x x x x x x x x x)); #(("Label"), ("Info"), ("Kernel"), ("Initrd"), ("Method"), ("Interface"), ("Network"), ("Server"), ("Directory"), ("Ramdisk"), ("vga"), ("Display"), ("Extra"), ("Options")); } ############### # Main Program ############### # check if first launch if (! -f "$X86/drakwizard_pxe") { info_dialog(N("Please configure a PXE server"), N("Its seems this is the first time you run this tool.\n") . ("A wizard will apppear to configure your 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 had unexpectly failled:") . "\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 $banner = Gtk2::Banner->new('wiz_default_up', ("DrakPXE default configuration file")); my $okcancel = create_okcancel({ cancel_clicked => sub { ugtk2->exit }, ok_clicked => &write_conf_pxe, }, ); ; # main interface $W->add(gtkpack_(Gtk2::VBox->new(0,0), if_(! $::isEmbedded, 0, $banner ), 1, create_scrolled_window($treeview), 0, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3), 0, Gtk2::VSeparator->new(), 0, Gtk2::VSeparator->new, 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add 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 add PXE entry wizard had unexpectly failled:") . "\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, gtksignal_connect(new Gtk2::Button(N("Help")), clicked => sub { show_help } ), ), if_($::isEmbedded, 0, $okcancel), ), ); $W->show_all; Gtk2->main;