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