Bill Luebkert wrote:

>How about telling us why you are using those routines ?
>Do you have a snippet of code that shows your usage of them ?
>I've never had the need for them, so I don't have any experience.
>There are a lot of REs in that code from a cursory look.

I will try and put some of my code here, hopefully it will help:

Sample Section A: Declaring vars - read from an INI file (there are a few dozens of those):
my $cfg = new Config::IniFiles -file => "settings.ini";

my $HOME_DIR = $cfg->val('env', 'HOME_DIR');
my $MAIN_DIR = $cfg->val('env', 'MAIN_DIR');
my $LOG_DIR = $cfg->val('env', 'LOG_DIR');
my $BACKUP_DIR = $cfg->val('env', 'BACKUP_DIR');
my $REPORTS_DIR = $cfg->val('env', 'REPORTS_DIR');
my $CONF_DIR = $cfg->val('env', 'CONF_DIR');
my $PATCH_DIR = $cfg->val('env', 'PATCH_DIR');
 
Sample Section B: Main menu print: (There are about 15 similar menus)

sub printMainMenu ()
{
    print "## SECURITY HARDENING PROGRAM ##\n";
    print "## Please select one option from the menu ##\n";
    print "1. Disable Services\n";
    print "2. Check Security Patches\n";
    print "3. Misc System Security Tweaks\n";
    print "4. File System Tweaks\n";
    print "5. Account Management\n";
    print "6. Log Management\n";
    print "7. Network tweaks\n";
    print "8. Send all script output (logs, reports, backups) to email \n";
    print "q .Quit (q also)\n\n>";
}

Sample Section C: Actions menu: (There are about 10 similar menus)
Using switch as the menu option is very common in the script.

sub menuDisableServices ()
{
    my $choise = $_[0];
    my $ans;
    switch ($choise)
    {
        case "1"{  # disable from inetd.conf
                   &printDisInetdSubMenu ();
                   chomp($ans = <STDIN>);
                   $ans = &checkInput($ans);
                   if ( $ans ne "q" )  { &disableInetdServices( $ans ); }
                }
        case "2"{  #disable startup Scripts
                   &printDisRcSubMenu ();
                   chomp($ans = <STDIN>);
                   $ans = &checkInput($ans);
                   if ( $ans ne "q" ) { &updateRcdFiles( $ans ); }
                }
        case ["3"] { last; }  # exit to the main menu
        else  { print "value invalid, please select value from the menu or 'q' to exit.";}
    }

Sample Section D: Methods: (There are alot of those)
Almost every method includes backing up file using "File:Copy" and wring to a LOG file.

open (ACTLOG, ">>$LOG_DIR$ACTION_LOG.$date");  # define filehandler for log file

copy (qq($ETC$INETDCF), qq($BACKUP_DIR$INETDCF$date)) or warn "Couldn't copy $ETC$INETDCF to $BACKUP_DIR$INETDCF$date: $!\n";   # backup /etc/inetd.conf

print ACTLOG "[$hour] DISSERV:INETD:Backing up $ETC$INETDCF to $BACKUP_DIR$INETDCF.$date\n";

Hopefully this will help give you an idea on how the script is built (most of it contains very similar code snippets as shown here).

Thank you.

_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to