This commit was generated by cvs2svn to compensate for changes in r2523,
[freeside.git] / rt / lib / RT.pm
1 package RT;
2 use RT::Handle;
3 use RT::CurrentUser;
4 use strict;
5
6 use vars qw($VERSION $SystemUser $Nobody $Handle $Logger);
7
8 $VERSION = '!!RT_VERSION!!';
9
10 =head1 NAME
11
12         RT - Request Tracker
13
14 =head1 SYNOPSIS
15
16         A fully featured request tracker package
17         
18
19 =head1 DESCRIPTION
20
21
22 =cut
23
24 sub Init {
25     #Get a database connection
26     $Handle = new RT::Handle($RT::DatabaseType);
27     $Handle->Connect();
28     
29     
30     #RT's system user is a genuine database user. its id lives here
31     $SystemUser = new RT::CurrentUser();
32     $SystemUser->LoadByName('RT_System');
33     
34     #RT's "nobody user" is a genuine database user. its ID lives here.
35     $Nobody = new RT::CurrentUser();
36     $Nobody->LoadByName('Nobody');
37    
38    InitLogging(); 
39 }
40
41 =head2 InitLogging
42
43 Create the RT::Logger object. 
44
45 =cut
46 sub InitLogging {
47
48     # We have to set the record seperator ($, man perlvar)
49     # or Log::Dispatch starts getting
50     # really pissy, as some other module we use unsets it.
51
52     $, = '';
53     use Log::Dispatch 1.6;
54     use Log::Dispatch::File;
55     use Log::Dispatch::Screen;
56
57     $Logger=Log::Dispatch->new();
58     
59     if ($RT::LogToFile) {
60         my $filename = $RT::LogToFileNamed || "$RT::LogDir/rt.log";
61
62           $Logger->add(Log::Dispatch::File->new
63                        ( name=>'rtlog',
64                          min_level=> $RT::LogToFile,
65                          filename=> $filename,
66                          mode=>'append',
67             callbacks => sub {my %p=@_; return "[".gmtime(time)."] [".$p{level}."]: $p{message}\n"}
68
69                        ));
70     }
71     if ($RT::LogToScreen) {
72         $Logger->add(Log::Dispatch::Screen->new
73                      ( name => 'screen',
74                        min_level => $RT::LogToScreen,
75                        stderr => 1
76                      ));
77     }
78 # {{{ Signal handlers
79
80 ## This is the default handling of warnings and die'ings in the code
81 ## (including other used modules - maybe except for errors catched by
82 ## Mason).  It will log all problems through the standard logging
83 ## mechanism (see above).
84
85 $SIG{__WARN__} = sub {$RT::Logger->warning($_[0])};
86
87 #When we call die, trap it and log->crit with the value of the die.
88
89 $SIG{__DIE__}  = sub {
90     unless ($^S || !defined $^S ) {
91         $RT::Logger->crit("$_[0]");
92         exit(-1);
93     }
94     else {
95         #Get out of here if we're in an eval
96         die $_[0];
97     }
98 };
99
100 # }}}
101
102 }
103
104 # }}}
105
106
107 sub SystemUser {
108     return($SystemUser);
109 }       
110
111 sub Nobody {
112     return ($Nobody);
113 }
114
115
116 =head2 DropSetGIDPermissions
117
118 Drops setgid permissions.
119
120 =cut
121
122 sub DropSetGIDPermissions {
123     # Now that we got the config read in, we have the database 
124     # password and don't need to be setgid
125     # make the effective group the real group
126     $) = $(;
127 }
128
129
130 =head1 NAME
131
132 RT - Request Tracker
133
134 =head1 SYNOPSIS
135
136 =head1 BUGS
137
138 =head1 SEE ALSO
139
140
141 =begin testing
142
143 ok (require RT::TestHarness);
144
145 ok ($RT::Nobody->Name() eq 'Nobody', "Nobody is nobody");
146 ok ($RT::Nobody->Name() ne 'root', "Nobody isn't named root");
147 ok ($RT::SystemUser->Name() eq 'RT_System', "The system user is RT_System");
148 ok ($RT::SystemUser->Name() ne 'noname', "The system user isn't noname");
149
150
151 =end testing
152
153 =cut
154
155 1;