summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Interface/CLI.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/Interface/CLI.pm')
-rw-r--r--rt/lib/RT/Interface/CLI.pm112
1 files changed, 45 insertions, 67 deletions
diff --git a/rt/lib/RT/Interface/CLI.pm b/rt/lib/RT/Interface/CLI.pm
index a3c840af5..a3bf92d5f 100644
--- a/rt/lib/RT/Interface/CLI.pm
+++ b/rt/lib/RT/Interface/CLI.pm
@@ -1,31 +1,9 @@
-# BEGIN LICENSE BLOCK
-#
-# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
-#
-# (Except where explictly superceded by other copyright notices)
-#
-# This work is made available to you under the terms of Version 2 of
-# the GNU General Public License. A copy of that license should have
-# been provided with this software, but in any event can be snarfed
-# from www.gnu.org.
-#
-# This work is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# Unless otherwise specified, all modifications, corrections or
-# extensions to this work which alter its source code become the
-# property of Best Practical Solutions, LLC when submitted for
-# inclusion in the work.
-#
-#
-# END LICENSE BLOCK
-use strict;
+# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Interface/CLI.pm,v 1.1 2002-08-12 06:17:08 ivan Exp $
+# RT is (c) 1996-2001 Jesse Vincent <jesse@fsck.com>
-use RT;
package RT::Interface::CLI;
+use strict;
BEGIN {
@@ -33,14 +11,14 @@ BEGIN {
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
- $VERSION = do { my @r = (q$Revision: 1.1.1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
+ $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
@ISA = qw(Exporter);
# your exported package globals go here,
# as well as any optionally exported functions
- @EXPORT_OK = qw(&CleanEnv
- &GetCurrentUser &GetMessageContent &debug &loc);
+ @EXPORT_OK = qw(&CleanEnv &LoadConfig &DBConnect
+ &GetCurrentUser &GetMessageContent &debug);
}
=head1 NAME
@@ -49,28 +27,25 @@ BEGIN {
=head1 SYNOPSIS
- use lib "/path/to/rt/libraries/";
+ use lib "!!RT_LIB_PATH!!";
+ use lib "!!RT_ETC_PATH!!";
- use RT::Interface::CLI qw(CleanEnv
- GetCurrentUser GetMessageContent loc);
+ use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
+ GetCurrentUser GetMessageContent);
#Clean out all the nasties from the environment
CleanEnv();
- #let's talk to RT'
- use RT;
+ #Load etc/config.pm and drop privs
+ LoadConfig();
- #Load RT's config file
- RT::LoadConfig();
+ #Connect to the database and get RT::SystemUser and RT::Nobody loaded
+ DBConnect();
- # Connect to the database. set up loggign
- RT::Init();
#Get the current user all loaded
my $CurrentUser = GetCurrentUser();
- print loc('Hello!'); # Synonym of $CuurentUser->loc('Hello!');
-
=head1 DESCRIPTION
@@ -78,6 +53,7 @@ BEGIN {
=begin testing
+ok(require RT::TestHarness);
ok(require RT::Interface::CLI);
=end testing
@@ -101,10 +77,35 @@ sub CleanEnv {
+=head2 LoadConfig
+
+Loads RT's config file and then drops setgid privileges.
+
+=cut
+
+sub LoadConfig {
+
+ #This drags in RT's config.pm
+ use config;
+
+}
+
+
+
+=head2 DBConnect
+
+ Calls RT::Init, which creates a database connection and then creates $RT::Nobody
+ and $RT::SystemUser
+
+=cut
+
+
+sub DBConnect {
+ use RT;
+ RT::Init();
+}
-{
- my $CurrentUser; # shared betwen GetCurrentUser and loc
# {{{ sub GetCurrentUser
@@ -114,14 +115,15 @@ sub CleanEnv {
loaded with that user. if the current user isn't found, returns a copy of RT::Nobody.
=cut
-
sub GetCurrentUser {
+ my ($Gecos, $CurrentUser);
+
require RT::CurrentUser;
#Instantiate a user object
- my $Gecos= ($^O eq 'MSWin32') ? Win32::LoginName() : (getpwuid($<))[0];
+ $Gecos=(getpwuid($<))[0];
#If the current user is 0, then RT will assume that the User object
#is that of the currentuser.
@@ -132,29 +134,10 @@ sub GetCurrentUser {
unless ($CurrentUser->Id) {
$RT::Logger->debug("No user with a unix login of '$Gecos' was found. ");
}
-
return($CurrentUser);
}
# }}}
-
-# {{{ sub loc
-
-=head2 loc
-
- Synonym of $CurrentUser->loc().
-
-=cut
-
-sub loc {
- die "No current user yet" unless $CurrentUser ||= RT::CurrentUser->new;
- return $CurrentUser->loc(@_);
-}
-# }}}
-
-}
-
-
# {{{ sub GetMessageContent
=head2 GetMessageContent
@@ -238,9 +221,4 @@ sub debug {
# }}}
-eval "require RT::Interface::CLI_Vendor";
-die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/CLI_Vendor.pm});
-eval "require RT::Interface::CLI_Local";
-die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/CLI_Local.pm});
-
1;