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