Initial commit
[clearscm.git] / clearadm / processsystem.cgi
1 #!/usr/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'} or $opts{'edit.x'} or $opts{action} eq 'Post') {
90   displayError 'Action not defined!';
91   exit 1;
92 } # unless
93
94 unless ($opts{action} eq 'Add') {
95   unless ($opts{name}) {
96     displayError 'System not defined!';
97     exit 1;
98   } # unless
99 } # unless
100
101 my ($err, $msg);
102
103 if ($opts{action} eq 'Add') {
104   display h1 {class => 'center'}, 'Add System';
105   editSystem; 
106 } elsif ($opts{'delete.x'}) {
107   ($err, $msg) = $clearadm->DeleteSystem ($opts{name});
108    
109   display h1 { class => 'center'}, ucfirst $opts{name} . ' deleted';
110 } elsif ($opts{'edit.x'}) {
111   display h1 {class => 'center'}, 'Edit System: ', ucfirst $opts{name};
112   editSystem ($opts{name});
113 } elsif ($opts{action} eq 'Post') {
114   delete $opts{action};
115
116   my %system = $clearadm->GetSystem ($opts{name});
117   
118   $opts{active} = 'false'
119     unless $opts{active};
120   
121   if (%system) {
122     ($err, $msg) = $clearadm->UpdateSystem ($opts{name}, %opts);
123
124     if ($err) {
125       displayError "$msg (Status: $err)";
126     } else {
127       display h1 {class => 'center'}, ucfirst $opts{name} . ' updated';
128     
129       displaySystem ($opts{name});
130     } # if
131   } else {
132     ($err, $msg) = $clearadm->AddSystem (%opts);
133
134     if ($err) {
135       displayError "$msg (Status: $err)";
136     } else {
137       display h1 {class => 'center'}, ucfirst $opts{name} . ' updated';
138     
139       displaySystem ($opts{name});
140     } # if
141   } # if
142 } else {
143   displayError "Unknown action - $opts{action}";
144 } # if
145
146 footing;
147
148 =pod
149
150 =head1 CONFIGURATION AND ENVIRONMENT
151
152 DEBUG: If set then $debug is set to this level.
153
154 VERBOSE: If set then $verbose is set to this level.
155
156 TRACE: If set then $trace is set to this level.
157
158 =head1 DEPENDENCIES
159
160 =head2 Perl Modules
161
162 L<CGI>
163
164 L<CGI::Carp|CGI::Carp>
165
166 L<FindBin>
167
168 L<Getopt::Long|Getopt::Long>
169
170 =head2 ClearSCM Perl Modules
171
172 =begin man 
173
174  Clearadm
175  ClearadmWeb
176  Display
177  Utils
178
179 =end man
180
181 =begin html
182
183 <blockquote>
184 <a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
185 <a href="http://clearscm.com/php/cvs_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
186 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
187 <a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
188 </blockquote>
189
190 =end html
191
192 =head1 BUGS AND LIMITATIONS
193
194 There are no known bugs in this script
195
196 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
197
198 =head1 LICENSE AND COPYRIGHT
199
200 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
201
202 =cut