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