#!/usr/bin/perl -wT # # MENUXL v0.1 # Gestionnaire de Menu # # Copyright XL Programmation Micro # # Janvier 2003 sub screen; my $rc; my $choice; my $username; BEGIN { # Clear PATH and related environment variables so that calls to # external programs do not cause results to be tainted. See # "perlsec" manual page for details. # $username = $ENV{'USER'}; $ENV {'PATH'} = '/usr/bin:/bin:/usr/local/bin'; $ENV {'SHELL'} = '/bin/bash'; delete $ENV {'ENV'}; delete $ENV {'BASH_ENV'}; } goto INITIAL; #------------------------------------------------------------ INITIAL: #------------------------------------------------------------ { my @args = ( "S", "STOCK 1", "T", "STOCK 2", "", "", "R", "ARCHIVES", "", "", "A", "A propos...", "Q", "Quitter", ); ($rc, $choice) = screen ("--title", "Bonjour , veuillez selectionner le programme a lancer...", "--menu", "\n\n\n\nUtilisez les fleches Haut/Bas pour selectionner,\nvalidez avec [Entree].", 21, 80, 8, "--nocancel", @args); unless ($rc == 0) { goto QUITASK; } if ($choice eq "S") { goto STOCK1; } elsif ($choice eq "T") { goto STOCK2; } elsif ($choice eq "R") { goto ARCHIVE; } elsif ($choice eq "A") { goto ABOUT; } elsif ($choice eq "Q") { goto QUITDIRECT; } goto INITIAL; } #------------------------------------------------------------ STOCK1: #------------------------------------------------------------ { chdir("/var/xlpm/stock/stock1"); system("/usr/xlpm/stock.linux"); goto INITIAL; } #------------------------------------------------------------ STOCK2: #------------------------------------------------------------ { chdir("/var/xlpm/stock/stock2"); system("/usr/xlpm/stock.linux"); goto INITIAL; } #------------------------------------------------------------ ARCHIVE: #------------------------------------------------------------ { chdir("/var/xlpm/stock/archives"); system("/usr/xlpm/archives/stock.linux"); goto INITIAL; } #------------------------------------------------------------ ABOUT: #------------------------------------------------------------ { screen ("--title", "A propos...", "--msgbox", " MENUXL v0.1 MENU DE SESSION copyright XL Programmation Micro Janvier 2K3 Appuyez sur [ENTREE] pour continuer", 15, 40); goto INITIAL; } #------------------------------------------------------------ QUITASK: #------------------------------------------------------------ { ($rc, $choice) = screen ("--title", "Confirmez svp...", "--yesno", " Quitter le menu et votre session ?", 9, 44); goto INITIAL unless ($rc == 0); system("/usr/bin/tput", "clear"); exit (0); } #------------------------------------------------------------ QUITDIRECT: #------------------------------------------------------------ { system("/usr/bin/tput", "clear"); exit (0); } #------------------------------------------------------------ # Function to display whiptail screens #------------------------------------------------------------ sub screen { my @whiptailArgs = @_; # now would be a good time to flush output buffers, so the partial # buffers don't get copied: $| = 1; print ""; pipe (READER, WRITER) || die "Couldn't create pipe: $!; aborting"; my $pid = fork; if (! defined $pid) { die "Couldn't fork: $!; aborting"; } elsif ($pid == 0) { #---------------------------------------- # Child #---------------------------------------- # Attach child's STDIN to the reading end of the pipe close READER or die "Couldn't close reading end of pipe; $!; aborting"; open STDERR, ">& WRITER" or die "Couldn't connect STDERR to pipe; $!; aborting"; close WRITER or die "Couldn't close writing end of pipe; $!; aborting"; unshift @whiptailArgs, '/usr/bin/whiptail', '--clear', '--backtitle', " MENUXL - Copyright 2003 XL Programmation Micro"; exec @whiptailArgs; die "Couldn't exec: #!; aborting"; } #---------------------------------------- # Parent #---------------------------------------- close WRITER; my $choice = ; close READER; waitpid ($pid, 0); my $rc = $?; return ($rc, $choice); }