This commit was generated by cvs2svn to compensate for changes in r2526,
[freeside.git] / rt / bin / webmux.pl
1 # $Header: /home/cvs/cvsroot/freeside/rt/bin/Attic/webmux.pl,v 1.1 2002-08-12 06:17:07 ivan Exp $
2 # RT is (c) 1996-2000 Jesse Vincent (jesse@fsck.com);
3
4 use strict;
5 $ENV{'PATH'} = '/bin:/usr/bin';    # or whatever you need
6 $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'};
7 $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
8 $ENV{'ENV'} = '' if defined $ENV{'ENV'};
9 $ENV{'IFS'} = ''          if defined $ENV{'IFS'};
10
11
12 # We really don't want apache to try to eat all vm
13 # see http://perl.apache.org/guide/control.html#Preventing_mod_perl_Processes_Fr
14
15
16 package RT::Mason;
17
18 use CGI qw(-private_tempfiles); #bring this in before mason, to make sure we
19                                 #set private_tempfiles
20 use HTML::Mason::ApacheHandler (args_method => 'CGI');
21 use HTML::Mason;  # brings in subpackages: Parser, Interp, etc.
22
23 use vars qw($VERSION %session $Nobody $SystemUser $r $m);
24
25 # List of modules that you want to use from components (see Admin
26 # manual for details)
27
28 #Clean up our umask...so that the session files aren't world readable, writable or executable
29 umask(0077);
30
31
32           
33 $VERSION="!!RT_VERSION!!";
34
35 use lib "!!RT_LIB_PATH!!";
36 use lib "!!RT_ETC_PATH!!";
37
38 #This drags in  RT's config.pm
39 use config;
40 use Carp;
41
42 {  
43             package HTML::Mason::Commands;
44             use vars qw(%session $m);
45           
46             use RT; 
47             use RT::Ticket;
48             use RT::Tickets;
49             use RT::Transaction;
50             use RT::Transactions;
51             use RT::User;
52             use RT::Users;
53             use RT::CurrentUser;
54             use RT::Template;
55             use RT::Templates;
56             use RT::Queue;
57             use RT::Queues;
58             use RT::ScripAction;
59             use RT::ScripActions;
60             use RT::ScripCondition;
61             use RT::ScripConditions;
62             use RT::Scrip;
63             use RT::Scrips;
64             use RT::Group;
65             use RT::Groups;
66             use RT::Keyword;
67             use RT::Keywords;
68             use RT::ObjectKeyword;
69             use RT::ObjectKeywords;
70             use RT::KeywordSelect;
71             use RT::KeywordSelects;
72             use RT::GroupMember;
73             use RT::GroupMembers;
74             use RT::Watcher;
75             use RT::Watchers;
76             use RT::Handle;
77             use RT::Interface::Web;    
78             use MIME::Entity;
79             use Text::Wrapper;
80             use Apache::Cookie;
81             use Date::Parse;
82             use HTML::Entities;
83             
84             #TODO: make this use DBI
85             use Apache::Session::File;
86
87             # Set this page's content type to whatever we are called with
88             sub SetContentType {
89                 my $type = shift;
90                 $RT::Mason::r->content_type($type);
91             }
92
93             sub CGIObject {
94                 $m->cgi_object();
95             }
96
97         }
98 my ($parser, $interp, $ah);
99 if ($HTML::Mason::VERSION < 1.0902) {
100  $parser = &RT::Interface::Web::NewParser(allow_globals => [%session]);
101
102  $interp = &RT::Interface::Web::NewInterp(parser=>$parser,
103                                           allow_recursive_autohandlers => 1,
104                                                               );
105
106  $ah = &RT::Interface::Web::NewApacheHandler($interp);
107 } else {
108  $ah = &RT::Interface::Web::NewMason11ApacheHandler();
109 }
110 # Activate the following if running httpd as root (the normal case).
111 # Resets ownership of all files created by Mason at startup.
112 #
113 chown (Apache->server->uid, Apache->server->gid, 
114                 [$RT::MasonSessionDir]);
115
116
117 chown (Apache->server->uid, Apache->server->gid, 
118                 $ah->interp->files_written);
119
120 # Die if WebSessionDir doesn't exist or we can't write to it
121
122 stat ($RT::MasonSessionDir);
123 die "Can't read and write $RT::MasonSessionDir"
124   unless (( -d _ ) and ( -r _ ) and ( -w _ ));
125
126
127 sub handler {
128     ($r) = @_;
129     
130     RT::Init();
131  
132     # We don't need to handle non-text items
133     return -1 if defined($r->content_type) && $r->content_type !~ m|^text/|io;
134     
135     #This is all largely cut and pasted from mason's session_handler.pl
136     
137     my %cookies = Apache::Cookie::parse($r->header_in('Cookie'));
138     
139     eval { 
140         tie %HTML::Mason::Commands::session, 'Apache::Session::File',
141           ( $cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef ), 
142             { Directory => $RT::MasonSessionDir,
143               LockDirectory => $RT::MasonSessionDir,
144             }   ;
145     };
146     
147     if ( $@ ) {
148         # If the session is invalid, create a new session.
149         if ( $@ =~ m#^Object does not exist in the data store# ) {
150              tie %HTML::Mason::Commands::session, 'Apache::Session::File', undef,
151              { Directory => $RT::MasonSessionDir,
152                LockDirectory => $RT::MasonSessionDir,
153              };
154              undef $cookies{'AF_SID'};
155         }
156           else {
157              die "RT Couldn't write to session directory '$RT::MasonSessionDir'. Check that this directory's permissions are correct.";
158           }
159     }
160     
161     if ( !$cookies{'AF_SID'} ) {
162         my $cookie = new Apache::Cookie
163           ($r,
164            -name=>'AF_SID', 
165            -value=>$HTML::Mason::Commands::session{_session_id}, 
166            -path => '/',);
167         $cookie->bake;
168
169     }
170     my $status = $ah->handle_request($r);
171     untie %HTML::Mason::Commands::session;
172     
173     return $status;
174     
175   }
176 1;
177