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