root/honeyclient/branches/bug/42/lib/HoneyClient/Agent/Driver/Browser/IE.pm

Revision 70, 7.8 kB (checked in by kindlund, 2 years ago)

Updated SVN properties, to support CVS ID tags.

  • Property svn:keywords set to Id "$file"
Line 
1 #######################################################################
2 # Created on:  May 11, 2006
3 # Package:     HoneyClient::Agent::Driver::Browser::IE
4 # File:        IE.pm
5 # Description: A specific driver for automating an instance of
6 #              the Internet Explorer browser, running inside a
7 #              HoneyClient VM.
8 #
9 # CVS: $Id$
10 #
11 # @author knwang, ttruong, kindlund, stephenson
12 #
13 # Copyright (C) 2006 The MITRE Corporation.  All rights reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation, using version 2
18 # of the License.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 # 02110-1301, USA.
29 #
30 #
31 #######################################################################
32
33 #TODO: Documentation below
34
35 =pod
36
37 =head1 NAME
38
39 HoneyClient::Agent::Driver::Browser::IE - Perl extension to fetch the content
40 of a given web page.  This extends the Browser class by implementing
41 the getContent() function.
42
43 =head1 VERSION
44
45 This documentation refers to HoneyClient::Agent::Driver::Browser::IE version 1.0.
46
47 =head1 SYNOPSIS
48
49   use HoneyClient::Agent::Driver::Browser::IE;
50
51 =cut
52
53 package HoneyClient::Agent::Driver::Browser::IE;
54
55 # XXX: Disabled version check, Honeywall does not have Perl v5.8 installed.
56 #use 5.008006;
57 use strict;
58 use warnings;
59 use Config;
60 use Carp ();
61
62 # Traps signals, allowing END: blocks to perform cleanup.
63 use sigtrap qw(die untrapped normal-signals error-signals);
64
65 #######################################################################
66 # Module Initialization                                               #
67 #######################################################################
68
69 BEGIN {
70
71     # Defines which functions can be called externally.
72     require Exporter;
73     our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION );
74
75     # Set our package version.
76     $VERSION = 0.9;
77
78     # Define inherited modules.
79     use HoneyClient::Agent::Driver::Browser;
80
81     @ISA = qw(Exporter HoneyClient::Agent::Driver::Browser);
82
83     # Symbols to export on request
84     # Note: Since this module is object-oriented, we do *NOT* export
85     # any functions other than "new" to call statically.  Each function
86     # for this module *must* be called as a method from a unique
87     # object instance.
88     @EXPORT = qw();
89
90     # Items to export into callers namespace by default. Note: do not export
91     # names by default without a very good reason. Use EXPORT_OK instead.
92     # Do not simply export all your public functions/methods/constants.
93
94     # This allows declaration use HoneyClient::Agent::Driver::Browser::IE ':all';
95     # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
96     # will save memory.
97
98     # Note: Since this module is object-oriented, we do *NOT* export
99     # any functions other than "new" to call statically.  Each function
100     # for this module *must* be called as a method from a unique
101     # object instance.
102     %EXPORT_TAGS = ( 'all' => [qw()], );
103
104     # Symbols to autoexport (:DEFAULT tag)
105     @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
106
107 # XXX: Fix this!
108 # Check to make sure our OS is Windows-based.
109 #if ($Config{osname} !~ /^MSWin32$/) {
110 #    Carp::croak "Error: " . __PACKAGE__ . " will only run on Win32 platforms!\n";
111 #}
112
113     $SIG{PIPE} = 'IGNORE';    # Do not exit on broken pipes.
114 }
115 our ( @EXPORT_OK, $VERSION );
116
117 #TODO: Rewrite the test module
118
119 =pod
120
121 =begin testing
122
123 =end testing
124
125 =cut
126
127 #######################################################################
128
129 #TODO: Remove any of these use statements that aren't needed
130
131 # Include the Global Configuration Processing Library
132 use HoneyClient::Util::Config qw(getVar);
133
134 # Use ISO 8601 DateTime Libraries
135 use DateTime::HiRes;
136
137 # Use fractional second sleeping.
138 # TODO: Need unit testing.
139 use Time::HiRes qw(sleep);
140
141 # Use Storable Library
142 use Storable qw(dclone);
143
144 # Use threads Library
145 # TODO: Need unit testing.
146 use threads;
147
148 # TODO: Need unit testing.
149 use threads::shared;
150
151 # TODO: Need unit testing.
152 use HoneyClient::Util::SOAP qw(getClientHandle);
153
154 # TODO: Need unit testing.
155 use Win32::Job;
156
157 # TODO: clean this up.
158 #my %PARAMS = (
159 #);
160
161 #######################################################################
162 # Private Methods Implemented                                         #
163 #######################################################################
164
165 #sub new {
166 #   
167 #    # - This function takes in an optional hashtable,
168 #    #   that contains various key => 'value' configuration
169 #    #   parameters.
170 #    #
171 #    # - For each parameter given, it overwrites any corresponding
172 #    #   parameters specified within the default hashtable, %PARAMS,
173 #    #   with custom entries that were given as parameters.
174 #    #
175 #    # - Finally, it returns a blessed instance of the
176 #    #   merged hashtable, as an 'object'.
177 #
178 #    # Get the class name.
179 #    my $self = shift;
180 #
181 #    # Get the rest of the arguments, as a hashtable.
182 #    # Hash-based arguments are used, since HoneyClient::Util::SOAP is unable to handle
183 #    # hash references directly.  Thus, flat hashtables are used throughout the code
184 #    # for consistency.
185 #    my %args = @_;
186 #
187 #    # Check to see if the class name is inherited or defined.
188 #    my $class = ref($self) || $self;
189 #
190 #    # Initialize default parameters.
191 #    my %params = %{dclone(\%PARAMS)};
192 #    $self = $class->SUPER::new();
193 #    @{$self}{keys %params} = values %params;
194 #
195 #    # Now, overwrite any default parameters that were redefined
196 #    # in the supplied arguments.
197 #    @{$self}{keys %args} = values %args;
198 #
199 #    # Now, assign our object the appropriate namespace.
200 #    bless $self, $class;
201 #
202 #    # Finally, return the blessed object.
203 #    return $self;
204 #}
205
206 sub drive {
207
208     # Extract arguments.
209     my ($self, %args) = @_;
210
211     # Sanity check: Make sure we've been fed an object.
212     unless (ref($self)) {
213         Carp::croak "Error: Function must be called in reference to a " .
214                     __PACKAGE__ . "->new() object!\n";
215     }
216
217     # Sanity check, don't get the next link, if
218     # we've been fed a url.
219     my $argsExist = scalar(%args);
220     if (!$argsExist ||
221         !exists($args{'url'}) ||
222         !defined($args{'url'})) {
223         # Get the next URL from our hashtables.
224         $args{'url'} = $self->_getNextLink();
225     }
226
227     # Drive the generic browser before opening with IE
228     $self = $self->SUPER::drive(%args);
229
230     # Sanity check: Make sure our next URL is defined.
231     unless (defined($args{'url'})) {
232         Carp::croak "Error: Unable to drive browser - 'links_to_visit' " .
233                     "hashtable is empty!\n";
234     }
235
236     # Indicates how long we wait for each drive operation to complete,
237     # before registering attempt as a failure.
238     my $timeout : shared = $self->timeout();
239
240     # Create a new Job.
241     my $job = Win32::Job->new();
242
243     # Sanity check.
244     if (!defined($job)) {
245         Carp::croak "Error: Unable to spawn new job - " . $^E . ".\n";
246     }
247
248     # Spawn the job.
249     $job->spawn(undef, "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"" . $args{'url'});
250
251     # TODO: check to see if spawn fails.
252
253     # Run the job.
254     $job->run($timeout);
255
256     # TODO: check to see if run fails.
257
258     # Return the modified object state.
259     return $self;
260 }
261
262 #######################################################################
263
264 1;
265
Note: See TracBrowser for help on using the browser.