File Coverage

blib/lib/Citrix.pm
Criterion Covered Total %
statement 12 43 27.9
branch 0 12 0.0
condition 0 6 0.0
subroutine 4 7 57.1
pod 3 3 100.0
total 19 71 26.7


line stmt bran cond sub pod time code
1             # API / Module version 1.X restructuring placeholder
2             # - Aim to ease up Citrix module use by including all the sub-modules here
3             # and allowing merely "use Citrix;" in the application
4             # TODO:
5             # - Provide porting guide ... (???)
6             # - CitrixPortal.pm
7             # DONE
8             # - Deprecated Citrix::Config.pm ? maybe leave for farms
9             # - Farms: uses 'farmid'
10             # Allow loading config from DB
11              
12             package Citrix;
13 2     2   38077 use Citrix::SessionSet;
  2         4  
  2         61  
14 2     2   1123 use Citrix::SessOp;
  2         6  
  2         51  
15 2     2   1157 use Citrix::Farm;
  2         5  
  2         43  
16             #use Citrix::Config;
17 2     2   544 use Citrix::LaunchMesg;
  2         12  
  2         1248  
18              
19             our $VERSION = '0.25';
20              
21             =head1 NAME
22              
23             Module Suite for managing UNIX Citrix Sessions.
24              
25             =head1 DESCRIPTION
26              
27             Citrix "top-level" module loads all Citrix::* modules into runtime for simple use.
28             Citrix::* modules have no problems running in mod_perl based web application.
29              
30             =head1 CLASS VARIABLES
31              
32             The following class variables serve as Global Citrix environment settings.
33              
34             =head2 $Citrix::binpath
35              
36             Path to Citrix command line utilities (for ctxconnect,ctxdisconnect,ctxlogoff,ctxreset,
37             ctxquery,ctxquser,ctxshadow ... Default: /opt/CTXSmf/bin)
38              
39             =head2 $Citrix::admins
40              
41             Hash(ref) containing admin usernames set to (dummy) true value. Set this from external
42             configuration files (Optional, No default value). This is provided as convenience for application
43             to store "admin" role for certain users.
44              
45             =head2 $Citrix::farms
46              
47             Array of hashes for Citrix farms configuration. See L for Farm hash structure.
48             Load these with Citrix::loadconfig() (see METHODS).
49              
50             =head2 $Citrix::touts
51              
52             Timeout(s) for Citrix (over-the-network) Operations. Has separate settings for 'host','user','op'.
53             Set these by your network speed and latency.
54              
55             =cut
56              
57              
58             # Citrix Admins
59             our $admins = {};
60             # Global handle to farm configurations
61             our $farms; # []
62             # Domain to use in launch message
63             our $domain = '';
64             # Citrix Command line binaries path
65             our $binpath = '/opt/CTXSmf/bin';
66             # TODO: New Granular timeouts for various use-cases
67             our $touts = {'host' => 10, 'user' => 5, 'op' => 5,};
68              
69             =head1 METHODS
70              
71             =head2 my Citrix::loadconfig($fname);
72              
73             Load Farm Configuration from a file in perl format. The file should "return" an array
74             of (non blessed) Citrix::Farm hashes with keys described in L module
75             (all this as a result of underlying "require()").
76             Do not terminate this config file with the traditional "1;" true value (the array
77             returned will be the true value).
78              
79             This file is expected to be found in Perl library path (@INC). Usually the application
80             current directory is a safe choice for storing config (as '.' is always in @INC).
81              
82             Behind the scenes the Farm config is stored in Citrix class to be accessed later by
83             getfarms
84              
85             =head2 my $farms = Citrix::getfarms();
86              
87             Get Handle to farms (array of hashes). Passing keyword param 'idx' set to true values makes getfarms
88             return a hash(ref) keyed by farm id (instead or array(ref) ).
89             Farm id keys are usually chosen to be short name string (Example 'la' for Los Angeles farm), see Citrix::Farm.
90             Passing keyword param 'sort' set to valid Farm attribute value makes getfarms() return farm set array sorted by
91             atribute ('sort' and 'idx' don't work together).
92              
93             =head2 Citrix::loadconfig_db($dbh)
94              
95             Load Citrix Farms from DB using DBI connection $dbh.
96             Method stores L entries in $Citrix::farms for later access.
97             Use Citrix::getfarms() to access farm info (see L).
98              
99             Useful in bigger environments with world-wide multi-farm Citrix system layout.
100             Notice that Citrix::* modules are not tightly coupled with perl DBI, but to use
101             this method you do need DBI to to establish the connection.
102              
103              
104             =cut
105              
106             # Load Farm Configuration
107             sub loadconfig {
108 0     0 1   my ($fname) = @_;
109 0 0 0       if ($farms && @$farms) {return($farms);}
  0            
110 0           eval {
111 0           $farms = require($fname);
112             };
113 0 0         if ($@) {die("No Farms Cached or config file found: $!\n");}
  0            
114 0           return($farms);
115             }
116              
117             sub loadconfig_db {
118 0     0 1   my ($dbh, %opt) = @_;
119 0   0       my $tn = $opt{'tabname'} || $farmtabname;
120 0           my $w = " WHERE active = 1";
121 0           my $qs = "SELECT * FROM $tn $w ";
122 0           my $arr = $dbh->selectall_arrayref($qs, {Slice => {} });
123            
124 0           my @farms = map({
125 0           $_->{'hosts'} = [split(/,\s*/, $_->{'hosts'})];
126 0           $_->{'apps'} = [split(/,\s*/, $_->{'apps'})];
127             #DEBUG:print("Entry:\n".Dumper($_));
128 0           bless($_, 'Citrix::Farm');
129             } @$arr);
130 0           return(\@farms);
131             }
132              
133             # Get Array of farm configs.
134             # Options
135             # - idx - Set to 1 return hash indexed by Farm id:s
136             # - sort - Sort by attribute
137             sub getfarms {
138 0     0 1   my (%c) = @_;
139 0 0         if (!$farms) {die("No Farms loaded / cached");}
  0            
140 0 0         if (ref($farms) ne 'ARRAY') {die("Farms Not in array collection");}
  0            
141             # ARRAY/HASH
142 0 0         if ($c{'idx'}) {my %fi = map({$_->{'farmid'}, $_;} @$farms);return(\%fi);}
  0 0          
  0            
  0            
  0            
143 0           elsif (my $sa = $c{'sort'}) {my @s = sort({$a->{$sa} cmp $b->{$sa};} @$farms);return(\@s);}
  0            
144 0           return($farms);
145             }
146             1;
147              
148             #Thanks to Ramana Mokkapati and Ken Venner, who are not only avid Perl users but
149             #friends of Open-Source in general and allowed me to contribute this module.
150              
151             __END__