|
1 #!/usr/bin/perl -w |
|
2 use strict; |
|
3 use FindBin; # for FindBin::Bin |
|
4 use lib $FindBin::Bin; # for BldMachineDir (if in same dir. as this .PL file) |
|
5 use Getopt::Long; # Get long options |
|
6 use AntiVirus qw{Start Stop Scan WaitTillAntiVirusStarts}; |
|
7 |
|
8 ####my $gTimeNow = time(); |
|
9 |
|
10 # Get the command line args |
|
11 my ($gCommand,$gOutFilesDir ,$gDirsToScan,$gWaitingTime, $gRetries) = &ProcessCommandLine(); |
|
12 |
|
13 # If the command is to stop the services/processes, then do so. |
|
14 |
|
15 if($gCommand eq 'STOP') |
|
16 { |
|
17 Stop($gWaitingTime, $gRetries); |
|
18 } |
|
19 elsif($gCommand eq 'START') |
|
20 { |
|
21 Start(); |
|
22 } |
|
23 else # ($gCommand eq 'SCAN') NB Any unknown command has been caught by ProcessCommandLine() |
|
24 { |
|
25 Scan($gOutFilesDir, $gDirsToScan); |
|
26 } |
|
27 |
|
28 ####printf ("DEBUG MSG: Elapsed time = %d seconds", time() - $gTimeNow); ####???? For debugging! |
|
29 |
|
30 ################################################################################ |
|
31 # ProcessCommandLine # |
|
32 # Inputs: None (Gets data from @ARGV) # |
|
33 # Outputs: ($iCommand, $iOutFilesDir, \@iDirsToScan) # |
|
34 # Remarks: None # |
|
35 ################################################################################ |
|
36 sub ProcessCommandLine |
|
37 { |
|
38 my ($iHelp, $iCommand,$iOutFilesDir,@iDirsToScan,$iWaitingTime, $iRetries ); |
|
39 unless (GetOptions('h' => \$iHelp, 'o=s' => \$iOutFilesDir, 'c=s' => \$iCommand,'w=s' => \$iWaitingTime,'r=s' => \$iRetries, 'd=s' => \@iDirsToScan)) |
|
40 { |
|
41 Usage('Command Line error(s), as above.'); |
|
42 } |
|
43 if (scalar @ARGV) |
|
44 { |
|
45 Usage("Redundant data on Command Line: @ARGV"); |
|
46 } |
|
47 if ($iHelp) |
|
48 { |
|
49 Usage(); |
|
50 } |
|
51 unless(defined($iCommand)) |
|
52 { |
|
53 Usage('No command given'); |
|
54 } |
|
55 # Uppercase $iCommand once and for all. Then we can check using 'eq'. |
|
56 # NB: uppercasing undef results in a defined, but empty, string! |
|
57 $iCommand = uc $iCommand; |
|
58 |
|
59 |
|
60 |
|
61 if($iCommand eq 'SCAN') |
|
62 { |
|
63 unless((scalar @iDirsToScan) and ($iOutFilesDir)) |
|
64 { # Make sure there are some directories to scan! |
|
65 # It is an error to ask for a scan and to not |
|
66 # supply directories, so print usage information |
|
67 Usage('With SCAN command, must specify directory(ies) and output file'); |
|
68 } |
|
69 return ($iCommand, $iOutFilesDir, \@iDirsToScan); |
|
70 } |
|
71 |
|
72 if(($iCommand eq 'START')or ($iCommand eq 'STOP')) |
|
73 { |
|
74 if((scalar @iDirsToScan) or ($iOutFilesDir)) |
|
75 { # Can't specify directories when starting and stopping |
|
76 # the AV processes and services. |
|
77 Usage('With START/STOP command, cannot specify directories &/or output file'); |
|
78 } |
|
79 # Only valid to start/stop if no directories have been given |
|
80 return ($iCommand, $iOutFilesDir, \@iDirsToScan,$iWaitingTime, $iRetries); |
|
81 } |
|
82 # Something else has gone wrong. So print usage. |
|
83 Usage("Unknown command $iCommand"); |
|
84 } |
|
85 |
|
86 ################################################################################ |
|
87 # Usage # |
|
88 # Inputs: Optional error message # |
|
89 # Outputs: Usage information for the user. # |
|
90 # Remarks: None # |
|
91 ################################################################################ |
|
92 sub Usage |
|
93 { |
|
94 my $iErrorMsg = shift; |
|
95 |
|
96 if ($iErrorMsg) |
|
97 { |
|
98 print STDERR "\nERROR: $iErrorMsg.\n"; |
|
99 } |
|
100 |
|
101 print <<USAGE_EOF; |
|
102 |
|
103 Usage: AntiVirus.pl -c STOP [-w waitTime -r retries] |
|
104 AntiVirus.pl -c START |
|
105 AntiVirus.pl -c SCAN -d scandir1 [-d scandir2 [-d scandir3]] -o outdir |
|
106 |
|
107 Parameters: |
|
108 -c command to perform, limited to "START", "STOP", "SCAN" |
|
109 -d used ONLY in combination with "-c SCAN" to specify the directories to |
|
110 scan. Multiple allowed. |
|
111 -o used ONLY in combination with "-c SCAN" to specify the full name |
|
112 of the directory in which the output file is to be written. |
|
113 -w used ONLY in combination with "-c STOP" .If Antivirus is inactive at |
|
114 the time of STOP attempt,this argument specifies the waiting time in |
|
115 seconds before next attempt is made to check AV service status |
|
116 -r used ONLY in combination with "-c STOP" .If Antivirus is inactive at |
|
117 the time of STOP attempt,this argument specifies the maximum number |
|
118 of attempts to check AntiVirus service status. |
|
119 |
|
120 |
|
121 |
|
122 Optional Parameters: |
|
123 -h help - print this information and exit |
|
124 |
|
125 Examples: |
|
126 1) AntiVirus.pl -c STOP |
|
127 2) AntiVirus.pl -c START |
|
128 3) AntiVirus.pl -c SCAN -d M:\\epoc32\\ -o M:\\logs\\cedar\\ |
|
129 4) AntiVirus.pl -c STOP -w 30 -r 5 |
|
130 |
|
131 Description and Remarks: |
|
132 This script controls operation of the installed anti-virus software. The |
|
133 script stops and starts anti-virus services &/or programs. Reports of |
|
134 missing anti-virus programs or failures to start/stop a service are |
|
135 reported with keyword "WARNING:" or "REMARK:" prepended. |
|
136 |
|
137 Scanning is carried out on all the directories listed on the command line, |
|
138 each one being specified with the -d option. |
|
139 |
|
140 Currently only McAfee anti-virus software is supported. |
|
141 |
|
142 USAGE_EOF |
|
143 exit 1; |
|
144 } |