| Line 1... | Line 1... | 
          
            | 1 | #!/usr/bin/env perl
 | 1 | #!/usr/bin/env perl
 | 
          
            | 2 | use warnings;
 | 2 | use warnings;
 | 
          
            | 3 | use strict;  
 | 3 | use strict;  
 | 
          
            | 4 |  
 | 4 |  
 | 
          
            | 5 | # Description: Windows Basic System Information
 | - |   | 
          
            | 6 |  
 | - |   | 
          
            | 7 | our $VERSION = '0.1.0';
 | 5 | use version ; our $VERSION = 'v1.0.0';
 | 
          
            | 8 |  
 | 6 |  
 | 
          
            | - |   | 7 | # Template for modules to be used in sysinfo
 | 
          
            | - |   | 8 | # Author: R. W. Rodolico
 | 
          
            | - |   | 9 | # Date:   2025-04-02
 | 
          
            | - |   | 10 | #
 | 
          
            | 9 | # This is a simple script to gather some basic Windows system information
 | 11 | # This is a simple script to gather some basic Windows system information
 | 
          
            | 10 | # all we get is the operating system name (small, code name) and the
 | 12 | # all we get is the operating system name (small, code name) and the
 | 
          
            | 11 | # display name (ie, Windows Server 2019
 | 13 | # display name (ie, Windows Server 2019
 | 
          
            | 12 | # uses Win32 (cpan install Win32)
 | 14 | # uses Win32 (cpan install Win32)
 | 
          
            | - |   | 15 | #
 | 
          
            | - |   | 16 | # Revision History
 | 
          
            | - |   | 17 | #
 | 
          
            | - |   | 18 | #
 | 
          
            | 13 |  
 | 19 |  
 | 
          
            | 14 |  
 | - |   | 
          
            | 15 | # find our location and use it for searching for libraries
 | 20 | # find our location and use it for searching for libraries. library.pm must be in the same directory as the calling script
 | 
          
            | - |   | 21 | # or, if run interactively, in the parent of the modules
 | 
          
            | 16 | BEGIN {
 | 22 | BEGIN {
 | 
          
            | 17 |    use FindBin;
 | 23 |    use FindBin;
 | 
          
            | 18 |    use File::Spec;
 | 24 |    use File::Spec;
 | 
          
            | - |   | 25 |    # prepend the bin directory and its parent
 | 
          
            | 19 |    use lib File::Spec->catdir($FindBin::Bin);
 | 26 |    use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/..");
 | 
          
            | 20 |    eval( 'use library;' );
 | 27 |    eval( 'use library;' );
 | 
          
            | 21 |    die "Could not find library.pm in the code directory\n" if $@;
 | 28 |    die sprintf( "Could not find library.pm in %s, INC is %s\n", __FILE__, join( "\n", @INC ) ) if $@;
 | 
          
            | 22 |    eval( 'use Data::Dumper;' );
 | - |   | 
          
            | 23 | }
 | 29 | }
 | 
          
            | 24 |  
 | 30 |  
 | 
          
            | - |   | 31 | #####
 | 
          
            | - |   | 32 | ##### Change these to match your needs
 | 
          
            | - |   | 33 | #####
 | 
          
            | - |   | 34 |  
 | 
          
            | - |   | 35 | # Make this a list of all the modules we are going to use. You can replace undef with the version you need, if you like
 | 
          
            | - |   | 36 | my $modulesList = {
 | 
          
            | - |   | 37 |         'Data::Dumper'     => undef,
 | 
          
            | - |   | 38 |         'win32'            => undef,
 | 
          
            | - |   | 39 |    };
 | 
          
            | - |   | 40 |  
 | 
          
            | - |   | 41 | # hash of commands that are needed for the system. key is the name of the command and, in some cases, the value will become
 | 
          
            | - |   | 42 | # the full path (from which or where)
 | 
          
            | 25 | # check for valid OS. 
 | 43 | my $commandsList = {
 | 
          
            | - |   | 44 |    };
 | 
          
            | - |   | 45 |  
 | 
          
            | - |   | 46 | # list of operating systems this module can be used on.
 | 
          
            | - |   | 47 | my $osList = {
 | 
          
            | 26 | exit 1 unless &checkOS( { 'mswin32' => undef } );
 | 48 |          'mswin32' => undef,
 | 
          
            | - |   | 49 | #         'freebsd' => undef,
 | 
          
            | - |   | 50 | #         'linux'   => undef,
 | 
          
            | - |   | 51 |    };
 | 
          
            | 27 |  
 | 52 |  
 | 
          
            | 28 | # check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
 | - |   | 
          
            | 29 | # script returns a 2
 | - |   | 
          
            | 30 | #foreach my $command ( 'systeminfo' ) {
 | - |   | 
          
            | 31 | #   exit 2 unless $commands{$command} = &validCommandOnSystem( $command );
 | - |   | 
          
            | 32 | #}
 | - |   | 
          
            | 33 | # category we will use for all values found
 | 53 | # the category the return data should go into. See sysinfo for a list
 | 
          
            | 34 | # see sysinfo for a list of valid categories
 | - |   | 
          
            | 35 | my $CATEGORY = 'operatingsystem';
 | 54 | my $CATEGORY = 'operatingsystem';
 | 
          
            | 36 |  
 | 55 |  
 | 
          
            | - |   | 56 | #####
 | 
          
            | - |   | 57 | ##### End of required
 | 
          
            | - |   | 58 | #####
 | 
          
            | - |   | 59 |  
 | 
          
            | - |   | 60 | # some variables needed for our system
 | 
          
            | - |   | 61 | my $errorPrepend = 'error: in ' . __FILE__; # this is prepended to any error messages
 | 
          
            | - |   | 62 | my @out; # temporary location for each line of output
 | 
          
            | - |   | 63 |  
 | 
          
            | - |   | 64 | # Try to load the modules we need. If we can not, then make a list of missing modules for error message.
 | 
          
            | - |   | 65 | for my $module ( keys %$modulesList ) {
 | 
          
            | - |   | 66 |    eval ( "use $module;" );
 | 
          
            | - |   | 67 |    push @out, "$errorPrepend Could not load $module" if $@;
 | 
          
            | - |   | 68 | }
 | 
          
            | - |   | 69 |  
 | 
          
            | - |   | 70 | if ( ! @out && ! checkOS ( $osList ) ) { # check if we are on an acceptible operating system
 | 
          
            | - |   | 71 |     push @out, "$errorPrepend Invalid Operating System";
 | 
          
            | - |   | 72 | }
 | 
          
            | - |   | 73 | if ( !@out && ! validCommandOnSystem ( $commandsList ) ) {
 | 
          
            | - |   | 74 |    push @out, "$errorPrepend Can not find some commands needed";
 | 
          
            | - |   | 75 | }
 | 
          
            | - |   | 76 | if ( !@out ) { # we made it, we have everything, so do the processing
 | 
          
            | - |   | 77 |    #####
 | 
          
            | - |   | 78 |    ##### Your code starts here. Remember to push all output onto @out
 | 
          
            | 37 | use Win32;
 | 79 |    #####
 | 
          
            | - |   | 80 |    
 | 
          
            | - |   | 81 |    # in scalar, will simply return the short name. use 'scalar' to force that.
 | 
          
            | - |   | 82 |    push @out, sprintf( "%s\t%s\t%s\n", $CATEGORY, 'distribution', scalar Win32::GetOSName() );
 | 
          
            | - |   | 83 |    push @out, sprintf( "%s\t%s\t%s\n", $CATEGORY, 'description', Win32::GetOSDisplayName() );
 | 
          
            | - |   | 84 |    
 | 
          
            | - |   | 85 |    #####
 | 
          
            | - |   | 86 |    ##### Your code ends here.
 | 
          
            | - |   | 87 |    #####
 | 
          
            | - |   | 88 | }
 | 
          
            | 38 |  
 | 89 |  
 | 
          
            | 39 | # in scalar, will simply return the short name. use 'scalar' to force that.
 | 90 | # If we are testing from the command line (caller is undef), print the results for debugging
 | 
          
            | 40 | printf( "%s\t%s\t%s\n", $CATEGORY, 'distribution', scalar Win32::GetOSName() );
 | 91 | print join( "\n", @out ) . "\n" unless caller;
 | 
          
            | 41 | printf( "%s\t%s\t%s\n", $CATEGORY, 'description', Win32::GetOSDisplayName() );
 | 92 | # called by do, which has a value of the last assignment made, so make the assignment. The equivilent of a return
 | 
          
            | - |   | 93 | my $return = join( "\n", @out );
 | 
          
            | 42 |  
 | 94 |  
 | 
          
            | 43 | exit 0;
 | - |   |