]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl Add functions to view/add/del users and setup roles
[bacula/bacula] / gui / bweb / cgi / bweb.pl
1 #!/usr/bin/perl -w
2 use strict ;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
33    Switzerland, email:ftf@fsfeurope.org.
34
35 =head1 VERSION
36
37     $Id$
38
39 =cut
40
41 use Data::Dumper;
42 use Bweb;
43 use CGI;
44
45 my $client_re = qr/^([\w\d\.-]+)$/;
46
47 my $action = CGI::param('action') || 'begin';
48
49 if ($action eq 'restore') {
50     print CGI::header('text/brestore'); # specialy to run brestore.pl
51
52 } else {
53     print CGI::header('text/html');
54 }
55
56 # loading config file
57 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
58 $conf->load();
59
60 my $bweb = new Bweb(info => $conf);
61
62 # just send data with text/brestore content
63 if ($action eq 'restore') {
64     $bweb->restore();
65     exit 0;
66 }
67
68 my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
69
70 $bweb->display_begin();
71
72 # if no configuration, we send edit_conf
73 if ($action ne 'apply_conf' and !$bweb->{info}->{dbi}) {
74     $action = 'edit_conf';
75 }
76
77 if ($action eq 'begin') {               # main display
78     print "<div style='left=0;'><table border='0'><tr><td valign='top' width='100%'>\n";
79     $bweb->display_general(age => $arg->{age});
80     $bweb->display_running_jobs(0);
81     print "</td><td valign='top'>";
82     $bweb->display({}, "stats.tpl");
83     print "</td></tr></table></div>";
84     $bweb->display_job(limit => 10); 
85
86 } elsif ($action eq 'view_conf') {
87     $conf->view()
88
89 } elsif ($action eq 'edit_conf') {
90     $conf->edit();
91
92 } elsif ($action eq 'apply_conf') {
93     $conf->modify();
94
95 } elsif ($action eq 'user_del') {
96     $bweb->users_del();
97
98 } elsif ($action eq 'user_add') {
99     $bweb->users_add();
100
101 } elsif ($action eq 'user_edit') {
102     $bweb->display_user();
103
104 } elsif ($action eq 'user_save') {
105     $bweb->users_add();
106
107 } elsif ($action eq 'users') {
108     $bweb->display_users();
109
110 } elsif ($action eq 'client') { 
111     $bweb->display_clients();
112
113 } elsif ($action eq 'pool') {
114     $bweb->display_pool();
115
116 } elsif ($action eq 'location_edit') {
117     $bweb->location_edit();
118
119 } elsif ($action eq 'location_save') {
120     $bweb->location_save();
121
122 } elsif ($action eq 'location_add') {
123     $bweb->location_add();
124
125 } elsif ($action eq 'location_del') {
126     $bweb->location_del();
127
128 } elsif ($action eq 'media') {
129     print "<div><table border='0'><tr><td valign='top'>\n";
130     my $fields = $bweb->get_form(qw/db_locations db_pools expired
131                                     qlocations qpools volstatus qre_media
132                                     limit  qmediatypes db_mediatypes/);
133     $bweb->display($fields, "display_form_media.tpl");
134
135     print "</td><td valign='top'>";
136     $bweb->display_media(offset => $arg->{offset},
137                          limit => $arg->{limit});
138     print "</td></tr></table></div>";
139
140 } elsif ($action eq 'allmedia') {
141     $bweb->display_allmedia();
142
143 } elsif ($action eq 'eject') {
144     my $arg = $bweb->get_form("ach");
145     my $a = $bweb->ach_get($arg->{ach});
146     
147     if ($a) {
148         $a->status();
149         foreach my $slot (CGI::param('slot')) {
150             print $a->{error} unless $a->send_to_io($slot);
151         }
152
153         foreach my $media (CGI::param('media')) {
154             my $slot = $a->get_media_slot($media);
155             print $a->{error} unless $a->send_to_io($slot);
156         }
157
158         $a->display_content();
159     }
160
161 } elsif ($action eq 'eject_media') {
162     $bweb->eject_media();
163
164 } elsif ($action eq 'clear_io') {
165     my $arg = $bweb->get_form('ach');
166
167     my $a = $bweb->ach_get($arg->{ach});
168     if (defined $a) {
169         $a->status();
170         $a->clear_io();
171         $a->display_content();
172     }
173
174 } elsif ($action eq 'ach_edit') {
175     $bweb->ach_edit();
176
177 } elsif ($action eq 'ach_del') {
178     $bweb->ach_del();
179
180 } elsif ($action eq 'ach_view') {
181     # TODO : get autochanger name and create it
182     $bweb->connect_db();
183     my $arg = $bweb->get_form('ach');
184
185     my $a = $bweb->ach_get($arg->{ach});
186     if ($a) {
187         $a->status();
188         $a->display_content();
189     }
190
191 } elsif ($action eq 'ach_add') {
192     $bweb->ach_add();
193
194 } elsif ($action eq 'ach_load') {
195     my $arg = $bweb->get_form('ach', 'drive', 'slot');
196     
197     my $a = $bweb->ach_get($arg->{ach});
198
199     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
200     {
201         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
202         # TODO : use template here
203         print "<pre>\n";
204         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
205         print "</pre>\n";
206     } else {
207         $bweb->error("Can't get drive, slot or ach");
208     }
209     
210 } elsif ($action eq 'ach_unload') {
211     my $arg = $bweb->get_form('drive', 'slot', 'ach');
212
213     my $a = $bweb->ach_get($arg->{ach});
214
215     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
216     {
217         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
218         # TODO : use template here
219         print "<pre>\n";
220         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
221         print "</pre>\n";
222
223     } else {
224         $bweb->error("Can't get drive, slot or ach");
225     }   
226 } elsif ($action eq 'intern_media') {
227     $bweb->help_intern();
228
229 } elsif ($action eq 'compute_intern_media') {
230     $bweb->help_intern_compute();
231
232 } elsif ($action eq 'extern_media') {
233     $bweb->help_extern();
234
235 } elsif ($action eq 'compute_extern_media') {
236     $bweb->help_extern_compute();
237
238 } elsif ($action eq 'extern') {
239     print "<div style='float: left;'>";
240     my @achs = $bweb->eject_media();
241     for my $ach (@achs) {
242         CGI::param('ach', $ach);
243         $bweb->update_slots();
244     }
245     print "</div><div style='float: left;margin-left: 20px;'>";
246     $bweb->move_media('no');    # enabled = no
247     print "</div>";
248
249 } elsif ($action eq 'move_email') {
250     $bweb->move_email();
251
252 } elsif ($action eq 'change_location') {
253     $bweb->location_change();
254
255 } elsif ($action eq 'location') {
256     $bweb->location_display();
257
258 } elsif ($action eq 'about') {
259     $bweb->display($bweb, 'about.tpl');
260
261 } elsif ($action eq 'intern') {
262     $bweb->move_media('yes'); # TODO : remove that
263
264 } elsif ($action eq 'move_media') {
265     my $a = $bweb->get_form('enabled');
266     $bweb->move_media($a->{enabled}); 
267
268 } elsif ($action eq 'save_location') {
269     $bweb->save_location();
270
271 } elsif ($action eq 'update_location') {
272     $bweb->update_location();
273
274 } elsif ($action eq 'update_media') {
275     $bweb->update_media();
276
277 } elsif ($action eq 'do_update_media') {
278     $bweb->do_update_media();
279
280 } elsif ($action eq 'update_slots') {
281     $bweb->update_slots();
282
283 } elsif ($action eq 'graph') {
284     $bweb->display_graph();
285
286 } elsif ($action eq 'next_job') {
287     $bweb->director_show_sched();
288
289 } elsif ($action eq 'enable_job') {
290     $bweb->enable_disable_job(1);
291
292 } elsif ($action eq 'disable_job') {
293     $bweb->enable_disable_job(0);
294
295 } elsif ($action eq 'groups') {
296     $bweb->display_groups();
297
298 } elsif ($action eq 'groups_edit') {
299     $bweb->groups_edit();
300
301 } elsif ($action eq 'groups_save') {
302     $bweb->groups_save();
303
304 } elsif ($action eq 'groups_add') {
305     $bweb->groups_add();
306
307 } elsif ($action eq 'groups_del') {
308     $bweb->groups_del();
309
310 } elsif ($action eq 'job') {
311
312     print "<div><table border='0'><tr><td valign='top'>\n";
313     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
314                                     limit age offset qclients qfilesets
315                                     jobtype qpools db_pools
316                                     db_client_groups qclient_groups/); # drop this to hide 
317
318     $bweb->display($fields, "display_form_job.tpl");
319
320     print "</td><td valign='top'>";
321     $bweb->display_job(age => $arg->{age},  # last 7 days
322                        offset => $arg->{offset},
323                        limit => $arg->{limit});
324     print "</td></tr></table></div>";
325 } elsif ($action eq 'job_group') {
326
327     print "<div><table border='0'><tr><td valign='top'>\n";
328     my $fields = $bweb->get_form(qw/limit level age 
329                                     db_client_groups qclient_groups/); # drop this to hide 
330
331     $fields->{hide_status} = 1;
332     $fields->{hide_type} = 1;
333     $fields->{action} = 'job_group';
334
335     $bweb->display($fields, "display_form_job.tpl");
336
337     print "</td><td valign='top'>";
338     $bweb->display_job_group(age => $arg->{age},  # last 7 days
339                              limit => $arg->{limit});
340     print "</td></tr></table></div>";
341 } elsif ($action eq 'client_stats') {
342
343     foreach my $client (CGI::param('client')) {
344         if ($client =~ m/$client_re/) {
345             $bweb->display_client_stats(clientname => $1,
346                                         age => $arg->{age});
347         }
348     }
349
350 } elsif ($action eq 'group_stats') {
351
352     $bweb->display_group_stats(age => $arg->{age});
353
354 } elsif ($action eq 'running') {
355     $bweb->display_running_jobs(1);
356
357 } elsif ($action eq 'dsp_cur_job') {
358     $bweb->display_running_job();
359
360 } elsif ($action eq 'update_from_pool') {
361     my $elt = $bweb->get_form(qw/media pool/);
362     unless ($elt->{media} || $elt->{pool}) {
363         $bweb->error("Can't get media or pool param");
364     } else {
365         my $b = new Bconsole(pref => $conf) ;
366
367         $bweb->display({
368  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
369  title => "Update pool",
370  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
371         }, "command.tpl");      
372     }
373     
374     $bweb->update_media();
375
376 } elsif ($action eq 'client_status') {
377     my $b;
378     foreach my $client (CGI::param('client')) {
379         if ($client =~ m/$client_re/) {
380             $client = $1;
381             $b = new Bconsole(pref => $conf) 
382                 unless ($b) ;
383
384             $bweb->display({
385                 content => $b->send_cmd("st client=$client"),
386                 title => "Client status",
387                 name => $client,
388             }, "command.tpl");
389             
390         } else {
391             $bweb->error("Can't get client selection");
392         }
393     }
394
395 } elsif ($action eq 'cancel_job') {
396     $bweb->cancel_job();
397
398 } elsif  ($action eq 'media_zoom') {
399     $bweb->display_media_zoom();
400
401 } elsif  ($action eq 'job_zoom') {
402     if ($arg->{jobid}) {
403         $bweb->display_job_zoom($arg->{jobid});
404         $bweb->get_job_log();
405     } 
406 } elsif ($action eq 'job_log') {
407     $bweb->get_job_log();
408
409 } elsif ($action eq 'prune') {
410     $bweb->prune();
411
412 } elsif ($action eq 'purge') {
413     $bweb->purge();
414
415 } elsif ($action eq 'run_job') {
416     $bweb->run_job();
417
418 } elsif ($action eq 'run_job_mod') {
419     $bweb->run_job_mod();
420
421 } elsif ($action eq 'run_job_now') {
422     $bweb->run_job_now();
423
424 } elsif ($action eq 'label_barcodes') {
425     $bweb->label_barcodes();
426
427 } elsif ($action eq 'delete') {
428     $bweb->delete();
429
430 } elsif ($action eq 'fileset_view') {
431     $bweb->fileset_view();
432
433 } else {
434     $bweb->error("Sorry, this action don't exist");
435 }
436
437 $bweb->display_end();
438
439 $bweb->dbh_disconnect();
440
441 __END__
442
443 TODO :
444
445  o Affichage des job en cours, termines
446  o Affichage du detail d'un job (status client)
447  o Acces aux log d'une sauvegarde
448  o Cancel d'un job
449  o Lancement d'un job
450
451  o Affichage des medias (pool, cf bacweb)
452  o Affichage de la liste des cartouches
453  o Affichage d'un autochangeur
454  o Mise a jour des slots
455  o Label barcodes
456  o Affichage des medias qui ont besoin d'etre change
457
458  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
459  o Affichage des stats sur un type de job
460  o Affichage des infos de query.sql
461
462  - Affichage des du TapeAlert sur le site
463  - Recuperation des erreurs SCSI de /var/log/kern.log
464
465  o update d'un volume
466  o update d'un pool
467
468  o Configuration des autochanger a la main dans un hash dumper