]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl fix delete jobid
[bacula/bacula] / gui / bweb / cgi / bweb.pl
1 #!/usr/bin/perl -w
2 use strict ;
3
4 =head1 LICENSE
5
6     Copyright (C) 2006 Eric Bollengier
7         All rights reserved.
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
23 =head1 VERSION
24
25     $Id$
26
27 =cut
28
29 use Data::Dumper;
30 use Bweb;
31 use CGI;
32
33 my $client_re = qr/^([\w\d\.-]+)$/;
34 my $pool_re   = $client_re; 
35
36 my $action = CGI::param('action') || 'begin';
37
38 if ($action eq 'restore') {
39     print CGI::header('text/brestore'); # specialy to run brestore.pl
40
41 } else {
42     print CGI::header('text/html');
43 }
44
45 # loading config file
46 my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
47 $conf->load();
48
49 my $bweb = new Bweb(info => $conf);
50
51 # just send data with text/brestore content
52 if ($action eq 'restore') {
53     $bweb->restore();
54     exit 0;
55 }
56
57 my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
58
59 $bweb->display_begin();
60
61 # if no configuration, we send edit_conf
62 if ($action ne 'apply_conf' and !$bweb->{info}->{dbi}) {
63     $action = 'edit_conf';
64 }
65
66 if ($action eq 'begin') {               # main display
67     print "<div style='left=0;'><table border='0'><tr><td valign='top' width='100%'>\n";
68     $bweb->display_general(age => $arg->{age});
69     $bweb->display_running_jobs(0);
70     print "</td><td valign='top'>";
71     print "
72 <div class='titlediv'>
73   <h1 class='newstitle'> Statistics (last 48 hours)</h1>
74 </div>
75 <div class='bodydiv'>
76 <a href='?action=job;age=172800;jobtype=B'>
77 <img src='bgraph.pl?age=172800;width=600;height=250;graph=job_size;limit=100;action=graph;legend=off' alt='Nothing to display'>
78 </a>
79 </div>";
80     print "</td></tr></table></div>";
81     $bweb->display_job(limit => 10); 
82
83 } elsif ($action eq 'view_conf') {
84     $conf->view()
85
86 } elsif ($action eq 'edit_conf') {
87     $conf->edit();
88
89 } elsif ($action eq 'apply_conf') {
90     $conf->modify();
91
92 } elsif ($action eq 'client') { 
93     $bweb->display_clients();
94
95 } elsif ($action eq 'pool') {
96     $bweb->display_pool();
97
98 } elsif ($action eq 'location_edit') {
99     $bweb->location_edit();
100
101 } elsif ($action eq 'location_save') {
102     $bweb->location_save();
103
104 } elsif ($action eq 'location_add') {
105     $bweb->location_add();
106
107 } elsif ($action eq 'location_del') {
108     $bweb->del_location();
109
110 } elsif ($action eq 'media') {
111     $bweb->display_media();
112
113 } elsif ($action eq 'medias') {
114     $bweb->display_medias();
115
116 } elsif ($action eq 'eject') {
117     my $arg = $bweb->get_form("ach");
118     my $a = $bweb->ach_get($arg->{ach});
119     
120     if ($a) {
121         $a->status();
122         foreach my $slot (CGI::param('slot')) {
123             print $a->{error} unless $a->send_to_io($slot);
124         }
125
126         foreach my $media (CGI::param('media')) {
127             my $slot = $a->get_media_slot($media);
128             print $a->{error} unless $a->send_to_io($slot);
129         }
130
131         $a->display_content();
132     }
133
134 } elsif ($action eq 'eject_media') {
135     $bweb->eject_media();
136
137 } elsif ($action eq 'clear_io') {
138     my $arg = $bweb->get_form('ach');
139
140     my $a = $bweb->ach_get($arg->{ach});
141     if (defined $a) {
142         $a->status();
143         $a->clear_io();
144         $a->display_content();
145     }
146
147 } elsif ($action eq 'ach_edit') {
148     $bweb->ach_edit();
149
150 } elsif ($action eq 'ach_del') {
151     $bweb->ach_del();
152
153 } elsif ($action eq 'ach_view') {
154     # TODO : get autochanger name and create it
155     $bweb->connect_db();
156     my $arg = $bweb->get_form('ach');
157
158     my $a = $bweb->ach_get($arg->{ach});
159     if ($a) {
160         $a->status();
161         $a->display_content();
162     }
163
164 } elsif ($action eq 'ach_add') {
165     $bweb->ach_add();
166
167 } elsif ($action eq 'ach_load') {
168     my $arg = $bweb->get_form('ach', 'drive', 'slot');
169     
170     my $a = $bweb->ach_get($arg->{ach});
171
172     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
173     {
174         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
175         # TODO : use template here
176         print "<pre>\n";
177         $b->send_cmd_with_drive("mount slot=$arg->{slot} storage=\"" . $a->get_drive_name($arg->{drive}) . '"',
178                                 $arg->{drive});
179         print "</pre>\n";
180     } else {
181         $bweb->error("Can't get drive, slot or ach");
182     }
183     
184 } elsif ($action eq 'ach_unload') {
185     my $arg = $bweb->get_form('drive', 'slot', 'ach');
186
187     my $a = $bweb->ach_get($arg->{ach});
188
189     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
190     {
191         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
192         # TODO : use template here
193         print "<pre>\n";
194         $b->send_cmd_with_drive("umount storage=\"" . $a->get_drive_name($arg->{drive}) . '"',
195                                 $arg->{drive});
196
197         print "</pre>\n";
198
199     } else {
200         $bweb->error("Can't get drive, slot or ach");
201     }   
202 } elsif ($action eq 'intern_media') {
203     $bweb->help_intern();
204
205 } elsif ($action eq 'compute_intern_media') {
206     $bweb->help_intern_compute();
207
208 } elsif ($action eq 'extern_media') {
209     $bweb->help_extern();
210
211 } elsif ($action eq 'compute_extern_media') {
212     $bweb->help_extern_compute();
213
214 } elsif ($action eq 'extern') {
215     print "TODO : Eject ", join(",", CGI::param('media'));
216     $bweb->move_media();
217
218 } elsif ($action eq 'change_location') {
219     $bweb->change_location();
220
221 } elsif ($action eq 'location') {
222     $bweb->display_location();
223
224 } elsif ($action eq 'about') {
225     $bweb->display($bweb, 'about.tpl');
226
227 } elsif ($action eq 'intern') {
228     $bweb->move_media(); # TODO : remove that
229
230 } elsif ($action eq 'move_media') {
231     $bweb->move_media(); 
232
233 } elsif ($action eq 'save_location') {
234     $bweb->save_location();
235
236 } elsif ($action eq 'update_location') {
237     $bweb->update_location();
238
239 } elsif ($action eq 'update_media') {
240     $bweb->update_media();
241
242 } elsif ($action eq 'do_update_media') {
243     $bweb->do_update_media();
244
245 } elsif ($action eq 'update_slots') {
246     $bweb->update_slots();
247
248 } elsif ($action eq 'graph') {
249     $bweb->display_graph();
250
251 } elsif ($action eq 'next_job') {
252     $bweb->director_show_sched();
253
254 } elsif ($action eq 'enable_job') {
255     $bweb->enable_disable_job(1);
256
257 } elsif ($action eq 'disable_job') {
258     $bweb->enable_disable_job(0);
259
260 } elsif ($action eq 'job') {
261
262     print "<div><table border='0'><tr><td valign='top'>\n";
263     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
264                                     limit age offset qclients qfilesets
265                                     jobtype/);
266     $bweb->display($fields, "display_form_job.tpl");
267
268     print "</td><td valign='top'>";
269     $bweb->display_job(age => $arg->{age},  # last 7 days
270                        offset => $arg->{offset},
271                        limit => $arg->{limit});
272     print "</td></tr></table></div>";
273 } elsif ($action eq 'client_stats') {
274
275     foreach my $client (CGI::param('client')) {
276         if ($client =~ m/$client_re/) {
277             $bweb->display_client_stats(clientname => $1,
278                                         age => $arg->{age});
279         }
280     }
281
282 } elsif ($action eq 'running') {
283     $bweb->display_running_jobs(1);
284
285 } elsif ($action eq 'dsp_cur_job') {
286     $bweb->display_running_job();
287
288 } elsif ($action eq 'update_from_pool') {
289     my $elt = $bweb->get_form(qw/media pool/);
290     unless ($elt->{media} || $elt->{pool}) {
291         $bweb->error("Can't get media or pool param");
292     } else {
293         my $b = new Bconsole(pref => $conf) ;
294
295         $bweb->display({
296  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
297  title => "Update pool",
298  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
299         }, "command.tpl");      
300     }
301     
302     $bweb->update_media();
303
304 } elsif ($action eq 'client_status') {
305     my $b;
306     foreach my $client (CGI::param('client')) {
307         if ($client =~ m/$client_re/) {
308             $client = $1;
309             $b = new Bconsole(pref => $conf) 
310                 unless ($b) ;
311
312             $bweb->display({
313                 content => $b->send_cmd("st client=$client"),
314                 title => "Client status",
315                 name => $client,
316             }, "command.tpl");
317             
318         } else {
319             $bweb->error("Can't get client selection");
320         }
321     }
322
323 } elsif ($action eq 'cancel_job') {
324     $bweb->cancel_job();
325
326 } elsif  ($action eq 'media_zoom') {
327     $bweb->display_media_zoom();
328
329 } elsif  ($action eq 'job_zoom') {
330     if ($arg->{jobid}) {
331         $bweb->display_job_zoom($arg->{jobid});
332         $bweb->get_job_log();
333     } 
334 } elsif ($action eq 'job_log') {
335     $bweb->get_job_log();
336
337 } elsif ($action eq 'prune') {
338     $bweb->prune();
339
340 } elsif ($action eq 'purge') {
341     $bweb->purge();
342
343 } elsif ($action eq 'run_job') {
344     $bweb->run_job();
345
346 } elsif ($action eq 'run_job_mod') {
347     $bweb->run_job_mod();
348
349 } elsif ($action eq 'run_job_now') {
350     $bweb->run_job_now();
351
352 } elsif ($action eq 'label_barcodes') {
353     $bweb->label_barcodes();
354
355 } elsif ($action eq 'delete') {
356     $bweb->delete();
357
358 } else {
359     $bweb->error("Sorry, this action don't exist");
360 }
361
362 $bweb->display_end();
363
364
365 __END__
366
367 TODO :
368
369  o Affichage des job en cours, termines
370  o Affichage du detail d'un job (status client)
371  o Acces aux log d'une sauvegarde
372  o Cancel d'un job
373  o Lancement d'un job
374
375  o Affichage des medias (pool, cf bacweb)
376  o Affichage de la liste des cartouches
377  o Affichage d'un autochangeur
378  o Mise a jour des slots
379  o Label barcodes
380  o Affichage des medias qui ont besoin d'etre change
381
382  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
383  o Affichage des stats sur un type de job
384  o Affichage des infos de query.sql
385
386  - Affichage des du TapeAlert sur le site
387  - Recuperation des erreurs SCSI de /var/log/kern.log
388
389  o update d'un volume
390  o update d'un pool
391
392  o Configuration des autochanger a la main dans un hash dumper