OpenInteract2/Brick/Apache.pm

filter: Statementstmt 95.6% 22 / 23 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 8 totaltotal 77.2% 34 / 44 CC 2 SCAR 1.7
CC
2
Cov
92%
load
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« OpenInteract2/Brick/CGI.pm ↑ Summary OpenInteract2/Exception.pm »
1 package OpenInteract2::Brick::Apache;
2  
3 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 87 ▶use base qw( OpenInteract2::Brick );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 87 ▶use OpenInteract2::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 87 my %INLINED_SUBS = (
8 'httpd_cgi_solo.conf' => 'HTTPD_CGI_SOLOCONF',
9 'httpd_modperl.conf' => 'HTTPD_MODPERLCONF',
10 'httpd_modperl_solo.conf' => 'HTTPD_MODPERL_SOLOCONF',
11 'httpd_static.conf' => 'HTTPD_STATICCONF',
12 'startup.pl' => 'STARTUPPL',
13 );
14  
15 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
16 87 return 'apache';
17 }
18  
19 6 ▶sub get_resources {
Subroutine get_resources: called CC=1 SCAR=0.0
Pod undocumented
20 return (
21 6 'httpd_cgi_solo.conf' => [ 'conf httpd_cgi_solo.conf', 'yes' ],
22 'httpd_modperl.conf' => [ 'conf httpd_modperl.conf', 'yes' ],
23 'httpd_modperl_solo.conf' => [ 'conf httpd_modperl_solo.conf', 'yes' ],
24 'httpd_static.conf' => [ 'conf httpd_static.conf', 'yes' ],
25 'startup.pl' => [ 'conf startup.pl', 'yes' ],
26 );
27 }
28  
29 5 ▶sub load {
Subroutine load: called CC=2 SCAR=7.4
Pod undocumented
30 5 my ( $self, $resource_name ) = @_;
31 5 my $inline_sub_name = $INLINED_SUBS{ $resource_name };
32 5 ▶ unless ( $inline_sub_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inline_sub_name) 0 5 5
33 0 OpenInteract2::Exception->throw(
34 "Resource name '$resource_name' not found ",
35 "in ", ref( $self ), "; cannot load content." );
36 }
37 5 return $self->$inline_sub_name();
38 }
39  
40 87 OpenInteract2::Brick->register_factory_type( get_name() => __PACKAGE__ );
41  
42 =pod
43  
44 =head1 NAME
45  
46 OpenInteract2::Brick::Apache - All resources used for creating Apache 1.x configurations in a new website
47  
48 =head1 SYNOPSIS
49  
50 oi2_manage create_website --website_dir=/path/to/site
51  
52 =head1 DESCRIPTION
53  
54 This class just holds all the static resources used for creating Apache configuration files when creating a website.
55  
56 These resources are associated with OpenInteract2 version 1.99_06.
57  
58 =head2 Resources
59  
60 You can grab resources individually using the names below and
61 C<load_resource()> and C<copy_resources_to()>, or you can copy all the
62 resources at once using C<copy_all_resources_to()> -- see
63 L<OpenInteract2::Brick> for details.
64  
65 =over 4
66  
67  
68 =item B<httpd_cgi_solo.conf>
69  
70 =item B<httpd_modperl.conf>
71  
72 =item B<httpd_modperl_solo.conf>
73  
74 =item B<httpd_static.conf>
75  
76 =item B<startup.pl>
77  
78  
79 =back
80  
81 =head1 COPYRIGHT
82  
83 Copyright (c) 2005 Chris Winters. All rights reserved.
84  
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself.
87  
88 =head1 AUTHORS
89  
90  
91 Chris Winters E<lt>chris@cwinters.comE<gt>
92  
93  
94 =cut
95  
96  
97 1 ▶sub HTTPD_CGI_SOLOCONF {
Subroutine HTTPD_CGI_SOLOCONF: called CC=1 SCAR=0.0
Pod undocumented
98 1 return <<'SOMELONGSTRING';
99 # Change manually:
100 # -- Change '127.0.0.1' to your IP address
101 # -- Change 'webmaster@mycompany.com' to your contact e-mail address
102 # -- Change 'www.mycompany.com' to your website hostname
103  
104 # If you're using Named virtual hosts, just remove the 'Listen' line
105  
106 Listen 127.0.0.1:80
107 <VirtualHost 127.0.0.1:80>
108 Port 80
109 ServerAdmin webmaster@mycompany.com
110 ServerName www.mycompany.com
111 #SuexecUserGroup user group
112 DocumentRoot [% website_dir %]/html
113  
114 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
115 CustomLog [% website_dir %]/logs/access_log combined
116 ErrorLog [% website_dir %]/logs/error_log
117  
118 # Uncomment for using FastCGI
119 #AddHandler fastcgi-script .fcgi
120 AddHandler cgi-script .cgi
121  
122 Alias /cgi-bin [% website_dir %]/cgi-bin
123 <Directory [% website_dir %]/cgi-bin>
124 AllowOverride None
125 Options ExecCGI
126 Order allow,deny
127 Allow from all
128 </Directory>
129  
130 # Override any global /images alias
131 #Alias /images [% website_dir %]/html/images
132  
133 # This sends all incoming requests (except for images, robot help and
134 # dumb Code Red requests) to the OpenInteract cgi script handler
135 # (/cgi-bin/oi2.cgi)
136  
137 # Tell mod_rewrite to start working for this VirtualHost
138  
139 RewriteEngine On
140  
141 # Any URL beginning with /images will be answered by this server and
142 # no further mod_rewrite rules will be processed
143  
144 RewriteRule ^/images - [L]
145  
146 # Enable your front-end server to handle search engine requests
147  
148 RewriteRule ^/robots\.txt - [L]
149  
150 # Discard (with a '403 Forbidden') requests for the Code Red document
151 # (hole in IIS servers that can keep your server busy...)
152  
153 RewriteRule ^/default\.ida - [F]
154  
155 # Pass all other request to the oi2 cgi script
156 RewriteRule ^/(.*) [% website_dir %]/cgi-bin/oi2.cgi/$1 [NS,T=cgi-script]
157  
158 </VirtualHost>
159  
160  
161 SOMELONGSTRING
162 }
163  
164 1 ▶sub HTTPD_MODPERLCONF {
Subroutine HTTPD_MODPERLCONF: called CC=1 SCAR=0.0
Pod undocumented
165 1 return <<'SOMELONGSTRING';
166 # Change manually:
167 # -- Change '127.0.0.1' to your IP address
168 # -- Change 'webmaster@mycompany.com' to your contact e-mail address
169 # -- Change 'www.mycompany.com' to your website hostname
170 # -- If you wish to run the mod_perl server on a port other than 8080, change it
171  
172 # NOTE: This is meant to be used in a proxy environment. If you're not
173 # running a proxy server in front of this and instead want to run OI
174 # standalone, see the file 'httpd_modperl_solo.conf'
175  
176 # If you're using Named virtual hosts, just remove the 'Listen' line
177  
178 Listen 127.0.0.1:8080
179 <VirtualHost 127.0.0.1:8080>
180 Port 8080
181 ServerAdmin webmaster@mycompany.com
182 ServerName www.mycompany.com
183 DocumentRoot [% website_dir %]/html
184  
185 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
186 CustomLog [% website_dir %]/logs/access_log_modperl combined
187 ErrorLog [% website_dir %]/logs/error_log_modperl
188  
189 # This reads in all your SPOPS objects, sets up aliases, database
190 # handles, template processing objects, etc.
191  
192 PerlRequire [% website_dir %]/conf/startup.pl
193  
194 # This is used to read the 'X-Forwarded-For' header created by the
195 # mod_proxy_add_forward.c Apache module that should be compiled into
196 # your front-end proxy server. If you don't have this, then every
197 # request will appear to come from the proxy server, which can be
198 # annoying.
199  
200 PerlPostReadRequestHandler OpenInteract::ProxyRemoteAddr
201  
202 # This sends all incoming requests to the OpenInteract Apache content
203 # handler (Apache::OpenInteract2)
204  
205 # NOTE: If you're not running under the root context, just
206 # change the path specified in 'Location' to the server
207 # configuration key 'context_info.deployed_under'
208  
209 <Location />
210 SetHandler perl-script
211 PerlHandler Apache::OpenInteract2
212 </Location>
213  
214 </VirtualHost>
215 SOMELONGSTRING
216 }
217  
218 1 ▶sub HTTPD_MODPERL_SOLOCONF {
Subroutine HTTPD_MODPERL_SOLOCONF: called CC=1 SCAR=0.0
Pod undocumented
219 1 return <<'SOMELONGSTRING';
220 # Change manually:
221 # -- Change '127.0.0.1' to your IP address
222 # -- Change 'webmaster@mycompany.com' to your contact e-mail address
223 # -- Change 'www.mycompany.com' to your website hostname
224 # -- If you wish to run the mod_perl server on a port other than 80,
225 # change it in the 'Listen' and 'VirtualHost' directives
226  
227 # If you're using Named virtual hosts, just remove the 'Listen' line
228  
229 Listen 127.0.0.1:80
230 <VirtualHost 127.0.0.1:80>
231 Port 80
232 ServerAdmin webmaster@mycompany.com
233 ServerName www.mycompany.com
234 DocumentRoot [% website_dir %]/html
235  
236 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
237 CustomLog [% website_dir %]/logs/access_log_modperl combined
238 ErrorLog [% website_dir %]/logs/error_log_modperl
239  
240 # This reads in all your SPOPS objects, sets up aliases, database
241 # handles, template processing objects, etc.
242  
243 PerlRequire [% website_dir %]/conf/startup.pl
244  
245 # This sends all incoming requests to the OpenInteract Apache content
246 # handler (Apache::OpenInteract2)
247  
248 # NOTE: If you're not running under the root context, just
249 # change the path specified in 'Location' to the server
250 # configuration key 'context_info.deployed_under'
251  
252 <Location />
253 SetHandler perl-script
254 PerlHandler Apache::OpenInteract2
255 </Location>
256  
257 # If you want to serve them up directly (more efficient) add to the
258 # regex 'css|ico', but if you move OI under a different context you'll
259 # have to create a separate mapping
260  
261 <LocationMatch "\.(jpg|gif|png|js|pdf|jar|zip|gz)$">
262 SetHandler default-handler
263 </LocationMatch>
264  
265 # Override any global /images/ alias
266 #Alias /images /[% website_dir %]/html/images
267  
268 <LocationMatch "/images">
269 SetHandler default-handler
270 </LocationMatch>
271  
272 ScriptAlias /cgi-bin [% website_dir %]/cgi-bin
273 <Location /cgi-bin>
274 SetHandler cgi-script
275 AllowOverride None
276 Options None
277 Order allow,deny
278 Allow from all
279 </Location>
280  
281 </VirtualHost>
282  
283 SOMELONGSTRING
284 }
285  
286 1 ▶sub HTTPD_STATICCONF {
Subroutine HTTPD_STATICCONF: called CC=1 SCAR=0.0
Pod undocumented
287 1 return <<'SOMELONGSTRING';
288 # Change manually:
289 # -- Change '127.0.0.1' to your IP address
290 # -- Change 'webmaster@mycompany.com' to your contact e-mail address
291 # -- Change 'www.mycompany.com' to your website hostname
292  
293 # If you're using Named virtual hosts, just remove the 'Listen' line
294  
295 Listen 127.0.0.1:80
296 <VirtualHost 127.0.0.1:80>
297 Port 80
298  
299 ServerAdmin webmaster@mycompany.com
300 ServerName www.mycompany.com
301 DocumentRoot [% website_dir %]/html
302  
303 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
304 CustomLog [% website_dir %]/logs/access_log_static combined
305 ErrorLog [% website_dir %]/logs/error_log_static
306  
307 #
308 # Proxy server setup
309 #
310  
311 # Tell mod_rewrite to start working for this VirtualHost
312  
313 RewriteEngine On
314  
315 # Any URL beginning with /images will be answered by this server and
316 # no further mod_rewrite rules will be processed
317  
318 RewriteRule ^/images - [L]
319 RewriteRule ^/favicon.ico - [L]
320  
321 # Enable your front-end server to handle search engine requests
322  
323 RewriteRule ^/robots\.txt - [L]
324  
325 # Discard (with a '403 Forbidden') requests for the Code Red document
326 # (hole in IIS servers that can keep your backend mod_perl servers
327 # busy...)
328  
329 RewriteRule ^/default\.ida - [F]
330  
331 # Proxy ([P]) all other requests to a back-end server
332  
333 RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [P]
334  
335 # Ensure that the locations coming back from the back-end server
336 # through this proxy to the client are correct; otherwise, users would
337 # see things like:
338 #
339 # http://www.mysite.com:8080/User/listing/
340 #
341 # in their location, which messes up *everything*.
342  
343 ProxyPassReverse / http://127.0.0.1/
344  
345 # This last line ensures that bad people don't try to use your proxy
346 # server to get other content from around the web
347  
348 RewriteRule ^proxy:.* - [F]
349  
350 </VirtualHost>
351  
352 SOMELONGSTRING
353 }
354  
355 1 ▶sub STARTUPPL {
Subroutine STARTUPPL: called CC=1 SCAR=0.0
Pod undocumented
356 1 return <<'SOMELONGSTRING';
357 #!/usr/bin/perl
358  
359 use strict;
360 use Apache::OpenInteract2;
361 use Apache::OpenInteract2::HttpAuth;
362 use Log::Log4perl;
363 use OpenInteract2::Config::Bootstrap;
364 use OpenInteract2::Constants qw( :log );
365 use OpenInteract2::Context;
366  
367 my $BOOTSTRAP_CONFIG_FILE = '[% website_dir %]/conf/bootstrap.ini';
368  
369 {
370 Log::Log4perl::init( '[% website_dir %]/conf/log4perl.conf' );
371 my $bootstrap = OpenInteract2::Config::Bootstrap->new({
372 filename => $BOOTSTRAP_CONFIG_FILE
373 });
374 my $ctx = OpenInteract2::Context->create(
375 $bootstrap, { temp_lib_create => 'create' } );
376 $ctx->assign_request_type( 'apache' );
377 $ctx->assign_response_type( 'apache' );
378 }
379  
380 1;
381  
382 SOMELONGSTRING
383 }
384  
« OpenInteract2/Brick/CGI.pm ↑ Summary OpenInteract2/Exception.pm »