Removed /usr/local from CDPATH
[clearscm.git] / clearadm / processsystem.cgi
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: processsystem.cgi,v $
6
7 Process a system
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.6 $
20
21 =item Created:
22
23 Mon Oct 25 11:10:47 PDT 2008
24
25 =item Modified:
26
27 $Date: 2011/02/14 14:53:51 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage processsystem.cgi: [-u|sage] [-ve|rbose] [-d|ebug]
34                           action=[Add|Delete|Edit|Post] system=<systemname>
35                           
36
37  Where:
38    -u|sage:   Displays usage
39    -ve|rbose: Be verbose
40    -d|ebug:   Output debug messages
41    
42    action:    Specifies to add, delete, edit or post an alert
43    system:    Name of alert to delete or edit
44
45 =head2 DESCRIPTION
46
47 This script adds, deletes, edits or posts an alert
48
49 =cut
50
51 use strict;
52 use warnings;
53
54 use FindBin;
55 use Getopt::Long;
56 use CGI qw (:standard :cgi-lib *table start_Tr end_Tr);
57 use CGI::Carp 'fatalsToBrowser';
58
59 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
60
61 use Clearadm;
62 use ClearadmWeb;
63 use Display;
64 use Utils;
65
66 my $VERSION  = '$Revision: 1.6 $';
67   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
68   
69 my $clearadm;
70
71 # Main
72 GetOptions (
73   usage      => sub { Usage },
74   verbose    => sub { set_verbose },
75   debug      => sub { set_debug },
76 ) or Usage 'Invalid parameter';
77
78 # Announce ourselves
79 verbose "$FindBin::Script v$VERSION";
80
81 $clearadm = Clearadm->new;
82
83 my %opts = Vars;
84
85 my $title = 'Process System';
86
87 heading $title;
88
89 unless ($opts{'delete.x'}
90      or $opts{'edit.x'}
91      or $opts{action} eq 'Post'
92      or $opts{action} eq 'Add'
93   ) {
94   displayError 'Action not defined!';
95   exit 1;
96 } # unless
97
98 unless ($opts{action} eq 'Add') {
99   unless ($opts{name}) {
100     displayError 'System not defined!';
101     exit 1;
102   } # unless
103 } # unless
104
105 my ($err, $msg);
106
107 if ($opts{action} eq 'Add') {
108   display h1 {class => 'center'}, 'Add System';
109   editSystem; 
110 } elsif ($opts{'delete.x'}) {
111   ($err, $msg) = $clearadm->DeleteSystem ($opts{name});
112    
113   display h1 { class => 'center'}, ucfirst $opts{name} . ' deleted';
114 } elsif ($opts{'edit.x'}) {
115   display h1 {class => 'center'}, 'Edit System: ', ucfirst $opts{name};
116   editSystem ($opts{name});
117 } elsif ($opts{action} eq 'Post') {
118   delete $opts{action};
119
120   my %system = $clearadm->GetSystem ($opts{name});
121   
122   $opts{active} = 'false'
123     unless $opts{active};
124   
125   if (%system) {
126     ($err, $msg) = $clearadm->UpdateSystem ($opts{name}, %opts);
127
128     if ($err) {
129       displayError "$msg (Status: $err)";
130     } else {
131       display h1 {class => 'center'}, ucfirst $opts{name} . ' updated';
132     
133       displaySystem ($opts{name});
134     } # if
135   } else {
136     ($err, $msg) = $clearadm->AddSystem (%opts);
137
138     if ($err) {
139       displayError "$msg (Status: $err)";
140     } else {
141       display h1 {class => 'center'}, ucfirst $opts{name} . ' updated';
142     
143       displaySystem ($opts{name});
144     } # if
145   } # if
146 } else {
147   displayError "Unknown action - $opts{action}";
148 } # if
149
150 footing;
151
152 =pod
153
154 =head1 CONFIGURATION AND ENVIRONMENT
155
156 DEBUG: If set then $debug is set to this level.
157
158 VERBOSE: If set then $verbose is set to this level.
159
160 TRACE: If set then $trace is set to this level.
161
162 =head1 DEPENDENCIES
163
164 =head2 Perl Modules
165
166 L<CGI>
167
168 L<CGI::Carp|CGI::Carp>
169
170 L<FindBin>
171
172 L<Getopt::Long|Getopt::Long>
173
174 =head2 ClearSCM Perl Modules
175
176 =begin man 
177
178  Clearadm
179  ClearadmWeb
180  Display
181  Utils
182
183 =end man
184
185 =begin html
186
187 <blockquote>
188 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
189 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
190 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
191 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
192 </blockquote>
193
194 =end html
195
196 =head1 BUGS AND LIMITATIONS
197
198 There are no known bugs in this script
199
200 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
201
202 =head1 LICENSE AND COPYRIGHT
203
204 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
205
206 =cut