1 |
diff -urN e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.2.0.new/root/etc/e-smith/events/actions/workstation-backup-dar |
2 |
--- e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar 2010-02-15 20:54:05.000000000 +1100 |
3 |
+++ e-smith-backup-2.2.0.new/root/etc/e-smith/events/actions/workstation-backup-dar 2010-02-15 20:58:18.000000000 +1100 |
4 |
@@ -151,7 +151,7 @@ |
5 |
|
6 |
chomp $vollbl; |
7 |
chomp $blkdev; |
8 |
- $vollbl = lc("media/$vollbl"); |
9 |
+ $vollbl = "media/$vollbl"; |
10 |
if ($vollbl eq $smbshare) { |
11 |
$device = $blkdev; |
12 |
} |
13 |
diff -urN e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup e-smith-backup-2.2.0.new/root/etc/e-smith/web/functions/backup |
14 |
--- e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup 2010-02-15 20:54:05.000000000 +1100 |
15 |
+++ e-smith-backup-2.2.0.new/root/etc/e-smith/web/functions/backup 2010-02-15 20:57:42.000000000 +1100 |
16 |
@@ -1221,7 +1221,7 @@ |
17 |
my $vollbl = qx(hal-get-property --udi $1 --key volume.label); |
18 |
$vollbl =~ m/^(\S+)/; |
19 |
if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} |
20 |
- push @usbdisks, lc($vollbl); |
21 |
+ push @usbdisks, $vollbl; |
22 |
} |
23 |
|
24 |
unless ($usbdisks[0]){ |
25 |
@@ -3254,7 +3254,7 @@ |
26 |
|
27 |
chomp $vollbl; |
28 |
chomp $blkdev; |
29 |
- $vollbl = lc("media/$vollbl"); |
30 |
+ $vollbl = "media/$vollbl"; |
31 |
if ($vollbl eq $share) { |
32 |
$device = $blkdev; |
33 |
} |
34 |
diff -urN e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup.orig e-smith-backup-2.2.0.new/root/etc/e-smith/web/functions/backup.orig |
35 |
--- e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup.orig 2010-02-15 20:54:05.000000000 +1100 |
36 |
+++ e-smith-backup-2.2.0.new/root/etc/e-smith/web/functions/backup.orig 1970-01-01 10:00:00.000000000 +1000 |
37 |
@@ -1,3271 +0,0 @@ |
38 |
-#!/usr/bin/perl -wT |
39 |
-#---------------------------------------------------------------------- |
40 |
-# heading : Administration |
41 |
-# description : Backup or restore |
42 |
-# navigation : 4000 4200 |
43 |
-# Copyright (C) 2002 Mitel Networks Corporation |
44 |
-# |
45 |
-# This program is free software; you can redistribute it and/or modify |
46 |
-# it under the terms of the GNU General Public License as published by |
47 |
-# the Free Software Foundation; either version 2 of the License, or |
48 |
-# (at your option) any later version. |
49 |
-# |
50 |
-# This program is distributed in the hope that it will be useful, |
51 |
-# but WITHOUT ANY WARRANTY; without even the implied warranty of |
52 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
53 |
-# GNU General Public License for more details. |
54 |
-# |
55 |
-# You should have received a copy of the GNU General Public License |
56 |
-# along with this program; if not, write to the Free Software |
57 |
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
58 |
-# |
59 |
-# Technical support for this program is available from Mitel Networks |
60 |
-# Please visit our web site www.mitel.com/sme/ for details. |
61 |
-#---------------------------------------------------------------------- |
62 |
-use strict; |
63 |
-use esmith::FormMagick; |
64 |
-use esmith::ConfigDB; |
65 |
-use esmith::Backup; |
66 |
-use esmith::BackupHistoryDB; |
67 |
-use esmith::AccountsDB; |
68 |
-use esmith::cgi; |
69 |
-use esmith::util; |
70 |
-use esmith::lockfile; |
71 |
-use File::Find; |
72 |
- |
73 |
-$File::Find::dont_use_nlink = 1; # fix for Windows shares |
74 |
- |
75 |
-my $fm = esmith::FormMagick->new(); |
76 |
- |
77 |
-# These statements _must_ come _after_ the FormMagick constructor. It sets |
78 |
-# POST_MAX and DISABLE_UPLOADS to values that will cause this script to fail |
79 |
-# on restores and verification of files. |
80 |
-$CGI::POST_MAX = -1; # allow any size POST |
81 |
-$CGI::DISABLE_UPLOADS = 0; # need to upload to restore from desktop |
82 |
- |
83 |
-$fm->parse_xml(); |
84 |
- |
85 |
-my $conf = esmith::ConfigDB->open() |
86 |
- || die $fm->localise('CANNOT_OPEN').'configuration db'; |
87 |
- |
88 |
-my $restore = esmith::ConfigDB->open('/etc/e-smith/restore') |
89 |
- || die $fm->localise('CANNOT_OPEN').'/etc/e-smith/restore'; |
90 |
- |
91 |
-my $es_backup = new esmith::Backup or die "Couldn't create Backup object\n"; |
92 |
- |
93 |
-my @directories = $es_backup->restore_list; |
94 |
-@directories = grep { -e "/$_" } @directories; |
95 |
- |
96 |
-# Unbuffer standard output so that files and directories are listed as |
97 |
-# they are restored |
98 |
-$| = 1; |
99 |
- |
100 |
-# Store away current gid of 'www' group. |
101 |
-my $www_gid = getgrnam("www"); |
102 |
- |
103 |
-#------------------------------------------------------------ |
104 |
-# examine state parameter and display the appropriate form |
105 |
-#------------------------------------------------------------ |
106 |
- |
107 |
-my $q = $fm->{cgi}; |
108 |
- |
109 |
-if (! grep (/^state$/, $q->param)) |
110 |
-{ |
111 |
- showInitial ($q, ''); |
112 |
-} |
113 |
-elsif ($q->param ('state') eq "perform") |
114 |
-{ |
115 |
- performAndShowResult ($q); |
116 |
-} |
117 |
-elsif ($q->param ('state') eq "tape-configure") |
118 |
-{ |
119 |
- updateTapeBackupConfig($q); |
120 |
-} |
121 |
-elsif ($q->param ('state') eq "tape-restore") |
122 |
-{ |
123 |
- performTapeRestore ($q); |
124 |
-} |
125 |
-elsif ($q->param ('state') eq "workstn-configure") |
126 |
-{ |
127 |
- WorkstnBackupConfig1($q); |
128 |
-} |
129 |
-elsif ($q->param ('state') eq "workstn-configure1") |
130 |
-{ |
131 |
- updateWorkstnBackupConfig($q); |
132 |
-} |
133 |
-elsif ($q->param ('state') eq "workstn-verify") |
134 |
-{ |
135 |
- performWorkstnVerify($q); |
136 |
-} |
137 |
-elsif ($q->param ('state') eq "workstn-restore") |
138 |
-{ |
139 |
- performWorkstnRestore ($q); |
140 |
-} |
141 |
-elsif ($q->param ('state') eq "workstn-sel-restore") |
142 |
-{ |
143 |
- performWorkstnSelRestore ($q); |
144 |
-} |
145 |
-elsif ($q->param ('state') eq "workstn-sel-restore2") |
146 |
-{ |
147 |
- performWorkstnSelRestore2 ($q); |
148 |
-} |
149 |
-else |
150 |
-{ |
151 |
- esmith::cgi::genStateError ($q, undef); |
152 |
-} |
153 |
- |
154 |
-exit (0); |
155 |
- |
156 |
-#------------------------------------------------------------ |
157 |
-# subroutine to display initial form |
158 |
-#------------------------------------------------------------ |
159 |
- |
160 |
-sub showInitial |
161 |
-{ |
162 |
- my ($q, $msg) = @_; |
163 |
- |
164 |
- my $rec = $restore->get('restore'); |
165 |
- if($msg eq '') |
166 |
- { |
167 |
- if($rec) |
168 |
- { |
169 |
- $msg = $rec->prop('errmsg') || ''; |
170 |
- $rec->delete_prop('errmsg'); |
171 |
- } |
172 |
- } |
173 |
- |
174 |
- if ($msg eq '') |
175 |
- { |
176 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
177 |
- $fm->localise('BACKUP_TITLE')); |
178 |
- } |
179 |
- else |
180 |
- { |
181 |
- esmith::cgi::genHeaderNonCacheable |
182 |
- ($q, undef, $fm->localise('OPERATION_STATUS_REPORT')); |
183 |
- |
184 |
- print $q->div ({-class => "sme-error"}, $msg); |
185 |
- print $q->hr; |
186 |
- } |
187 |
- print $q->div({-class => 'error'}, |
188 |
- $q->h5('Warning: a reboot is required before proceeding! |
189 |
- Failure to reboot now may leave your system in an unknown |
190 |
- state!')) |
191 |
- if $conf->get_prop('bootstrap-console', 'Run') eq 'yes'; |
192 |
- |
193 |
- my ($tarsize, $dumpsize, undef, undef) = &CalculateSizes(); |
194 |
- |
195 |
- my $module = $conf->get('backup'); |
196 |
- if ($module) |
197 |
- { |
198 |
- $module = $module->prop('Program'); |
199 |
- } |
200 |
- |
201 |
- # The default e-smith backup program is flexbackup. |
202 |
- |
203 |
- unless (defined $module) |
204 |
- { |
205 |
- $module = "flexbackup"; |
206 |
- } |
207 |
- elsif ($module eq '') |
208 |
- { |
209 |
- $module = "flexbackup"; |
210 |
- } |
211 |
- |
212 |
- # Hack to evaluate embedded vars |
213 |
- print eval 'return "'.$fm->localise('BACKUP_DESC_DAR').'\n";'; |
214 |
- |
215 |
- if ($tarsize =~ /Tb/ or $tarsize =~ /(\d+)Gb/ and $1 >= 2) |
216 |
- { |
217 |
- print $fm->localise("BACKUP_DESKTOP_TOO_BIG"), "\n"; |
218 |
- } |
219 |
- |
220 |
- print $q->h2($fm->localise("BACKUP_CONFIG_STATUS")),"\n"; |
221 |
- |
222 |
- my $backup_status = $conf->get('backup'); |
223 |
- if ($backup_status) |
224 |
- { |
225 |
- $backup_status = $backup_status->prop('status'); |
226 |
- } |
227 |
- |
228 |
- if (defined $backup_status && $backup_status eq "enabled") |
229 |
- { |
230 |
- my $backupTime = $conf->get('backup')->prop('backupTime'); |
231 |
- my $reminderTime = $conf->get('backup')->prop('reminderTime'); |
232 |
- |
233 |
- print $q->p ($fm->localise('TAPE_BACKUPS_ENABLED'), |
234 |
- $fm->localise('BACKUPS_RUN_AT'),$q->b($backupTime), |
235 |
- $fm->localise('REMINDER_MESSAGE_AT'),$q->b($reminderTime)), |
236 |
- "\n"; |
237 |
- } |
238 |
- else |
239 |
- { |
240 |
- print $q->p($fm->localise('TAPE_BACKUPS_DISABLED')),"\n"; |
241 |
- } |
242 |
- |
243 |
- my $backupwk_status = $conf->get('backupwk'); |
244 |
- if ($backupwk_status) |
245 |
- { |
246 |
- $backupwk_status = $backupwk_status->prop('status'); |
247 |
- } |
248 |
- |
249 |
- if (defined $backupwk_status && $backupwk_status eq "enabled") |
250 |
- { |
251 |
- my $backupwkTime = $conf->get('backupwk')->prop('BackupTime'); |
252 |
- |
253 |
- print $q->p ($fm->localise('WORKSTN_BACKUPS_ENABLED'), |
254 |
- $fm->localise('WKBACKUPS_RUN_AT'),$q->b($backupwkTime)); |
255 |
- } |
256 |
- else |
257 |
- { |
258 |
- print $q->p($fm->localise('WORKSTN_BACKUPS_DISABLED')); |
259 |
- } |
260 |
- |
261 |
- my %labels = ( |
262 |
- "desktop-backup" => $fm->localise('DESKTOP_BACKUP'), |
263 |
- "tape-configure" => $fm->localise('TAPE_CONFIGURE'), |
264 |
- "tape-restore" => $fm->localise('TAPE_RESTORE'), |
265 |
- "workstn-configure" => $fm->localise('WORKSTN_CONFIGURE'), |
266 |
- "workstn-verify" => $fm->localise('WORKSTN_VERIFY'), |
267 |
- "workstn-restore" => $fm->localise('WORKSTN_RESTORE'), |
268 |
- "workstn-sel-restore" => $fm->localise('WORKSTN_SEL_RESTORE'), |
269 |
- ); |
270 |
- |
271 |
- my @labels = ( |
272 |
- 'desktop-backup', |
273 |
- 'tape-configure', |
274 |
- 'tape-restore', |
275 |
- 'workstn-configure', |
276 |
- 'workstn-verify', |
277 |
- 'workstn-restore', |
278 |
- 'workstn-sel-restore', |
279 |
- ); |
280 |
- |
281 |
- my $default_action = 'desktop-backup'; |
282 |
- |
283 |
- my $restore_state; |
284 |
- if($rec) |
285 |
- { |
286 |
- $restore_state = $rec->prop('state'); |
287 |
- } |
288 |
- |
289 |
- unless (defined $restore_state) |
290 |
- { |
291 |
- # Undefined, set it to idle |
292 |
- if ($rec) |
293 |
- { |
294 |
- $rec->reset_props(type=>'status', state=>'idle', finish=>0, |
295 |
- start=>0); |
296 |
- } |
297 |
- else |
298 |
- { |
299 |
- $rec = $restore->new_record('restore', |
300 |
- {type=>'status', state=>'idle', finish=>0, start=>0}); |
301 |
- } |
302 |
- $restore_state = 'idle'; |
303 |
- } |
304 |
- elsif ($restore_state eq 'running') |
305 |
- { |
306 |
- my $start = $rec->prop('start'); |
307 |
- $start = scalar localtime($start); |
308 |
- |
309 |
- print $q->p ($fm->localise('RESTORE_IN_PROGRESS_BEGAN_AT') |
310 |
- . "<b>$start</b>.\n" ); |
311 |
- |
312 |
- %labels = ( |
313 |
- "refresh" => $fm->localise('REFRESH_THIS_DISPLAY'), |
314 |
- "tape-configure" => $fm->localise('CONFIGURE_TAPE_BACKUP'), |
315 |
- "workstn-configure" => $fm->localise('CONFIGURE_WORKSTN_BACKUP'), |
316 |
- ); |
317 |
- |
318 |
- @labels = ( |
319 |
- 'refresh', |
320 |
- 'tape-configure', |
321 |
- 'workstn-configure', |
322 |
- ); |
323 |
- |
324 |
- $default_action = 'refresh'; |
325 |
- } |
326 |
- elsif ($restore_state eq 'complete') |
327 |
- { |
328 |
- my $start = $rec->prop('start'); |
329 |
- $start = scalar localtime($start); |
330 |
- my $finish = $rec->prop('finish'); |
331 |
- $finish = scalar localtime($finish); |
332 |
- |
333 |
- print $q->p ($fm->localise('RESTORE_COMPLETED'),$q->br(), |
334 |
- $fm->localise('STARTED_AT'),$q->b($start),$q->br(), |
335 |
- $fm->localise('FINISHED_AT'),$q->b($finish)),"\n"; |
336 |
- |
337 |
- print $q->p ( |
338 |
- $q->b ($fm->localise('YOU_MUST_REBOOT') |
339 |
- ) |
340 |
- ),"\n"; |
341 |
- |
342 |
- $default_action = 'reboot'; |
343 |
- } |
344 |
- else |
345 |
- { |
346 |
- # Unknown state. Reset it to idle |
347 |
- |
348 |
- $rec->set_prop('state', 'idle'); |
349 |
- $restore_state = 'idle'; |
350 |
- } |
351 |
- |
352 |
- print $q->startform( |
353 |
- -method => 'POST', |
354 |
- -action => $q->url (-absolute => 1) |
355 |
- ),"\n"; |
356 |
- |
357 |
- print $q->start_table ({-class => "sme-noborders"}),"\n"; |
358 |
- |
359 |
- if ($default_action eq 'reboot') |
360 |
- { |
361 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}),"\n"; |
362 |
- print esmith::cgi::genButtonRow( |
363 |
- $q, |
364 |
- $q->submit (-name => 'action', -value => |
365 |
- $fm->localise('REBOOT')) |
366 |
- ); |
367 |
- # Put in a hidden widget to store the reboot value. |
368 |
- print $q->hidden( |
369 |
- -name => 'function', |
370 |
- -value => 'reboot' |
371 |
- ),"\n"; |
372 |
- print $q->end_table,"\n"; |
373 |
- } |
374 |
- else |
375 |
- { |
376 |
- print $q->Tr( |
377 |
- $q->td({-class => "sme-noborders-label"}, |
378 |
- $fm->localise("SELECT_AN_ACTION")), |
379 |
- $q->td({-class => "sme-noborders-content"}, |
380 |
- $q->popup_menu ( |
381 |
- -name => 'function', |
382 |
- -values => [ @labels ], |
383 |
- -default => $default_action, |
384 |
- -labels => \%labels |
385 |
- ) |
386 |
- ) |
387 |
- ),"\n"; |
388 |
- |
389 |
- } |
390 |
- |
391 |
- print $q->end_table,"\n"; |
392 |
- |
393 |
- if ($default_action ne 'reboot') |
394 |
- { |
395 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}), |
396 |
- "\n"; |
397 |
- |
398 |
- print esmith::cgi::genButtonRow( |
399 |
- $q, |
400 |
- $q->submit (-name => 'action', -value => |
401 |
- $fm->localise('PERFORM')) |
402 |
- ); |
403 |
- |
404 |
- print $q->end_table,"\n"; |
405 |
- } |
406 |
- |
407 |
- print $q->hidden ( |
408 |
- -name => 'state', |
409 |
- -override => 1, |
410 |
- -default => 'perform' |
411 |
- ),"\n"; |
412 |
- |
413 |
- print $q->endform,"\n"; |
414 |
- |
415 |
- esmith::cgi::genFooter($fm); |
416 |
- |
417 |
- return; |
418 |
-} |
419 |
- |
420 |
-sub performAndShowResult |
421 |
-{ |
422 |
- my ($q) = @_; |
423 |
- |
424 |
- my $function = $q->param ('function'); |
425 |
- |
426 |
- if ($function eq 'refresh') |
427 |
- { |
428 |
- showInitial ($q, ''); |
429 |
- } |
430 |
- elsif ($function eq 'reboot') |
431 |
- { |
432 |
- performReboot(); |
433 |
- } |
434 |
- elsif ($function eq 'desktop-backup') |
435 |
- { |
436 |
- desktopBackup(); |
437 |
- } |
438 |
- elsif ($function eq 'tape-configure') |
439 |
- { |
440 |
- TapeBackupConfig ($q); |
441 |
- } |
442 |
- elsif ($function eq 'tape-restore') |
443 |
- { |
444 |
- tapeRestore(); |
445 |
- } |
446 |
- elsif ($function eq 'workstn-configure') |
447 |
- { |
448 |
- WorkstnBackupConfig ($q); |
449 |
- } |
450 |
- elsif ($function eq 'workstn-verify') |
451 |
- { |
452 |
- workstnVerify(); |
453 |
- } |
454 |
- elsif ($function eq 'workstn-restore') |
455 |
- { |
456 |
- workstnRestore(); |
457 |
- } |
458 |
- elsif ($function eq 'workstn-sel-restore') |
459 |
- { |
460 |
- workstnSelRestore(); |
461 |
- } |
462 |
- else |
463 |
- { |
464 |
- # Unknown function - refresh the screen anyway |
465 |
- showInitial ($q, 'unknown'); |
466 |
- } |
467 |
- |
468 |
- return; |
469 |
- |
470 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
471 |
- $fm->localise("X_BACKUP_OR_RESTORE")); |
472 |
- print $q->p ( $function ); |
473 |
- esmith::cgi::genFooter($fm); |
474 |
-} |
475 |
- |
476 |
-sub desktopBackupRecordStatus |
477 |
-{ |
478 |
- my ($backup, $phase, $status) = @_; |
479 |
- my $now = time(); |
480 |
- |
481 |
- warn("Backup terminated: $phase failed - status: $status\n"); |
482 |
- $backup->set_prop('EndEpochTime', "$now"); |
483 |
- $backup->set_prop('Result', "$phase:$status"); |
484 |
-} |
485 |
- |
486 |
-sub desktopBackup () |
487 |
-{ |
488 |
- # Generate a header that will trigger a download and send data as |
489 |
- # an octet stream. |
490 |
- |
491 |
- my $backups = esmith::BackupHistoryDB->open; |
492 |
- my $now = time(); |
493 |
- my $backup_rec = $backups->new_record($now, { |
494 |
- type => 'backup_record', |
495 |
- BackupType => 'desktop', |
496 |
- StartEpochTime => $now, |
497 |
- }); |
498 |
- |
499 |
- # Dump the current mysql tables so that they are part of the image. |
500 |
- # The events handle cases where mysqld is not enabled, and/or is |
501 |
- # not running. |
502 |
- |
503 |
- my $status = system("/sbin/e-smith/signal-event", "pre-backup", "desktop"); |
504 |
- if ($status) |
505 |
- { |
506 |
- desktopBackupRecordStatus($backup_rec, 'pre-backup', $status); |
507 |
- esmith::cgi::genHeaderNonCacheable( |
508 |
- $fm->{cgi}, |
509 |
- undef, $fm->localise('OPERATION_STATUS_REPORT')); |
510 |
- esmith::cgi::genResult( |
511 |
- $fm->{cgi}, $fm->localise('ERR_PRE_BACKUP')); |
512 |
- return; |
513 |
- } |
514 |
- |
515 |
- print "Expires: 0\n"; |
516 |
- print "Content-type: application/octet-stream\n"; |
517 |
- print "Content-disposition: attachment; filename=smeserver.tgz\n"; |
518 |
- print "\n"; |
519 |
- setpgrp; |
520 |
- my $ourpgrp = getpgrp; |
521 |
- local $SIG{PIPE} = sub |
522 |
- { |
523 |
- local $SIG{HUP} = 'IGNORE'; |
524 |
- warn "Got sigpipe - sending HUP to $ourpgrp\n"; |
525 |
- kill HUP => -$ourpgrp; |
526 |
- desktopBackupRecordStatus($backup_rec, |
527 |
- 'send2browser', 'Incomplete'); |
528 |
- exit 1; |
529 |
- }; |
530 |
- |
531 |
- open(RD, |
532 |
- "/bin/tar --directory / --create @directories --file=-" |
533 |
- . " | /usr/bin/gzip |" |
534 |
- ); |
535 |
- |
536 |
- while (<RD>) |
537 |
- { |
538 |
- print; |
539 |
- } |
540 |
- |
541 |
- close RD; |
542 |
- |
543 |
- # Remove the dumped tables. |
544 |
- |
545 |
- $status = system("/sbin/e-smith/signal-event", "post-backup", "desktop"); |
546 |
- if ($status) |
547 |
- { |
548 |
- desktopBackupRecordStatus($backup_rec, 'post-backup', $status); |
549 |
- die ($fm->localise('ERR_POST_BACKUP'),"\n"); |
550 |
- } |
551 |
- $now = time(); |
552 |
- $backup_rec->set_prop('EndEpochTime', "$now"); |
553 |
- $backup_rec->set_prop('Result', "0"); |
554 |
-} |
555 |
- |
556 |
-sub TapeBackupConfig |
557 |
-{ |
558 |
- my ($q) = @_; |
559 |
- my $enabledChk = ""; |
560 |
- my $backupAMPM = 'AM'; |
561 |
- my $backupMin; |
562 |
- my $backupHour; |
563 |
- my $reminderAMPM = 'AM'; |
564 |
- my $reminderMin; |
565 |
- my $reminderHour; |
566 |
- |
567 |
- esmith::cgi::genHeaderNonCacheable( |
568 |
- $q, undef, $fm->localise('ENABLE_DISABLE_TAPE')); |
569 |
- |
570 |
- print $q->p ($fm->localise('TAPE_CONFIG_DESC')); |
571 |
- |
572 |
- # Obtain time for backup from the backup cron template |
573 |
- my $rec = $conf->get('backup'); |
574 |
- my $backupTime = "2:00"; |
575 |
- if ($rec) |
576 |
- { |
577 |
- $backupTime = $rec->prop('backupTime') || "2:00"; |
578 |
- } |
579 |
- |
580 |
- ($backupHour, $backupMin) = split (":", $backupTime, -1); |
581 |
- |
582 |
- if ($backupHour > 11) |
583 |
- { |
584 |
- if ($backupHour > 12) |
585 |
- { |
586 |
- $backupHour -= 12; |
587 |
- } |
588 |
- $backupAMPM = 'PM'; |
589 |
- } |
590 |
- |
591 |
- # Obtain time for reminder notice from the backup cron template |
592 |
- my $reminderTime = "14:00"; |
593 |
- if ($rec) |
594 |
- { |
595 |
- $reminderTime = $rec->prop('reminderTime') || "14:00"; |
596 |
- } |
597 |
- |
598 |
- ($reminderHour, $reminderMin) = split (":", $reminderTime, -1); |
599 |
- |
600 |
- if ($reminderHour > 12) |
601 |
- { |
602 |
- $reminderHour -= 12; |
603 |
- $reminderAMPM = 'PM'; |
604 |
- } |
605 |
- |
606 |
- print $q->startform( |
607 |
- -method => 'POST', |
608 |
- -action => $q->url (-absolute => 1) |
609 |
- ); |
610 |
- |
611 |
- print $q->start_table ({-class => "sme-noborders"}); |
612 |
- |
613 |
- my $backup_status; |
614 |
- if ($rec) |
615 |
- { |
616 |
- $backup_status = $rec->prop('status'); |
617 |
- } |
618 |
- |
619 |
- if (defined $backup_status && $backup_status eq "enabled") |
620 |
- { |
621 |
- $enabledChk = "checked"; |
622 |
- } |
623 |
- |
624 |
- print $q->Tr( |
625 |
- $q->td( |
626 |
- $fm->localise('ENABLE_TAPE_BACKUP') |
627 |
- . " <input type=\"checkbox\"" |
628 |
- . " name=\"tapebackup\"" |
629 |
- . " $enabledChk" |
630 |
- . " value=\"on\">" |
631 |
- ) |
632 |
- ); |
633 |
- |
634 |
- print $q->Tr( |
635 |
- esmith::cgi::genCell( |
636 |
- $q,$fm->localise('TAPE_BACKUP_TIME') |
637 |
- ), |
638 |
- |
639 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupHour', |
640 |
- -override => 1, |
641 |
- -default => $backupHour, |
642 |
- -size => 2)), |
643 |
- |
644 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupMin', |
645 |
- -override => 1, |
646 |
- -default => $backupMin, |
647 |
- -size => 2)), |
648 |
- |
649 |
- esmith::cgi::genCell ($q, "AM/PM:"), |
650 |
- |
651 |
- esmith::cgi::genCell ($q, $q->popup_menu (-name => 'backupAMPM', |
652 |
- -values => ['AM', 'PM'], |
653 |
- -default => $backupAMPM))); |
654 |
- |
655 |
- my %timelabels=('AM' => $fm->localise('AM'),'PM' => $fm->localise('PM')); |
656 |
- print $q->Tr( |
657 |
- esmith::cgi::genCell( |
658 |
- $q, $fm->localise('LOAD_TAPE_REMINDER_TIME') |
659 |
- ), |
660 |
- |
661 |
- esmith::cgi::genCell( |
662 |
- $q, |
663 |
- $q->textfield( |
664 |
- -name => 'reminderHour', |
665 |
- -override => 1, |
666 |
- -default => $reminderHour, |
667 |
- -size => 2 |
668 |
- ) |
669 |
- ), |
670 |
- |
671 |
- esmith::cgi::genCell( |
672 |
- $q, |
673 |
- $q->textfield( |
674 |
- -name => 'reminderMin', |
675 |
- -override => 1, |
676 |
- -default => $reminderMin, |
677 |
- -size => 2 |
678 |
- ) |
679 |
- ), |
680 |
- |
681 |
- esmith::cgi::genCell($q, $fm->localise("AM/PM").":"), |
682 |
- |
683 |
- esmith::cgi::genCell( |
684 |
- $q, |
685 |
- $q->popup_menu( |
686 |
- -name => 'reminderAMPM', |
687 |
- -values => ['AM', 'PM'], |
688 |
- -labels => \%timelabels, |
689 |
- -default => $reminderAMPM |
690 |
- ) |
691 |
- ) |
692 |
- ); |
693 |
- |
694 |
- print "</table>\n"; |
695 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}); |
696 |
- print $q->Tr($q->th({-class => "sme-layout"}, |
697 |
- $q->submit( |
698 |
- -name => 'action', |
699 |
- -value => $fm->localise('UPDATE_CONF') |
700 |
- ) |
701 |
- ) |
702 |
- ); |
703 |
- |
704 |
- print $q->hidden( |
705 |
- -name => 'state', |
706 |
- -override => 1, |
707 |
- -default => 'tape-configure' |
708 |
- ); |
709 |
- |
710 |
- print $q->endform; |
711 |
- print '</table>'; |
712 |
- |
713 |
- esmith::cgi::genFooter($fm); |
714 |
- return; |
715 |
-} |
716 |
- |
717 |
-sub updateTapeBackupConfig |
718 |
-{ |
719 |
- my ($q) = @_; |
720 |
- |
721 |
- my $status = $q->param ('tapebackup'); |
722 |
- my $ampm; |
723 |
- |
724 |
- esmith::cgi::genHeaderNonCacheable( |
725 |
- $q, |
726 |
- undef, $fm->localise('UPDATING_TAPE_CONF') |
727 |
- ); |
728 |
- |
729 |
- if (defined $status && $status eq "on") |
730 |
- { |
731 |
- |
732 |
- #-------------------------------------------------- |
733 |
- # Untaint parameters and check for validity |
734 |
- #-------------------------------------------------- |
735 |
- |
736 |
- my $backupHour = $q->param ('backupHour'); |
737 |
- if ($backupHour =~ /^(.*)$/) { |
738 |
- $backupHour = $1; |
739 |
- } else { |
740 |
- $backupHour = "12"; |
741 |
- } |
742 |
- if (($backupHour < 1) || ($backupHour > 12)) |
743 |
- { |
744 |
- esmith::cgi::genResult( |
745 |
- $fm->{cgi}, $fm->localise('ERR_INVALID_HOUR').$backupHour. |
746 |
- $fm->localise('BETWEEN_1_AND_12') |
747 |
- ); |
748 |
- |
749 |
- return; |
750 |
- } |
751 |
- |
752 |
- my $backupMin = $q->param ('backupMin'); |
753 |
- if ($backupMin =~ /^(.*)$/) { |
754 |
- $backupMin = $1; |
755 |
- } else { |
756 |
- $backupMin = "0"; |
757 |
- } |
758 |
- if (($backupMin < 0) || ($backupMin > 59)) |
759 |
- { |
760 |
- esmith::cgi::genResult( |
761 |
- $fm->{cgi}, $fm->localise('ERR_INVALID_MINUTE').$backupMin. |
762 |
- $fm->localise('BETWEEN_0_AND_59') |
763 |
- ); |
764 |
- |
765 |
- return; |
766 |
- } |
767 |
- |
768 |
- $backupMin = sprintf("%02d", $backupMin); |
769 |
- |
770 |
- $ampm = $q->param ('backupAMPM'); |
771 |
- if ($ampm =~ /^(.*)$/) { |
772 |
- $ampm = $1; |
773 |
- } else { |
774 |
- $ampm = "AM"; |
775 |
- } |
776 |
- |
777 |
- # convert to 24 hour time |
778 |
- |
779 |
- $backupHour = $backupHour % 12; |
780 |
- if ($ampm eq "PM") |
781 |
- { |
782 |
- $backupHour = $backupHour + 12; |
783 |
- } |
784 |
- |
785 |
- my $reminderHour = $q->param ('reminderHour'); |
786 |
- if ($reminderHour =~ /^(.*)$/) { |
787 |
- $reminderHour = $1; |
788 |
- } else { |
789 |
- $reminderHour = "12"; |
790 |
- } |
791 |
- if (($reminderHour < 1) || ($reminderHour > 12)) |
792 |
- { |
793 |
- esmith::cgi::genResult( |
794 |
- $fm->{cgi}, |
795 |
- $fm->localise('ERR_INVALID_REMINDER_HOUR').$reminderHour |
796 |
- .$fm->localise('BETWEEN_1_AND_12') |
797 |
- ); |
798 |
- |
799 |
- return; |
800 |
- } |
801 |
- |
802 |
- my $reminderMin = $q->param ('reminderMin'); |
803 |
- if ($reminderMin =~ /^(.*)$/) { |
804 |
- $reminderMin = $1; |
805 |
- } else { |
806 |
- $reminderMin = "0"; |
807 |
- } |
808 |
- if (($reminderMin < 0) || ($reminderMin > 59)) |
809 |
- { |
810 |
- esmith::cgi::genResult( |
811 |
- $fm->{cgi}, $fm->localise('ERR_INVALID_REMINDER_MINUTE'). |
812 |
- $reminderMin.$fm->localise('BETWEEN_0_AND_59') |
813 |
- ); |
814 |
- return; |
815 |
- } |
816 |
- |
817 |
- $reminderMin = sprintf("%02d", $reminderMin); |
818 |
- |
819 |
- $ampm = $q->param ('reminderAMPM'); |
820 |
- if ($ampm =~ /^(.*)$/) { |
821 |
- $ampm = $1; |
822 |
- } else { |
823 |
- $ampm = "AM"; |
824 |
- } |
825 |
- |
826 |
- # convert to 24 hour time |
827 |
- |
828 |
- $reminderHour = $reminderHour % 12; |
829 |
- if ($ampm eq "PM") |
830 |
- { |
831 |
- $reminderHour = $reminderHour + 12; |
832 |
- } |
833 |
- |
834 |
- # variables passed validity checks, set configuration database values |
835 |
- my $old = $conf->get('UnsavedChanges')->value; |
836 |
- |
837 |
- my $rec = $conf->get('backup'); |
838 |
- unless (defined $rec) |
839 |
- { |
840 |
- $rec = $conf->new_record('backup', {type=>'service'}); |
841 |
- } |
842 |
- |
843 |
- $rec->set_prop('status', 'enabled'); |
844 |
- |
845 |
- my $module = $rec->prop('Program'); |
846 |
- |
847 |
- # The default e-smith backup program is flexbackup. |
848 |
- |
849 |
- unless (defined $module) |
850 |
- { |
851 |
- $module = "flexbackup"; |
852 |
- } |
853 |
- elsif ($module eq '') |
854 |
- { |
855 |
- $module = "flexbackup"; |
856 |
- } |
857 |
- |
858 |
- $rec->set_prop('Program', $module); |
859 |
- $rec->set_prop('backupTime', "$backupHour:$backupMin"); |
860 |
- $rec->set_prop('reminderTime', "$reminderHour:$reminderMin"); |
861 |
- |
862 |
- $conf->get('UnsavedChanges')->set_value($old); |
863 |
- |
864 |
- system("/sbin/e-smith/signal-event", "conf-backup") == 0 |
865 |
- or die($fm->localise('ERR_CONF_BACKUP'),"\n"); |
866 |
- |
867 |
- esmith::cgi::genResult( |
868 |
- $fm->{cgi}, $fm->localise('SUCCESSFULLY_ENABLED_TAPE').$q->br(). |
869 |
- $fm->localise('WITH_BACKUP_TIME')."$backupHour:$backupMin". |
870 |
- $q->br().$fm->localise('WITH_REMINDER_TIME'). |
871 |
- "$reminderHour:$reminderMin"); |
872 |
- } |
873 |
- else |
874 |
- { |
875 |
- # set service to disabled |
876 |
- my $old = $conf->get('UnsavedChanges')->value; |
877 |
- |
878 |
- my $rec = $conf->get('backup'); |
879 |
- unless ($rec) |
880 |
- { |
881 |
- $rec = $conf->new_record('backup', {type=>'service'}); |
882 |
- } |
883 |
- |
884 |
- $rec->set_prop('status', 'disabled'); |
885 |
- $conf->get('UnsavedChanges')->set_value($old); |
886 |
- |
887 |
- system("/sbin/e-smith/signal-event", "conf-backup") == 0 |
888 |
- or die($fm->localise('ERR_CONF_BACKUP')."\n"); |
889 |
- |
890 |
- esmith::cgi::genResult( |
891 |
- $fm->{cgi}, $fm->localise('SUCCESSFULLY_DISABLED') |
892 |
- ); |
893 |
- } |
894 |
- |
895 |
- return; |
896 |
-} |
897 |
- |
898 |
-sub tapeRestore () |
899 |
-{ |
900 |
- esmith::cgi::genHeaderNonCacheable( |
901 |
- $q, undef, $fm->localise('RESTORE_CONF_FROM_TAPE')); |
902 |
- |
903 |
- print $fm->localise('RESTORE_CONF_FROM_TAPE_DESC'); |
904 |
- |
905 |
- print $q->start_multipart_form( |
906 |
- -method => 'POST', |
907 |
- -action => $q->url (-absolute => 1) |
908 |
- ); |
909 |
- |
910 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}); |
911 |
- |
912 |
- print esmith::cgi::genButtonRow( |
913 |
- $q, |
914 |
- $q->submit (-name => 'action', |
915 |
- -value => $fm->localise('RESTORE_FROM_TAPE')) |
916 |
- ); |
917 |
- print "</table>\n"; |
918 |
- print $q->hidden( |
919 |
- -name => 'state', |
920 |
- -override => 1, |
921 |
- -default => 'tape-restore' |
922 |
- ); |
923 |
- |
924 |
- print $q->endform; |
925 |
- esmith::cgi::genFooter($fm); |
926 |
-} |
927 |
- |
928 |
-sub performTapeRestore |
929 |
-{ |
930 |
- my ($q) = @_; |
931 |
- |
932 |
- #---------------------------------------- |
933 |
- # restore system from backup tape |
934 |
- #---------------------------------------- |
935 |
- |
936 |
- my $lock_file = "/var/lock/subsys/e-smith-restore"; |
937 |
- my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file); |
938 |
- |
939 |
- unless ($file_handle) |
940 |
- { |
941 |
- esmith::cgi::genHeaderNonCacheable( |
942 |
- $q, |
943 |
- undef, |
944 |
- $fm->localise('UNABLE_TO_RESTORE_CONF') |
945 |
- ); |
946 |
- |
947 |
- print $q->p ( |
948 |
- $q->b ($fm->localise('ANOTHER_RESTORE_IN_PROGRESS') |
949 |
- ) |
950 |
- ); |
951 |
- |
952 |
- esmith::cgi::genFooter($fm); |
953 |
- return; |
954 |
- } |
955 |
- |
956 |
- my $rec = $restore->get('restore'); |
957 |
- $rec->set_prop('state', 'running'); |
958 |
- $rec->set_prop('start', time); |
959 |
- |
960 |
- my $sec = 10; |
961 |
- print "Refresh: $sec; URL=/server-manager/cgi-bin/backup\n"; |
962 |
- esmith::cgi::genHeaderNonCacheable( |
963 |
- $q, undef, $fm->localise() |
964 |
- ); |
965 |
- |
966 |
- print $q->p($fm->localise('NOW_RESTORING_FROM_TAPE') |
967 |
- ); |
968 |
- |
969 |
- print $q->p ( |
970 |
- $q->b ($fm->localise('MUST_REBOOT_AFTER_RESTORE')) |
971 |
- ); |
972 |
- |
973 |
- print $q->p($fm->localise('PAGE_REFRESH_IN', {sec=>$sec})); |
974 |
- |
975 |
- my $child; |
976 |
- |
977 |
- if ($child = fork) |
978 |
- { |
979 |
- # Parent |
980 |
- |
981 |
- $SIG{'CHLD'} = 'IGNORE'; |
982 |
- &esmith::lockfile::UnlockFile($file_handle); |
983 |
- |
984 |
- esmith::cgi::genFooter($fm); |
985 |
- return; |
986 |
- } |
987 |
- elsif (defined $child) |
988 |
- { |
989 |
- # Child |
990 |
- |
991 |
- # Re-establish the lock. Wait till it is relinquished by the parent. |
992 |
- |
993 |
- $file_handle = &esmith::lockfile::LockFileOrWait($lock_file); |
994 |
- |
995 |
- # Close STDOUT so that the web server connection is closed. |
996 |
- |
997 |
- close STDOUT; |
998 |
- |
999 |
- # Now reopen STDOUT for the child. Redirect it to STDERR. |
1000 |
- |
1001 |
- open(STDOUT, ">&STDERR"); |
1002 |
- |
1003 |
- unless(system("/sbin/e-smith/signal-event", "pre-restore") == 0) |
1004 |
- { |
1005 |
- $rec->set_prop('errmsg', $fm->localise('ERR_PRE_RESTORE')); |
1006 |
- $rec->delete_prop('state'); |
1007 |
- die ($fm->localise('ERR_PRE_RESTORE'),"\n"); |
1008 |
- } |
1009 |
- unless(system("/sbin/e-smith/signal-event", "restore-tape") == 0) |
1010 |
- { |
1011 |
- $rec->set_prop('errmsg', $fm->localise('ERR_RESTORING_FROM_TAPE')); |
1012 |
- $rec->delete_prop('state'); |
1013 |
- die ($fm->localise('ERR_RESTORING_FROM_TAPE')."\n"); |
1014 |
- } |
1015 |
- |
1016 |
- #---------------------------------------- |
1017 |
- # regenerate configuration files |
1018 |
- #---------------------------------------- |
1019 |
- |
1020 |
- unless(system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0) |
1021 |
- { |
1022 |
- $rec->set_prop('errmsg', $rec->prop('errmsg').'<br>'. |
1023 |
- $fm->localise('ERR_RESTORING_GID')); |
1024 |
- warn ($fm->localise('ERR_RESTORING_GID')."\n"); |
1025 |
- } |
1026 |
- unless(system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0) |
1027 |
- { |
1028 |
- $rec->set_prop('errmsg', $rec->prop('errmsg').'<br>'. |
1029 |
- $fm->localise('ERR_RESTORING_INITIAL_GRP')); |
1030 |
- warn ($fm->localise('ERR_RESTORING_INITIAL_GRP')."\n"); |
1031 |
- } |
1032 |
- unless(system("/sbin/e-smith/signal-event", "post-upgrade") == 0) |
1033 |
- { |
1034 |
- $rec->set_prop('errmsg', $rec->prop('errmsg').'<br>'. |
1035 |
- $fm->localise('ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); |
1036 |
- $rec->delete_prop('state'); |
1037 |
- die ($fm->localise('ERR_UPDATING_CONF_AFTER_TAPE_RESTORE')); |
1038 |
- } |
1039 |
- |
1040 |
- my $finish = time; |
1041 |
- $rec->set_prop('state', 'complete'); |
1042 |
- $rec->set_prop('finish', $finish); |
1043 |
- |
1044 |
- my $start = $rec->prop('start'); |
1045 |
- $start = scalar localtime($start); |
1046 |
- $finish = scalar localtime($finish); |
1047 |
- |
1048 |
- &esmith::lockfile::UnlockFile($file_handle); |
1049 |
- |
1050 |
- exit; |
1051 |
- } |
1052 |
- else |
1053 |
- { |
1054 |
- # Error |
1055 |
- |
1056 |
- $rec->delete_prop('state'); |
1057 |
- $rec->set_prop('errmsg', $fm->localise('COULD_NOT_FORK')); |
1058 |
- die ($fm->localise("COULD_NOT_FORK")."$!\n"); |
1059 |
- } |
1060 |
-} |
1061 |
- |
1062 |
-sub WorkstnBackupConfig |
1063 |
-{ |
1064 |
- my ($q) = @_; |
1065 |
- my $backupwk_status; |
1066 |
- my $enabledIncOnlyTimeout = ""; |
1067 |
- my $backupwkLogin = 'backup'; |
1068 |
- my $backupwkPassword = 'backup'; |
1069 |
- my $backupwkStation = 'host'; |
1070 |
- my $backupwkFolder = 'share'; |
1071 |
- my $setsNumber; |
1072 |
- my $filesinset; |
1073 |
- my $backupwkTime; |
1074 |
- my $backupwkTimeout; |
1075 |
- my $backupwkIncOnlyTimeout; |
1076 |
- my $compression; |
1077 |
- my $VFSType; |
1078 |
- my $dof; |
1079 |
- my @dlabels = split(' ', $fm->localise('DOW')); |
1080 |
- my @VFST = ('cifs', 'nfs', 'usb'); |
1081 |
- my %VFST = ('cifs', 'cifs', 'nfs', 'nfs', 'usb', 'local usb disk'); |
1082 |
- |
1083 |
- # Obtain backup informations from configuration |
1084 |
- my $rec = $conf->get('backupwk'); |
1085 |
- if ($rec) |
1086 |
- { |
1087 |
- $backupwkTime = $rec->prop('BackupTime') || '2:00'; |
1088 |
- $backupwkLogin = $rec->prop('Login') || 'backup'; |
1089 |
- $backupwkPassword = $rec->prop('Password') || 'backup'; |
1090 |
- $backupwkStation = $rec->prop('SmbHost') || 'host'; |
1091 |
- $backupwkFolder = $rec->prop('SmbShare') || 'share'; |
1092 |
- $setsNumber = $rec->prop('SetsMax') || '1'; |
1093 |
- $filesinset = $rec->prop('DaysInSet') || '1'; |
1094 |
- $backupwkTimeout = $rec->prop('Timeout') || '12'; |
1095 |
- $backupwkIncOnlyTimeout = $rec->prop('IncOnlyTimeout') || 'yes'; |
1096 |
- $compression = $rec->prop('Compression') || '0'; |
1097 |
- $dof = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; |
1098 |
- $VFSType = $rec->prop('VFSType') || 'cifs'; |
1099 |
- $backupwk_status = $rec->prop('status'); |
1100 |
- } |
1101 |
- |
1102 |
- esmith::cgi::genHeaderNonCacheable( |
1103 |
- $q, undef, $fm->localise('CONFIGURE_WORKSTN_BACKUP')); |
1104 |
- |
1105 |
- if ($rec) { |
1106 |
- print $fm->localise('WORKSTN_BACKUP_DESC'); |
1107 |
- print $fm->localise('WORKSTN_BACKUP_ENABLED'), |
1108 |
- $q->b(' '.$fm->localise(uc($backupwk_status))), '.<br/>'; |
1109 |
- if ($VFSType eq 'usb') { |
1110 |
- print $fm->localise('WORKSTN_BACKUP_USB'), '<br/>'; |
1111 |
- } |
1112 |
- else { |
1113 |
- print $fm->localise('WORKSTN_BACKUP_HOST'), ' ', $backupwkStation; |
1114 |
- print ' ', $fm->localise('WORKSTN_BACKUP_VFSTYPE'), ' ', $VFSType, '<br/>'; |
1115 |
- } |
1116 |
- print $fm->localise('WORKSTN_BACKUP_SHARE'), ' ', $backupwkFolder, '<br/>'; |
1117 |
- if ($VFSType eq 'cifs') { |
1118 |
- print $fm->localise('LOGIN'), ' ', $backupwkLogin, '<br/>'; |
1119 |
- print $fm->localise('PASSWORD'), ' ********<br/>'; |
1120 |
- } |
1121 |
- print $fm->localise('WORKSTN_BACKUP_SETSNUM'), ' ', $setsNumber, '<br/>'; |
1122 |
- print $fm->localise('WORKSTN_BACKUP_DAYSINSET'), ' ', $filesinset, '<br/>'; |
1123 |
- print $fm->localise('WORKSTN_BACKUP_COMPRESSION'), ' ', $compression, '<br/>'; |
1124 |
- print $fm->localise('WORKSTN_BACKUP_TOD'), ' ', $backupwkTime, '<br/>'; |
1125 |
- print $fm->localise('WORKSTN_BACKUP_TIMEOUT'), ' ', $backupwkTimeout, ' ', $fm->localise('HOURS'); |
1126 |
- if ( $backupwkIncOnlyTimeout eq 'yes' ) {print $fm->localise('WORKSTN_BACKUP_INCONLY_TIMEOUT')} |
1127 |
- print '<br/>'; |
1128 |
- if ( $dof eq '7' ) { |
1129 |
- print $fm->localise('WORKSTN_FULL_BACKUP_EVERYDAY', '<br/>'); |
1130 |
- } |
1131 |
- else { |
1132 |
- print $fm->localise('WORKSTN_FULL_BACKUP_DAY'), ' ', $dlabels[$dof], '<br/>'; |
1133 |
- } |
1134 |
- } |
1135 |
- else { print $fm->localise('WORKSTN_BACKUP_NOT_CONFIGURED'), '<br/>' } |
1136 |
- |
1137 |
- print $q->startform( |
1138 |
- -method => 'POST', |
1139 |
- -action => $q->url (-absolute => 1) |
1140 |
- ); |
1141 |
- |
1142 |
- print $q->start_table ({-class => "sme-noborders"}); |
1143 |
- |
1144 |
- print $q->Tr($q->td($q->h3 ($fm->localise('WORKSTATION_BACKUP_SETCONF')))); |
1145 |
- |
1146 |
- |
1147 |
- print $q->Tr( |
1148 |
- esmith::cgi::genCell( |
1149 |
- $q, |
1150 |
- $fm->localise('SELECT_VFS_TYPE') |
1151 |
- ), |
1152 |
- |
1153 |
- esmith::cgi::genCell ($q, $q->popup_menu (-name => 'VFSType', |
1154 |
- -values => [ @VFST ], |
1155 |
- -labels => \%VFST, |
1156 |
- -default => $VFSType))); |
1157 |
- |
1158 |
- print "</table>\n"; |
1159 |
- |
1160 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}); |
1161 |
- print $q->Tr($q->th({-class => "sme-layout"}, |
1162 |
- $q->submit( |
1163 |
- -name => 'action', |
1164 |
- -value => $fm->localise('NEXT') |
1165 |
- ) |
1166 |
- ) |
1167 |
- ); |
1168 |
- |
1169 |
- print $q->hidden( |
1170 |
- -name => 'state', |
1171 |
- -override => 1, |
1172 |
- -default => 'workstn-configure' |
1173 |
- ); |
1174 |
- print '</table>'; |
1175 |
- |
1176 |
- print $q->endform; |
1177 |
- |
1178 |
- esmith::cgi::genFooter ($q); |
1179 |
- return; |
1180 |
-} |
1181 |
- |
1182 |
-sub WorkstnBackupConfig1 |
1183 |
-{ |
1184 |
- my ($q) = @_; |
1185 |
- my $enabledChk = ""; |
1186 |
- my $enabledIncOnlyTimeout = ""; |
1187 |
- my $backupwkAMPM = 'AM'; |
1188 |
- my $backupwkMin; |
1189 |
- my $backupwkHour; |
1190 |
- my $backupwkLogin = 'backup'; |
1191 |
- my $backupwkPassword = 'backup'; |
1192 |
- my $backupwkStation = 'host'; |
1193 |
- my $backupwkFolder = 'share'; |
1194 |
- my $setsNumber; |
1195 |
- my $filesinset; |
1196 |
- my $backupwkTimeout; |
1197 |
- my $backupwkIncOnlyTimeout; |
1198 |
- my $compression; |
1199 |
- my $VFSType = $q->param ('VFSType'); |
1200 |
- my $dof; |
1201 |
- my @usbdisks; |
1202 |
- my %dlabels = (); |
1203 |
- my @dlabels = split(' ', $fm->localise('DOW')); |
1204 |
- my $i = 0; |
1205 |
- foreach (@dlabels) { |
1206 |
- $dlabels{$i} = $_; |
1207 |
- $i++; |
1208 |
- } |
1209 |
- |
1210 |
- # Obtain backup informations from configuration |
1211 |
- my $rec = $conf->get('backupwk'); |
1212 |
- my $backupwkTime = '2:00'; |
1213 |
- if ($rec) |
1214 |
- { |
1215 |
- $backupwkTime = $rec->prop('BackupTime') || '2:00'; |
1216 |
- $backupwkLogin = $rec->prop('Login') || 'backup'; |
1217 |
- $backupwkPassword = $rec->prop('Password') || 'backup'; |
1218 |
- $backupwkStation = $rec->prop('SmbHost') || 'host'; |
1219 |
- $backupwkFolder = $rec->prop('SmbShare') || 'share'; |
1220 |
- $setsNumber = $rec->prop('SetsMax') || '1'; |
1221 |
- $filesinset = $rec->prop('DaysInSet') || '1'; |
1222 |
- $backupwkTimeout = $rec->prop('Timeout') || '12'; |
1223 |
- $backupwkIncOnlyTimeout = $rec->prop('IncOnlyTimeout') || 'yes'; |
1224 |
- $compression = $rec->prop('Compression') || '0'; |
1225 |
- $dof = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7'; |
1226 |
- } |
1227 |
- |
1228 |
- ($backupwkHour, $backupwkMin) = split (':', $backupwkTime, -1); |
1229 |
- |
1230 |
- if ($backupwkHour > 12) |
1231 |
- { |
1232 |
- $backupwkHour -= 12; |
1233 |
- $backupwkAMPM = 'PM'; |
1234 |
- } |
1235 |
- |
1236 |
- my $backupwk_status; |
1237 |
- if ($rec) |
1238 |
- { |
1239 |
- $backupwk_status = $rec->prop('status'); |
1240 |
- } |
1241 |
- |
1242 |
- if (defined $backupwk_status && $backupwk_status eq 'enabled') |
1243 |
- { |
1244 |
- $enabledChk = 'checked'; |
1245 |
- } |
1246 |
- |
1247 |
- if (defined $backupwkIncOnlyTimeout && $backupwkIncOnlyTimeout eq 'yes') |
1248 |
- { |
1249 |
- $enabledIncOnlyTimeout = 'checked'; |
1250 |
- } |
1251 |
- |
1252 |
- esmith::cgi::genHeaderNonCacheable( |
1253 |
- $q, undef, $fm->localise('CONFIGURE_WORKSTN_BACKUP')); |
1254 |
- |
1255 |
- if ( $VFSType eq 'usb' ) { |
1256 |
- foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { |
1257 |
- $udi =~ m/^(\S+)/; |
1258 |
- my $vollbl = qx(hal-get-property --udi $1 --key volume.label); |
1259 |
- $vollbl =~ m/^(\S+)/; |
1260 |
- if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} |
1261 |
- push @usbdisks, lc($vollbl); |
1262 |
- } |
1263 |
- |
1264 |
- unless ($usbdisks[0]){ |
1265 |
- esmith::cgi::genResult( |
1266 |
- $fm->{cgi}, $fm->localise('ERR_NO_USB_DISK')); |
1267 |
- return |
1268 |
- } |
1269 |
- } |
1270 |
- |
1271 |
- print $q->startform( |
1272 |
- -method => 'POST', |
1273 |
- -action => $q->url (-absolute => 1) |
1274 |
- ); |
1275 |
- |
1276 |
- print $fm->localise('CONFIGURE_WORKSTN_BACKUP_DESC'); |
1277 |
- |
1278 |
- print $q->start_table ({-class => "sme-noborders"}); |
1279 |
- |
1280 |
- print $q->Tr( |
1281 |
- $q->td( |
1282 |
- $fm->localise('ENABLE_WORKSTN_BACKUP') |
1283 |
- . " <input type=\"checkbox\"" |
1284 |
- . " name=\"workstnbackup\"" |
1285 |
- . " $enabledChk" |
1286 |
- . " value=\"on\">" |
1287 |
- ) |
1288 |
- ); |
1289 |
- |
1290 |
- print $q->Tr($q->td($q->h3 ($fm->localise('WORKSTATION_BACKUP_DEST')))); |
1291 |
- |
1292 |
- if ( $VFSType eq 'usb' ) { |
1293 |
- print $q->Tr( |
1294 |
- esmith::cgi::genCell( |
1295 |
- $q, |
1296 |
- $fm->localise('WORKSTN_NAME') |
1297 |
- ), |
1298 |
- |
1299 |
- esmith::cgi::genCell ($q, 'localhost'), |
1300 |
- ); |
1301 |
- } |
1302 |
- else { |
1303 |
- print $q->Tr( |
1304 |
- esmith::cgi::genCell( |
1305 |
- $q, |
1306 |
- $fm->localise('WORKSTN_NAME') |
1307 |
- ), |
1308 |
- |
1309 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkStation', |
1310 |
- -override => 1, |
1311 |
- -default => $backupwkStation, |
1312 |
- -size => 20)), |
1313 |
- ); |
1314 |
- } |
1315 |
- |
1316 |
- if ( $VFSType eq 'usb' ) { |
1317 |
- print $q->Tr( |
1318 |
- esmith::cgi::genCell( |
1319 |
- $q, |
1320 |
- $fm->localise('SHARED_FOLDER_NAME') |
1321 |
- ), |
1322 |
- |
1323 |
- esmith::cgi::genCell ($q, $q->popup_menu (-name => 'backupwkFolder', |
1324 |
- -values => [ @usbdisks ], |
1325 |
- -default => $backupwkFolder,)), |
1326 |
- ); |
1327 |
- } |
1328 |
- else { |
1329 |
- print $q->Tr( |
1330 |
- esmith::cgi::genCell( |
1331 |
- $q, |
1332 |
- $fm->localise('SHARED_FOLDER_NAME') |
1333 |
- ), |
1334 |
- |
1335 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkFolder', |
1336 |
- -override => 1, |
1337 |
- -default => $backupwkFolder, |
1338 |
- -size => 20)), |
1339 |
- ); |
1340 |
- } |
1341 |
- |
1342 |
- if ( $VFSType eq 'cifs' ) { |
1343 |
- print $q->Tr( |
1344 |
- esmith::cgi::genCell( |
1345 |
- $q, |
1346 |
- $fm->localise('WORKSTN_LOGIN') |
1347 |
- ), |
1348 |
- |
1349 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkLogin', |
1350 |
- -override => 1, |
1351 |
- -default => $backupwkLogin, |
1352 |
- -size => 12)), |
1353 |
- ); |
1354 |
- |
1355 |
- print $q->Tr( |
1356 |
- esmith::cgi::genCell( |
1357 |
- $q, |
1358 |
- $fm->localise('PASSWORD') |
1359 |
- ), |
1360 |
- |
1361 |
- esmith::cgi::genCell ($q, $q->password_field (-name => 'backupwkPassword', |
1362 |
- -override => 1, |
1363 |
- -default => $backupwkPassword, |
1364 |
- -size => 20)), |
1365 |
- ); |
1366 |
- } |
1367 |
- |
1368 |
- print '</table>'; |
1369 |
- |
1370 |
- print $q->table ({border => 0, cellspacing => 1, cellpadding => 4}); |
1371 |
- |
1372 |
- print $q->Tr($q->td({-colspan=>4},$q->h3 ($fm->localise('WORKSTN_BACKUP_SETTINGS')))); |
1373 |
- |
1374 |
- print $q->Tr( |
1375 |
- esmith::cgi::genCell( |
1376 |
- $q, |
1377 |
- $fm->localise('NUMBER_OF_SETS') |
1378 |
- ), |
1379 |
- |
1380 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'setsNumber', |
1381 |
- -override => 1, |
1382 |
- -default => $setsNumber, |
1383 |
- -size => 3)), |
1384 |
- |
1385 |
- esmith::cgi::genCell ($q, $fm->localise('NUMBER_OF_FILES_IN_SET')), |
1386 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'filesinset', |
1387 |
- -override => 1, |
1388 |
- -default => $filesinset, |
1389 |
- -size => 3)) |
1390 |
- ); |
1391 |
- |
1392 |
- print $q->Tr( |
1393 |
- esmith::cgi::genCell( |
1394 |
- $q, |
1395 |
- $fm->localise('WORKSTN_BACKUP_TIME') |
1396 |
- ), |
1397 |
- |
1398 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkHour', |
1399 |
- -override => 1, |
1400 |
- -default => $backupwkHour, |
1401 |
- -size => 2)), |
1402 |
- |
1403 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkMin', |
1404 |
- -override => 1, |
1405 |
- -default => $backupwkMin, |
1406 |
- -size => 2)), |
1407 |
- |
1408 |
- esmith::cgi::genCell ($q, $q->popup_menu (-name => 'backupwkAMPM', |
1409 |
- -values => ['AM', 'PM'], |
1410 |
- -default => $backupwkAMPM))); |
1411 |
- |
1412 |
- print $q->Tr( |
1413 |
- esmith::cgi::genCell( |
1414 |
- $q, |
1415 |
- $fm->localise('WORKSTN_TIMEOUT') |
1416 |
- ), |
1417 |
- |
1418 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'backupwkTimeout', |
1419 |
- -override => 1, |
1420 |
- -default => $backupwkTimeout, |
1421 |
- -size => 2)), |
1422 |
- |
1423 |
- esmith::cgi::genCell( |
1424 |
- $q, |
1425 |
- $fm->localise('INC_ONLY_TIMEOUT') |
1426 |
- ), |
1427 |
- |
1428 |
- esmith::cgi::genCell ( |
1429 |
- $q, |
1430 |
- " <input type=\"checkbox\"" |
1431 |
- . " name=\"incOnlyTimeout\"" |
1432 |
- . " $enabledIncOnlyTimeout" |
1433 |
- . " value=\"on\">" |
1434 |
- ), |
1435 |
- ); |
1436 |
- |
1437 |
- print $q->Tr( |
1438 |
- esmith::cgi::genCell( |
1439 |
- $q, |
1440 |
- $fm->localise('COMPRESSION_LEVEL') |
1441 |
- ), |
1442 |
- |
1443 |
- esmith::cgi::genCell ($q, $q->textfield (-name => 'compression', |
1444 |
- -override => 1, |
1445 |
- -default => $compression, |
1446 |
- -size => 1)), |
1447 |
- |
1448 |
- esmith::cgi::genCell( |
1449 |
- $q, |
1450 |
- $fm->localise('FULL_ONLY_ON') |
1451 |
- ), |
1452 |
- |
1453 |
- esmith::cgi::genCell ( |
1454 |
- $q, |
1455 |
- $q->popup_menu ( |
1456 |
- -name => 'dof', |
1457 |
- -values => [ '7', '0', '1', '2', '3', '4', '5', '6' ], |
1458 |
- -labels => \%dlabels, |
1459 |
- -default => $dof)) |
1460 |
- ); |
1461 |
- |
1462 |
- print "</table>\n"; |
1463 |
- |
1464 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}); |
1465 |
- print $q->Tr($q->th({-class => "sme-layout"}, |
1466 |
- $q->submit( |
1467 |
- -name => 'action', |
1468 |
- -value => $fm->localise('UPDATE_CONF') |
1469 |
- ) |
1470 |
- ) |
1471 |
- ); |
1472 |
- |
1473 |
- print $q->hidden( |
1474 |
- -name => 'state', |
1475 |
- -override => 1, |
1476 |
- -default => 'workstn-configure1' |
1477 |
- ); |
1478 |
- print $q->hidden( |
1479 |
- -name => 'VFSType', |
1480 |
- -override => 1, |
1481 |
- -default => $VFSType |
1482 |
- ); |
1483 |
- print '</table>'; |
1484 |
- |
1485 |
- print $q->endform; |
1486 |
- |
1487 |
- esmith::cgi::genFooter ($q); |
1488 |
- return; |
1489 |
-} |
1490 |
- |
1491 |
-sub updateWorkstnBackupConfig |
1492 |
-{ |
1493 |
- my ($q) = @_; |
1494 |
- |
1495 |
- my $status = $q->param ('workstnbackup'); |
1496 |
- my $inconly = $q->param ('incOnlyTimeout'); |
1497 |
- my $dof = $q->param('dof'); |
1498 |
- my $ampm; |
1499 |
- my $incOnlyTimeout; |
1500 |
- |
1501 |
- esmith::cgi::genHeaderNonCacheable( |
1502 |
- $q, |
1503 |
- undef, $fm->localise('UPDATING_WORKSTN_CONF') |
1504 |
- ); |
1505 |
- |
1506 |
- #-------------------------------------------------- |
1507 |
- # Untaint parameters and check for validity |
1508 |
- #-------------------------------------------------- |
1509 |
- |
1510 |
- my $VFSType = $q->param ('VFSType'); |
1511 |
- |
1512 |
- my $backupwkStation = $q->param ('backupwkStation'); |
1513 |
- if ( $VFSType eq 'usb') { $backupwkStation = 'localhost' } |
1514 |
- if ($backupwkStation =~ /^(.*)$/) { |
1515 |
- $backupwkStation = $1; |
1516 |
- } else { |
1517 |
- $backupwkStation = ""; |
1518 |
- } |
1519 |
- if ( $backupwkStation eq "" ) |
1520 |
- { |
1521 |
- esmith::cgi::genResult( |
1522 |
- $q, $fm->localise('ERR_INVALID_WORKSTN') |
1523 |
- ); |
1524 |
- return; |
1525 |
- } |
1526 |
- |
1527 |
- my $backupwkFolder = $q->param ('backupwkFolder'); |
1528 |
- if ( $VFSType eq 'usb' ) { |
1529 |
- $backupwkFolder = 'media/' . $backupwkFolder; |
1530 |
- } |
1531 |
- if ($backupwkFolder =~ /^(.*)$/) { |
1532 |
- $backupwkFolder = $1; |
1533 |
- $backupwkFolder =~ s/^\//; # remove leading / |
1534 |
- } else { |
1535 |
- $backupwkFolder = ""; |
1536 |
- } |
1537 |
- if ( $backupwkFolder eq "" ) |
1538 |
- { |
1539 |
- esmith::cgi::genResult( |
1540 |
- $q, $fm->localise('ERR_INVALID_FOLDER') |
1541 |
- ); |
1542 |
- return; |
1543 |
- } |
1544 |
- |
1545 |
- my $backupwkLogin = $q->param ('backupwkLogin') || ''; |
1546 |
- if ($backupwkLogin =~ /^(.*)$/) { |
1547 |
- $backupwkLogin = $1; |
1548 |
- } else { |
1549 |
- $backupwkLogin = ""; |
1550 |
- } |
1551 |
- if ( ( $backupwkLogin eq "" ) && ( $VFSType eq 'cifs' ) ) |
1552 |
- { |
1553 |
- esmith::cgi::genResult( |
1554 |
- $q, $fm->localise('ERR_INVALID_LOGIN') |
1555 |
- ); |
1556 |
- return; |
1557 |
- } |
1558 |
- |
1559 |
- my $backupwkPassword = $q->param ('backupwkPassword') || ''; |
1560 |
- if ($backupwkPassword =~ /^(.*)$/) { |
1561 |
- $backupwkPassword = $1; |
1562 |
- } else { |
1563 |
- $backupwkPassword = ""; |
1564 |
- } |
1565 |
- if ( ( $backupwkPassword eq "" ) && ( $VFSType eq 'cifs' ) ) |
1566 |
- { |
1567 |
- esmith::cgi::genResult( |
1568 |
- $q, $fm->localise('ERR_INVALID_PASSWORD') |
1569 |
- ); |
1570 |
- return; |
1571 |
- } |
1572 |
- |
1573 |
- my $setsNumber = $q->param ('setsNumber'); |
1574 |
- unless ( $setsNumber > 0 ) |
1575 |
- { |
1576 |
- esmith::cgi::genResult( |
1577 |
- $q, $fm->localise('ERR_INVALID_SETS_NUMBER') |
1578 |
- ); |
1579 |
- return; |
1580 |
- } |
1581 |
- |
1582 |
- my $filesinset = $q->param ('filesinset'); |
1583 |
- unless ( $filesinset > 0 ) |
1584 |
- { |
1585 |
- esmith::cgi::genResult( |
1586 |
- $q, $fm->localise('ERR_INVALID_FILES_IN_SET_NUMBER') |
1587 |
- ); |
1588 |
- return; |
1589 |
- } |
1590 |
- |
1591 |
- my $timeout = $q->param ('backupwkTimeout'); |
1592 |
- if (( $timeout eq '') || ( $timeout == 0 )) {$timeout = 24 } |
1593 |
- if (( $timeout < 1 ) || ( $timeout > 24 )) |
1594 |
- { |
1595 |
- esmith::cgi::genResult( |
1596 |
- $q, $fm->localise('ERR_INVALID_TIMEOUT') |
1597 |
- ); |
1598 |
- return; |
1599 |
- } |
1600 |
- |
1601 |
- if (defined $inconly && $inconly eq 'on') |
1602 |
- { |
1603 |
- $incOnlyTimeout = 'yes'; |
1604 |
- } |
1605 |
- else |
1606 |
- { |
1607 |
- $incOnlyTimeout = 'no'; |
1608 |
- } |
1609 |
- |
1610 |
- my $compression = $q->param ('compression'); |
1611 |
- if (( $compression < 0 ) || ( $compression > 9 )) |
1612 |
- { |
1613 |
- esmith::cgi::genResult( |
1614 |
- $q, $fm->localise('ERR_INVALID_COMPRESSION') |
1615 |
- ); |
1616 |
- return; |
1617 |
- } |
1618 |
- |
1619 |
- my $rec = $conf->get('backupwk'); |
1620 |
- unless (defined $rec) |
1621 |
- { |
1622 |
- $rec = $conf->new_record('backupwk', {type=>'service'}); |
1623 |
- } |
1624 |
- |
1625 |
- $rec->set_prop('SmbHost', $backupwkStation); |
1626 |
- $rec->set_prop('SmbShare', $backupwkFolder); |
1627 |
- $rec->set_prop('Login', $backupwkLogin); |
1628 |
- $rec->set_prop('Password', $backupwkPassword); |
1629 |
- $rec->set_prop('SetsMax', $setsNumber); |
1630 |
- $rec->set_prop('DaysInSet', $filesinset); |
1631 |
- $rec->set_prop('Timeout', $timeout); |
1632 |
- $rec->set_prop('IncOnlyTimeout', $incOnlyTimeout); |
1633 |
- $rec->set_prop('Compression', $compression); |
1634 |
- $rec->set_prop('FullDay', $dof); |
1635 |
- $rec->set_prop('VFSType', $VFSType); |
1636 |
- |
1637 |
- my $module = $rec->prop('Program'); |
1638 |
- |
1639 |
- # The default workstation backup program is dar. |
1640 |
- |
1641 |
- unless (defined $module) |
1642 |
- { |
1643 |
- $module = 'dar'; |
1644 |
- } |
1645 |
- elsif ($module eq '') |
1646 |
- { |
1647 |
- $module = 'dar'; |
1648 |
- } |
1649 |
- |
1650 |
- $rec->set_prop('Program', $module); |
1651 |
- |
1652 |
- if (defined $status && $status eq 'on') |
1653 |
- { |
1654 |
- |
1655 |
- my $backupwkHour = $q->param ('backupwkHour'); |
1656 |
- if ($backupwkHour =~ /^(.*)$/) { |
1657 |
- $backupwkHour = $1; |
1658 |
- } else { |
1659 |
- $backupwkHour = '12'; |
1660 |
- } |
1661 |
- if (($backupwkHour < 0) || ($backupwkHour > 12)) |
1662 |
- { |
1663 |
- esmith::cgi::genResult( |
1664 |
- $q, $fm->localise('ERR_INVALID_HOUR').$backupwkHour. |
1665 |
- $fm->localise('BETWEEN_0_AND_12') |
1666 |
- ); |
1667 |
- |
1668 |
- return; |
1669 |
- } |
1670 |
- |
1671 |
- my $backupwkMin = $q->param ('backupwkMin'); |
1672 |
- if ($backupwkMin =~ /^(.*)$/) { |
1673 |
- $backupwkMin = $1; |
1674 |
- } else { |
1675 |
- $backupwkMin = '0'; |
1676 |
- } |
1677 |
- if (($backupwkMin < 0) || ($backupwkMin > 59)) |
1678 |
- { |
1679 |
- esmith::cgi::genResult( |
1680 |
- $q, $fm->localise('ERR_INVALID_MINUTE').$backupwkMin. |
1681 |
- $fm->localise('BETWEEN_0_AND_59') |
1682 |
- ); |
1683 |
- |
1684 |
- return; |
1685 |
- } |
1686 |
- |
1687 |
- $backupwkMin = sprintf("%02d", $backupwkMin); |
1688 |
- |
1689 |
- $ampm = $q->param ('backupwkAMPM'); |
1690 |
- if ($ampm =~ /^(.*)$/) { |
1691 |
- $ampm = $1; |
1692 |
- } else { |
1693 |
- $ampm = 'AM'; |
1694 |
- } |
1695 |
- |
1696 |
- # convert to 24 hour time |
1697 |
- |
1698 |
- $backupwkHour = $backupwkHour % 12; |
1699 |
- if ($ampm eq 'PM') |
1700 |
- { |
1701 |
- $backupwkHour = $backupwkHour + 12; |
1702 |
- } |
1703 |
- |
1704 |
- |
1705 |
- # variables passed validity checks, set configuration database values |
1706 |
- my $old = $conf->get('UnsavedChanges')->value; |
1707 |
- |
1708 |
- $rec->set_prop('status', 'enabled'); |
1709 |
- |
1710 |
- $rec->set_prop('BackupTime', "$backupwkHour:$backupwkMin"); |
1711 |
- |
1712 |
- $conf->get('UnsavedChanges')->set_value($old); |
1713 |
- |
1714 |
- system("/sbin/e-smith/signal-event", "conf-backup") == 0 |
1715 |
- or die($fm->localise('ERR_CONF_BACKUP'),"\n"); |
1716 |
- |
1717 |
- esmith::cgi::genResult( |
1718 |
- $q, $fm->localise('SUCCESSFULLY_ENABLED_WORKSTN').$q->br(). |
1719 |
- $fm->localise('WITH_BACKUP_TIME')."$backupwkHour:$backupwkMin"); |
1720 |
- } |
1721 |
- else |
1722 |
- { |
1723 |
- # set service to disabled |
1724 |
- my $old = $conf->get('UnsavedChanges')->value; |
1725 |
- |
1726 |
- $rec->set_prop('status', 'disabled'); |
1727 |
- $conf->get('UnsavedChanges')->set_value($old); |
1728 |
- |
1729 |
- system("/sbin/e-smith/signal-event", "conf-backup") == 0 |
1730 |
- or die($fm->localise('ERR_CONF_BACKUP')."\n"); |
1731 |
- |
1732 |
- esmith::cgi::genResult( |
1733 |
- $q, $fm->localise('SUCCESSFULLY_DISABLED_WORKSTN') |
1734 |
- ); |
1735 |
- } |
1736 |
- |
1737 |
- return; |
1738 |
-} |
1739 |
- |
1740 |
-sub workstnVerify () |
1741 |
-{ |
1742 |
- |
1743 |
- my $rec = $conf->get('backupwk'); |
1744 |
- |
1745 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
1746 |
- $fm->localise('VERIFY_WORKSTN_BACKUP_FILE')); |
1747 |
- |
1748 |
- unless ($rec) |
1749 |
- { |
1750 |
- esmith::cgi::genResult( |
1751 |
- $q, $fm->localise('CONFIGURATION_TO_BE_DONE')); |
1752 |
- return; |
1753 |
- } |
1754 |
- |
1755 |
- my %backupfiles = (); |
1756 |
- my $mntdir = $rec->prop('MountDir') || '/mnt/smb'; |
1757 |
- my $mntbkdir; |
1758 |
- my $mounted; |
1759 |
- my $key; |
1760 |
- my $id = $rec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
1761 |
- my $smbhost = $rec->prop('SmbHost'); |
1762 |
- my $smbshare = $rec->prop('SmbShare'); |
1763 |
- my $VFSType = $rec->prop('VFSType') || 'cifs'; |
1764 |
- my $err; |
1765 |
- |
1766 |
- my $setbackuplist = sub { |
1767 |
- if ( $_ =~ /\.dar/ ) { |
1768 |
- my $dir = $File::Find::dir; |
1769 |
- my $backupref; |
1770 |
- $dir =~ s/$mntbkdir\///; |
1771 |
- $_ =~ s/\..*\.dar//; |
1772 |
- $backupref = $_; |
1773 |
- $_ =~ s/.*-//; |
1774 |
- @{$backupfiles{$_}}[0] = $dir; |
1775 |
- @{$backupfiles{$_}}[1] = $backupref; |
1776 |
- } |
1777 |
- }; |
1778 |
- |
1779 |
- # Mounting backup shared folder |
1780 |
- |
1781 |
- unless (-d $mntdir) |
1782 |
- { |
1783 |
- mkdir -p $mntdir; |
1784 |
- } |
1785 |
- |
1786 |
- my $login = $rec->prop('Login') || 'backup'; |
1787 |
- my $password = $rec->prop('Password') || 'backup'; |
1788 |
- |
1789 |
- if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) |
1790 |
- { |
1791 |
- esmith::cgi::genResult( |
1792 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
1793 |
- ); |
1794 |
- return; |
1795 |
- } |
1796 |
- else {$mounted = 1} |
1797 |
- |
1798 |
- # Test if backup subdirectory for our server |
1799 |
- |
1800 |
- $mntbkdir = $mntdir . '/' . $id; |
1801 |
- unless ( -d $mntbkdir) |
1802 |
- { |
1803 |
- if ($mounted) { |
1804 |
- system("/bin/umount", "$mntdir") == 0 |
1805 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
1806 |
- } |
1807 |
- esmith::cgi::genResult( |
1808 |
- $q, $fm->localise('ERR_NO_HOST_DIR'), $id |
1809 |
- ); |
1810 |
- return; |
1811 |
- } |
1812 |
- |
1813 |
- # Finding existing backups |
1814 |
- |
1815 |
- find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
1816 |
- |
1817 |
- my %blabels = (); |
1818 |
- my @blabels; |
1819 |
- my $backups = 0; |
1820 |
- |
1821 |
- foreach $key (sort keys %backupfiles) { |
1822 |
- my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1]; |
1823 |
- $blabels{$labkey} = $backupfiles{$key}[1] . " (" . $backupfiles{$key}[0] . ")"; |
1824 |
- $backups = push @blabels, $labkey; |
1825 |
- } |
1826 |
- |
1827 |
- if ($mounted) { |
1828 |
- system("/bin/umount", "$mntdir") == 0 |
1829 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
1830 |
- } |
1831 |
- |
1832 |
- # Stops here if no backups |
1833 |
- |
1834 |
- if ( $backups == 0 ) { |
1835 |
- esmith::cgi::genResult( |
1836 |
- $q, $fm->localise('NO_BACKUPS_TO_RESTORE')); |
1837 |
- return; |
1838 |
- } |
1839 |
- |
1840 |
- print $q->p ($fm->localise('VERIFY_WORKSTN_BACKUP_DESC') . ' ' . "$smbhost/$smbshare/$id"); |
1841 |
- print $q->p; |
1842 |
- |
1843 |
- print $q->start_multipart_form( |
1844 |
- -method => 'POST', |
1845 |
- -action => $q->url (-absolute => 1) |
1846 |
- ); |
1847 |
- |
1848 |
- print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
1849 |
- |
1850 |
- esmith::cgi::genWidgetRow( |
1851 |
- $q, |
1852 |
- $fm->localise('SELECT_BACKUP_FILE'), |
1853 |
- $q->popup_menu ( |
1854 |
- -name => 'backupset', |
1855 |
- -values => [ @blabels ], |
1856 |
- -labels => \%blabels |
1857 |
- ) |
1858 |
- ) |
1859 |
- ); |
1860 |
- |
1861 |
- print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
1862 |
- |
1863 |
- esmith::cgi::genWidgetRow( |
1864 |
- $q, |
1865 |
- $fm->localise('CHECK_TO_VERIFY_FULL_RESTORE'), |
1866 |
- $q->checkbox ( |
1867 |
- -name => 'verifyall', |
1868 |
- -checked=>0, |
1869 |
- -label=>'' |
1870 |
- ) |
1871 |
- ), |
1872 |
- $q->Tr( |
1873 |
- esmith::cgi::genTextRow( |
1874 |
- $q, |
1875 |
- $fm->localise('CHECK_INTEGRITY_WARNING') |
1876 |
- ) |
1877 |
- ) |
1878 |
- ),"\n"; |
1879 |
- |
1880 |
- print $q->table ({width => "100%", -class => "sme-noborders"}, |
1881 |
- esmith::cgi::genButtonRow( |
1882 |
- $q, |
1883 |
- $q->submit( |
1884 |
- -name => 'action', |
1885 |
- -value => $fm->localise('VERIFY') |
1886 |
- ) |
1887 |
- ) |
1888 |
- ),"\n"; |
1889 |
- |
1890 |
- print $q->hidden( |
1891 |
- -name => 'state', |
1892 |
- -override => 1, |
1893 |
- -default => 'workstn-verify' |
1894 |
- ); |
1895 |
- |
1896 |
- print $q->endform; |
1897 |
- |
1898 |
- esmith::cgi::genFooter ($q); |
1899 |
-} |
1900 |
- |
1901 |
-sub performWorkstnVerify |
1902 |
-{ |
1903 |
- my ($q) = @_; |
1904 |
- |
1905 |
- my $backupwkrec = $conf->get('backupwk'); |
1906 |
- my $smbhost = $backupwkrec->prop('SmbHost'); |
1907 |
- my $smbshare = $backupwkrec->prop('SmbShare'); |
1908 |
- my $login = $backupwkrec->prop('Login'); |
1909 |
- my $password = $backupwkrec->prop('Password'); |
1910 |
- my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; |
1911 |
- my $mounted; |
1912 |
- my $key; |
1913 |
- my $id = $backupwkrec->prop('Id') || |
1914 |
- $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
1915 |
- my $err; |
1916 |
- my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; |
1917 |
- my $verifyref = $q->param ('backupset'); |
1918 |
- |
1919 |
- # Mounting backup shared folder |
1920 |
- |
1921 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
1922 |
- { |
1923 |
- esmith::cgi::genResult( |
1924 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
1925 |
- ); |
1926 |
- return; |
1927 |
- } |
1928 |
- else {$mounted = 1} |
1929 |
- |
1930 |
- # Test if backup subdirectory for our server |
1931 |
- |
1932 |
- my $mntbkdir = $mntdir . "/$id"; |
1933 |
- unless (-d $mntbkdir) |
1934 |
- { |
1935 |
- if ($mounted) |
1936 |
- { |
1937 |
- system("/bin/umount", "$mntdir") == 0 |
1938 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
1939 |
- } |
1940 |
- esmith::cgi::genResult($q, $fm->localise('ERR_NO_HOST_DIR'), $id); |
1941 |
- return; |
1942 |
- } |
1943 |
- |
1944 |
- my $fullverify = $q->param('verifyall'); |
1945 |
- |
1946 |
- if ( $fullverify eq "on" ) |
1947 |
- { |
1948 |
- # Test all backups needed to full restore |
1949 |
- |
1950 |
- my %backupsetfiles = (); |
1951 |
- my @restorefiles; |
1952 |
- my $set = $verifyref; |
1953 |
- $set =~ s/\/[^\/]*$//; |
1954 |
- my $backupsetlist = sub { |
1955 |
- if ( $_ =~ /\.dar/ ) |
1956 |
- { |
1957 |
- my $backupref = $File::Find::name; |
1958 |
- $backupref =~ s/\.[0-9]+\.dar//; |
1959 |
- $_ =~ s/\..*\.dar//; |
1960 |
- $_ =~ s/.*-//; |
1961 |
- $backupsetfiles{$_} = $backupref; |
1962 |
- } |
1963 |
- }; |
1964 |
- |
1965 |
- # find list of available backups and verify |
1966 |
- # it contains all backups needed for full restore |
1967 |
- |
1968 |
- find { wanted => \&$backupsetlist, untaint => 1 }, $set ; |
1969 |
- |
1970 |
- my $key; |
1971 |
- my $num = 0; |
1972 |
- foreach $key (sort keys %backupsetfiles) |
1973 |
- { |
1974 |
- push @restorefiles, $backupsetfiles{$key}; |
1975 |
- if ( $num == 0 ) |
1976 |
- { |
1977 |
- unless ( $backupsetfiles{$key} =~ /\/full-/ ) |
1978 |
- { |
1979 |
- esmith::cgi::genHeaderNonCacheable( |
1980 |
- $q, |
1981 |
- undef, $fm->localise('VERIFY_WORKSTN_BACKUP_FILE') |
1982 |
- ); |
1983 |
- esmith::cgi::genResult( |
1984 |
- $q, $fm->localise('ERR_NO_FULL_BACKUP') |
1985 |
- ); |
1986 |
- return; |
1987 |
- } |
1988 |
- } |
1989 |
- else |
1990 |
- { |
1991 |
- my $numf = sprintf("%03d", $num); |
1992 |
- unless ( $backupsetfiles{$key} =~ /\/inc-$numf-/ ) |
1993 |
- { |
1994 |
- esmith::cgi::genHeaderNonCacheable( |
1995 |
- $q, |
1996 |
- undef, $fm->localise('VERIFY_WORKSTN_BACKUP_FILE') |
1997 |
- ); |
1998 |
- |
1999 |
- esmith::cgi::genResult( |
2000 |
- $q, $fm->localise('ERR_NO_INC_BACKUP') . " " . $numf |
2001 |
- ); |
2002 |
- return; |
2003 |
- } |
2004 |
- |
2005 |
- } |
2006 |
- $num++; |
2007 |
- last if ( $backupsetfiles{$key} eq $verifyref ); |
2008 |
- } |
2009 |
- |
2010 |
- # and test them |
2011 |
- |
2012 |
- $| = 1; |
2013 |
- |
2014 |
- if (open(RD, "-|")) |
2015 |
- { |
2016 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
2017 |
- $fm->localise('VERIFY_WORKSTN_BACKUP_FILE')); |
2018 |
- |
2019 |
- print $q->p ( |
2020 |
- $q->b ($fm->localise('TESTING_NEEDED_BACKUPS_FOR_RESTORE') ) |
2021 |
- ); |
2022 |
- print '<UL>'; |
2023 |
- |
2024 |
- while (<RD>) |
2025 |
- { |
2026 |
- print "<li>$_</li>\n"; |
2027 |
- } |
2028 |
- |
2029 |
- print '</UL>'; |
2030 |
- my $message; |
2031 |
- if (!close RD) |
2032 |
- { |
2033 |
- print $q->p ($q->b ( $fm->localise('RESTORE_VERIFY_FAILED') )); |
2034 |
- } |
2035 |
- else |
2036 |
- { |
2037 |
- print $q->p ($q->b ( $fm->localise('VERIFY_COMPLETE') )); |
2038 |
- } |
2039 |
- |
2040 |
- esmith::cgi::genFooter ($q); |
2041 |
- } |
2042 |
- else |
2043 |
- { |
2044 |
- select(STDOUT); |
2045 |
- $| = 1; |
2046 |
- |
2047 |
- my $file; |
2048 |
- foreach $file (@restorefiles) |
2049 |
- { |
2050 |
- if ($file =~ /^(.*)$/) |
2051 |
- { |
2052 |
- $file = $1; |
2053 |
- } |
2054 |
- else |
2055 |
- { |
2056 |
- if ($mounted) |
2057 |
- { |
2058 |
- system("/bin/umount", "$mntdir") == 0 |
2059 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2060 |
- } |
2061 |
- die('Unsecure data : ' . $file); |
2062 |
- } |
2063 |
- print $q->p($fm->localise('TESTED_BACKUP') . " " . $file); |
2064 |
- system ("/usr/bin/dar", "-Q", "--test", "$file", "--noconf"); |
2065 |
- } |
2066 |
- |
2067 |
- if ($mounted) |
2068 |
- { |
2069 |
- system("/bin/umount", "$mntdir") == 0 |
2070 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2071 |
- } |
2072 |
- |
2073 |
- exit(0); |
2074 |
- } |
2075 |
- return; |
2076 |
- |
2077 |
- } |
2078 |
- else |
2079 |
- { |
2080 |
- # verify selected backup only |
2081 |
- # and display files saved in the backup |
2082 |
- |
2083 |
- my $backupkey = $verifyref; |
2084 |
- if ($backupkey =~ /^(.*)$/) |
2085 |
- { |
2086 |
- $backupkey = $1; |
2087 |
- } |
2088 |
- else |
2089 |
- { |
2090 |
- if ($mounted) |
2091 |
- { |
2092 |
- system("/bin/umount", "$mntdir") == 0 |
2093 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2094 |
- } |
2095 |
- die('Unsecure data : ' . $backupkey); |
2096 |
- } |
2097 |
- |
2098 |
- if (open(RD, "-|")) |
2099 |
- { |
2100 |
- esmith::cgi::genHeaderNonCacheable ($q, |
2101 |
- undef, $fm->localise('VERIFY_WORKSTN_BACKUP_FILE')); |
2102 |
- print $q->p($fm->localise('FILES_IN_BACKUP')); |
2103 |
- |
2104 |
- print '<UL>'; |
2105 |
- |
2106 |
- my $complete = 0; |
2107 |
- while (<RD>) |
2108 |
- { |
2109 |
- $complete++ if /etc\/smbpasswd$/; |
2110 |
- $complete++ if /etc\/samba\/smbpasswd$/; # >6.0 base |
2111 |
- print "<li>$_</li>\n"; |
2112 |
- } |
2113 |
- |
2114 |
- print '</UL>'; |
2115 |
- my $status = close RD ? |
2116 |
- ($complete ? |
2117 |
- $fm->localise('VERIFY_COMPLETE') : |
2118 |
- $fm->localise('BACKUP_FILE_INCOMPLETE')) |
2119 |
- : ($fm->localise('ERROR_READING_FILE').' : '.$backupkey); |
2120 |
- print $q->p ($q->b ($status)); |
2121 |
- |
2122 |
- esmith::cgi::genFooter ($q); |
2123 |
- |
2124 |
- } |
2125 |
- else |
2126 |
- { |
2127 |
- select(STDOUT); |
2128 |
- $| = 1; |
2129 |
- |
2130 |
- system ("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0 |
2131 |
- or die ($fm->localise('ERR_EXTRACT')." : ".$!); |
2132 |
- |
2133 |
- if ($mounted) { |
2134 |
- system("/bin/umount", "$mntdir") == 0 |
2135 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2136 |
- } |
2137 |
- exit(0); |
2138 |
- } |
2139 |
- } |
2140 |
- |
2141 |
- return; |
2142 |
-} |
2143 |
- |
2144 |
-sub workstnRestore () |
2145 |
-{ |
2146 |
- |
2147 |
- my $rec = $conf->get('backupwk'); |
2148 |
- |
2149 |
- esmith::cgi::genHeaderNonCacheable( |
2150 |
- $q, undef, $fm->localise('RESTORE_CONF_FROM_WORKSTN')); |
2151 |
- |
2152 |
- unless ($rec) |
2153 |
- { |
2154 |
- esmith::cgi::genResult( |
2155 |
- $q, $fm->localise('CONFIGURATION_TO_BE_DONE')); |
2156 |
- return; |
2157 |
- } |
2158 |
- |
2159 |
- my $mntdir = $rec->prop('MountDir') || '/mnt/smb'; |
2160 |
- my $mntbkdir; |
2161 |
- my $mounted; |
2162 |
- my %backupfiles = (); |
2163 |
- my $key; |
2164 |
- my $id = $rec->prop('Id') || |
2165 |
- $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
2166 |
- my $VFSType = $rec->prop('VFSType') || 'cifs'; |
2167 |
- my $smbhost = $rec->prop('SmbHost'); |
2168 |
- my $smbshare = $rec->prop('SmbShare'); |
2169 |
- my $err; |
2170 |
- |
2171 |
- my $setbackupflist = sub { |
2172 |
- if ( $_ =~ /\.dar/ ) |
2173 |
- { |
2174 |
- my $dir = $File::Find::dir; |
2175 |
- my $backupref; |
2176 |
- $dir =~ s/$mntbkdir\///; |
2177 |
- $_ =~ s/\..*\.dar//; |
2178 |
- $backupref = $_; |
2179 |
- $_ =~ s/.*-//; |
2180 |
- @{$backupfiles{$_}}[0] = $dir; |
2181 |
- @{$backupfiles{$_}}[1] = $backupref; |
2182 |
- } |
2183 |
- }; |
2184 |
- |
2185 |
- # Mounting backup shared folder |
2186 |
- unless (-d $mntdir) |
2187 |
- { |
2188 |
- mkdir -p $mntdir; |
2189 |
- } |
2190 |
- |
2191 |
- my $login = $rec->prop('Login') || 'backup'; |
2192 |
- my $password = $rec->prop('Password') || 'backup'; |
2193 |
- |
2194 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
2195 |
- { |
2196 |
- esmith::cgi::genResult($q, |
2197 |
- $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err); |
2198 |
- return; |
2199 |
- } |
2200 |
- else {$mounted = 1} |
2201 |
- |
2202 |
- # Test if backup subdirectory for our server |
2203 |
- |
2204 |
- $mntbkdir = $mntdir . "/$id"; |
2205 |
- unless ( -d $mntbkdir) |
2206 |
- { |
2207 |
- if ($mounted) |
2208 |
- { |
2209 |
- system("/bin/umount", "$mntdir") == 0 |
2210 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2211 |
- } |
2212 |
- esmith::cgi::genResult($q, $fm->localise('ERR_NO_HOST_DIR'), $id); |
2213 |
- return; |
2214 |
- } |
2215 |
- |
2216 |
- # Finding existing backups |
2217 |
- |
2218 |
- find { wanted => \&$setbackupflist, untaint => 1 }, $mntbkdir ; |
2219 |
- |
2220 |
- my %blabels = (); |
2221 |
- my @blabels; |
2222 |
- my $backups = 0; |
2223 |
- |
2224 |
- foreach $key (sort keys %backupfiles) |
2225 |
- { |
2226 |
- my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1]; |
2227 |
- $blabels{$labkey} = $backupfiles{$key}[1] . ' (' . $backupfiles{$key}[0] . ')'; |
2228 |
- $backups = push @blabels, $labkey; |
2229 |
- } |
2230 |
- |
2231 |
- if ($mounted) |
2232 |
- { |
2233 |
- system("/bin/umount", "$mntdir") == 0 |
2234 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2235 |
- } |
2236 |
- |
2237 |
- if ( $backups == 0 ) |
2238 |
- { |
2239 |
- esmith::cgi::genResult( |
2240 |
- $q, $fm->localise('NO_BACKUPS_TO_RESTORE')); |
2241 |
- return; |
2242 |
- } |
2243 |
- |
2244 |
- print $q->p ($fm->localise('RESTORE_CONF_FROM_WORKSTN_DESC') . ' ' . "$smbhost/$smbshare/$id"); |
2245 |
- print $q->p; |
2246 |
- |
2247 |
- print $q->start_multipart_form( |
2248 |
- -method => 'POST', |
2249 |
- -action => $q->url (-absolute => 1) |
2250 |
- ); |
2251 |
- |
2252 |
- print $q->table ( {border => 0, cellspacing => 0, cellpadding => 4}, |
2253 |
- |
2254 |
- esmith::cgi::genWidgetRow( |
2255 |
- $q, |
2256 |
- $fm->localise('SELECT_BACKUP_FILE'), |
2257 |
- $q->popup_menu ( |
2258 |
- -name => 'backuptorestore', |
2259 |
- -values => [ @blabels ], |
2260 |
- -labels => \%blabels |
2261 |
- ) |
2262 |
- ) |
2263 |
- ); |
2264 |
- |
2265 |
- print $q->table ( {width => "100%", -class => "sme-noborders"}, |
2266 |
- esmith::cgi::genButtonRow( |
2267 |
- $q, |
2268 |
- $q->submit( |
2269 |
- -name => 'action', |
2270 |
- -value => $fm->localise('RESTORE_FROM_WORKSTN') |
2271 |
- ) |
2272 |
- ) |
2273 |
- ); |
2274 |
- |
2275 |
- print $q->hidden( |
2276 |
- -name => 'state', |
2277 |
- -override => 1, |
2278 |
- -default => 'workstn-restore' |
2279 |
- ); |
2280 |
- |
2281 |
- print $q->endform; |
2282 |
- |
2283 |
- esmith::cgi::genFooter ($q); |
2284 |
-} |
2285 |
- |
2286 |
-sub performWorkstnRestore |
2287 |
-{ |
2288 |
- my ($q) = @_; |
2289 |
- my $restoreref = $q->param ('backuptorestore'); |
2290 |
- my $set = $restoreref; |
2291 |
- $set =~ s/\/[^\/]*$//; |
2292 |
- my %backupsetfiles = (); |
2293 |
- my @restorefiles; |
2294 |
- |
2295 |
- my $backupsetlist = sub { |
2296 |
- if ( $_ =~ /\.dar/ ) |
2297 |
- { |
2298 |
- my $backupref = $File::Find::name; |
2299 |
- $backupref =~ s/\.[0-9]+\.dar//; |
2300 |
- $_ =~ s/\..*\.dar//; |
2301 |
- $_ =~ s/.*-//; |
2302 |
- $backupsetfiles{$_} = $backupref; |
2303 |
- } |
2304 |
- }; |
2305 |
- |
2306 |
- |
2307 |
- my $lock_file = "/var/lock/subsys/e-smith-restore"; |
2308 |
- my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file); |
2309 |
- |
2310 |
- unless ($file_handle) |
2311 |
- { |
2312 |
- esmith::cgi::genHeaderNonCacheable( |
2313 |
- $q, |
2314 |
- undef, $fm->localise('RESTORE_CANNOT_PROCEED') |
2315 |
- ); |
2316 |
- |
2317 |
- print $q->p ( |
2318 |
- $q->b ($fm->localise('ANOTHER_RESTORE_IN_PROGRESS') |
2319 |
- ) |
2320 |
- ); |
2321 |
- |
2322 |
- esmith::cgi::genFooter ($q); |
2323 |
- return; |
2324 |
- } |
2325 |
- |
2326 |
- # mounting backup shared folder |
2327 |
- |
2328 |
- my $backupwkrec = $conf->get('backupwk'); |
2329 |
- my $login = $backupwkrec->prop('Login'); |
2330 |
- my $password = $backupwkrec->prop('Password'); |
2331 |
- my $id = $backupwkrec->prop('Id') |
2332 |
- || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
2333 |
- my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; |
2334 |
- my $mounted; |
2335 |
- my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; |
2336 |
- my $smbhost = $backupwkrec->prop('SmbHost'); |
2337 |
- my $smbshare = $backupwkrec->prop('SmbShare'); |
2338 |
- my $err; |
2339 |
- |
2340 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
2341 |
- { |
2342 |
- esmith::cgi::genHeaderNonCacheable( |
2343 |
- $q, |
2344 |
- undef, $fm->localise('RESTORE_CANNOT_PROCEED') |
2345 |
- ); |
2346 |
- esmith::cgi::genResult( |
2347 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
2348 |
- ); |
2349 |
- return; |
2350 |
- } |
2351 |
- else {$mounted = 1} |
2352 |
- |
2353 |
- # Test if backup subdirectory for our server |
2354 |
- |
2355 |
- my $mntbkdir = $mntdir . "/$id"; |
2356 |
- unless ( -d $mntbkdir) |
2357 |
- { |
2358 |
- if ($mounted) |
2359 |
- { |
2360 |
- system("/bin/umount", "$mntdir") == 0 |
2361 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2362 |
- } |
2363 |
- esmith::cgi::genHeaderNonCacheable( |
2364 |
- $q, |
2365 |
- undef, $fm->localise('RESTORE_CANNOT_PROCEED') |
2366 |
- ); |
2367 |
- esmith::cgi::genResult( |
2368 |
- $q, $fm->localise('ERR_NO_HOST_DIR') . $id |
2369 |
- ); |
2370 |
- return; |
2371 |
- } |
2372 |
- |
2373 |
- # finding list of available backups |
2374 |
- # and verifying all needed backup files are available |
2375 |
- |
2376 |
- find { wanted => \&$backupsetlist, untaint => 1 }, $set ; |
2377 |
- |
2378 |
- my $key; |
2379 |
- my $num = 0; |
2380 |
- foreach $key (sort keys %backupsetfiles) |
2381 |
- { |
2382 |
- push @restorefiles, $backupsetfiles{$key}; |
2383 |
- if ( $num == 0 ) |
2384 |
- { |
2385 |
- unless ( $backupsetfiles{$key} =~ /\/full-/ ) |
2386 |
- { |
2387 |
- esmith::cgi::genHeaderNonCacheable( |
2388 |
- $q, |
2389 |
- undef, $fm->localise('RESTORE_CANNOT_PROCEED') |
2390 |
- ); |
2391 |
- esmith::cgi::genResult( |
2392 |
- $q, $fm->localise('ERR_NO_FULL_BACKUP') |
2393 |
- ); |
2394 |
- return; |
2395 |
- } |
2396 |
- } |
2397 |
- else |
2398 |
- { |
2399 |
- my $numf = sprintf("%03d", $num); |
2400 |
- unless ( $backupsetfiles{$key} =~ /\/inc-$numf-/ ) |
2401 |
- { |
2402 |
- esmith::cgi::genHeaderNonCacheable( |
2403 |
- $q, |
2404 |
- undef, $fm->localise('RESTORE_CANNOT_PROCEED') |
2405 |
- ); |
2406 |
- |
2407 |
- esmith::cgi::genResult( |
2408 |
- $q, $fm->localise('ERR_NO_INC_BACKUP') . $numf |
2409 |
- ); |
2410 |
- return; |
2411 |
- } |
2412 |
- |
2413 |
- } |
2414 |
- $num++; |
2415 |
- last if ( $backupsetfiles{$key} eq $restoreref ); |
2416 |
- } |
2417 |
- |
2418 |
- # backup is online, restoring now |
2419 |
- |
2420 |
- my $rec = $restore->get('restore'); |
2421 |
- $rec->set_prop('state','running'); |
2422 |
- $rec->set_prop('start', time); |
2423 |
- $conf->get('bootstrap-console')->set_prop('Run', 'yes'); |
2424 |
- |
2425 |
- unless (system("/sbin/e-smith/signal-event", "pre-restore") == 0) |
2426 |
- { |
2427 |
- esmith::cgi::genHeaderNonCacheable( |
2428 |
- $fm->{cgi}, |
2429 |
- undef, $fm->localise('OPERATION_STATUS_REPORT')); |
2430 |
- esmith::cgi::genResult( |
2431 |
- $fm->{cgi}, $fm->localise('ERR_PRE_RESTORE')); |
2432 |
- return; |
2433 |
- } |
2434 |
- |
2435 |
- $| = 1; |
2436 |
- |
2437 |
- if (open(RD, "-|")) |
2438 |
- { |
2439 |
- |
2440 |
- #----------------------------------------------------- |
2441 |
- # restore system from uploaded workstation backup file |
2442 |
- #----------------------------------------------------- |
2443 |
- |
2444 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
2445 |
- $fm->localise('RESTORE_IN_PROGRESS')); |
2446 |
- |
2447 |
- print $q->p ( |
2448 |
- $q->b ($fm->localise('RESTORE_IN_PROGRESS_DESC') |
2449 |
- ) |
2450 |
- ); |
2451 |
- |
2452 |
- print $q->p($fm->localise('FILES_HAVE_BEEN_RESTORED')); |
2453 |
- |
2454 |
- print '<UL>'; |
2455 |
- my $complete = 0; |
2456 |
- while (<RD>) |
2457 |
- { |
2458 |
- $complete++ if /etc\/smbpasswd$/; |
2459 |
- $complete++ if /etc\/samba\/smbpassword$/; |
2460 |
- print "<li>$_</li>\n"; |
2461 |
- } |
2462 |
- |
2463 |
- print '</UL>'; |
2464 |
- my $message; |
2465 |
- if (!close RD) |
2466 |
- { |
2467 |
- $message = $fm->localise('RESTORE_FAILED_MSG'); |
2468 |
- } |
2469 |
- else |
2470 |
- { |
2471 |
- #----------------------------------------------------- |
2472 |
- # if restore completed, regenerate configuration files |
2473 |
- #----------------------------------------------------- |
2474 |
- if ($complete) |
2475 |
- { |
2476 |
- |
2477 |
- $message = $fm->localise('RESTORE_COMPLETE'); |
2478 |
- system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0 |
2479 |
- or warn ($fm->localise('ERR_RESTORING_GID')."\n"); |
2480 |
- system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0 |
2481 |
- or warn ($fm->localise('ERR_RESTORING_INITIAL_GRP')."\n"); |
2482 |
- system("/sbin/e-smith/signal-event", "post-upgrade") == 0 |
2483 |
- or die ($fm->localise('ERROR_UPDATING_CONFIGURATION')."\n"); |
2484 |
- } |
2485 |
- else |
2486 |
- { |
2487 |
- $message = $fm->localise('RESTORE_FAILED'); |
2488 |
- } |
2489 |
- } |
2490 |
- |
2491 |
- $rec->set_prop('state', 'complete'); |
2492 |
- $rec->set_prop('finish', time); |
2493 |
- |
2494 |
- &esmith::lockfile::UnlockFile($file_handle); |
2495 |
- |
2496 |
- print $q->p ($q->b ($message)); |
2497 |
- |
2498 |
- print $q->startform( |
2499 |
- -method => 'POST', |
2500 |
- -action => $q->url (-absolute => 1) |
2501 |
- ); |
2502 |
- print $q->p($q->b ($fm->localise('YOU_MUST_REBOOT'))),"\n"; |
2503 |
- print $q->start_table ({width => "100%", -class => "sme-noborders"}),"\n"; |
2504 |
- print esmith::cgi::genButtonRow( |
2505 |
- $q, |
2506 |
- $q->submit (-name => 'action', -value => |
2507 |
- $fm->localise('REBOOT')) |
2508 |
- ); |
2509 |
- # Put in a hidden widget to store the reboot value. |
2510 |
- print $q->hidden( |
2511 |
- -name => 'function', |
2512 |
- -value => 'reboot' |
2513 |
- ),"\n"; |
2514 |
- print $q->hidden ( |
2515 |
- -name => 'state', |
2516 |
- -override => 1, |
2517 |
- -default => 'perform' |
2518 |
- ),"\n"; |
2519 |
- print $q->end_table,"\n"; |
2520 |
- print $q->endform; |
2521 |
- |
2522 |
- esmith::cgi::genFooter ($q); |
2523 |
- } |
2524 |
- else |
2525 |
- { |
2526 |
- select(STDOUT); |
2527 |
- $| = 1; |
2528 |
- |
2529 |
- my $file; |
2530 |
- foreach $file (@restorefiles) |
2531 |
- { |
2532 |
- if ($file =~ /^(.*)$/) |
2533 |
- { |
2534 |
- $file = $1; |
2535 |
- } |
2536 |
- else |
2537 |
- { |
2538 |
- if ($mounted) |
2539 |
- { |
2540 |
- system("/bin/umount", "$mntdir") == 0 |
2541 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2542 |
- } |
2543 |
- die('Unsecure data : ' . $file); |
2544 |
- } |
2545 |
- system ("/usr/bin/dar", "-Q", "-x", "$file", "-v", "-N", "-R", "/", "-wa"); |
2546 |
- } |
2547 |
- |
2548 |
- if ($mounted) |
2549 |
- { |
2550 |
- system("/bin/umount", "$mntdir") == 0 |
2551 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2552 |
- } |
2553 |
- |
2554 |
- exit(0); |
2555 |
- } |
2556 |
- return; |
2557 |
-} |
2558 |
- |
2559 |
-sub workstnSelRestore() |
2560 |
-{ |
2561 |
- my $rec = $conf->get('backupwk'); |
2562 |
- |
2563 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
2564 |
- $fm->localise('WORKSTN_SELECTIVE_RESTORE')); |
2565 |
- |
2566 |
- unless ($rec) |
2567 |
- { |
2568 |
- esmith::cgi::genResult( |
2569 |
- $q, $fm->localise('CONFIGURATION_TO_BE_DONE')); |
2570 |
- return; |
2571 |
- } |
2572 |
- |
2573 |
- my %backupfiles = (); |
2574 |
- my $mntdir = $rec->prop('MountDir') || '/mnt/smb'; |
2575 |
- my $mntbkdir; |
2576 |
- my $mounted; |
2577 |
- my $key; |
2578 |
- my $id = $rec->prop('Id') || |
2579 |
- $conf->get('SystemName')->value . '.' . $conf->get('DomainName')->value; |
2580 |
- my %blabels = (); |
2581 |
- my @blabels; |
2582 |
- my $backups = 0; |
2583 |
- my $filterexp; |
2584 |
- my $VFSType = $rec->prop('VFSType') || 'cifs'; |
2585 |
- my $smbhost = $rec->prop('SmbHost'); |
2586 |
- my $smbshare = $rec->prop('SmbShare'); |
2587 |
- my $err; |
2588 |
- |
2589 |
- my $setbackuplist = sub { |
2590 |
- if ( $_ =~ /\.dar/ ) |
2591 |
- { |
2592 |
- my $dir = $File::Find::dir; |
2593 |
- my $backupref; |
2594 |
- $dir =~ s/$mntbkdir\///; |
2595 |
- $_ =~ s/\..*\.dar//; |
2596 |
- $backupref = $_; |
2597 |
- $_ =~ s/.*-//; |
2598 |
- @{$backupfiles{$_}}[0] = $dir; |
2599 |
- @{$backupfiles{$_}}[1] = $backupref; |
2600 |
- } |
2601 |
- }; |
2602 |
- |
2603 |
- # Mounting backups smb shared folder |
2604 |
- |
2605 |
- unless (-d $mntdir) |
2606 |
- { |
2607 |
- mkdir -p $mntdir; |
2608 |
- } |
2609 |
- |
2610 |
- my $login = $rec->prop('Login') || 'backup'; |
2611 |
- my $password = $rec->prop('Password') || 'backup'; |
2612 |
- |
2613 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
2614 |
- { |
2615 |
- esmith::cgi::genResult( |
2616 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
2617 |
- ); |
2618 |
- return; |
2619 |
- } |
2620 |
- else {$mounted = 1} |
2621 |
- |
2622 |
- # Test if backup subdirectory for our server |
2623 |
- |
2624 |
- $mntbkdir = $mntdir . '/' . $id; |
2625 |
- unless ( -d $mntbkdir) |
2626 |
- { |
2627 |
- if ($mounted) |
2628 |
- { |
2629 |
- system("/bin/umount", "$mntdir") == 0 |
2630 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2631 |
- } |
2632 |
- esmith::cgi::genResult( |
2633 |
- $q, $fm->localise('ERR_NO_HOST_DIR'), $id |
2634 |
- ); |
2635 |
- return; |
2636 |
- } |
2637 |
- |
2638 |
- my $catalog = "$mntbkdir/dar-catalog"; |
2639 |
- unless ( -e $catalog) |
2640 |
- { |
2641 |
- system("/usr/bin/dar_manager", "-C", "$catalog") == 0 |
2642 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
2643 |
- } |
2644 |
- |
2645 |
- # find available backups for the server |
2646 |
- |
2647 |
- find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
2648 |
- |
2649 |
- # find backups in current catalog |
2650 |
- |
2651 |
- my $i = 0; |
2652 |
- my @bknum; |
2653 |
- my @setd; |
2654 |
- my @bkname; |
2655 |
- open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |"); |
2656 |
- while (<DAR_LIST>) |
2657 |
- { |
2658 |
- next unless ($_ =~ /set/); |
2659 |
- chomp; |
2660 |
- ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); |
2661 |
- $i++; |
2662 |
- } |
2663 |
- close (DAR_LIST); |
2664 |
- |
2665 |
- # delete from catalog old removed backups |
2666 |
- |
2667 |
- my $j = $i; |
2668 |
- while ($j) |
2669 |
- { |
2670 |
- unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") |
2671 |
- { |
2672 |
- my $del = $bknum[$j-1]; |
2673 |
- if ($del =~ /^(.*)$/) |
2674 |
- { |
2675 |
- $del = $1; |
2676 |
- } |
2677 |
- system("/usr/bin/dar_manager", "-B", "$catalog", "-D", "$del") == 0 |
2678 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
2679 |
- } |
2680 |
- $j--; |
2681 |
- } |
2682 |
- |
2683 |
- # add to catalog new backups |
2684 |
- |
2685 |
- foreach $key (sort keys %backupfiles) |
2686 |
- { |
2687 |
- my $exists = 0; |
2688 |
- my $rf; |
2689 |
- foreach $rf (@bkname) |
2690 |
- { |
2691 |
- $exists = 1 if ($rf eq $backupfiles{$key}[1]); |
2692 |
- last if $exists; |
2693 |
- } |
2694 |
- do |
2695 |
- { |
2696 |
- my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; |
2697 |
- if ($add =~ /^(.*)$/) |
2698 |
- { |
2699 |
- $add = $1; |
2700 |
- } |
2701 |
- system("/usr/bin/dar_manager", "-B", "$catalog", "-A", "$add") == 0 |
2702 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
2703 |
- } unless $exists; |
2704 |
- } |
2705 |
- |
2706 |
- # update backups list from current catalog |
2707 |
- |
2708 |
- open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |") ; |
2709 |
- |
2710 |
- $i = 0; |
2711 |
- while (<DAR_LIST>) |
2712 |
- { |
2713 |
- next unless m/set/; |
2714 |
- chomp; |
2715 |
- ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); |
2716 |
- $i++; |
2717 |
- } |
2718 |
- close (DAR_LIST); |
2719 |
- |
2720 |
- # set drop down list of backups |
2721 |
- |
2722 |
- push @blabels, "0"; |
2723 |
- $blabels{"0"} = $fm->localise('ALL_BACKUPS'); |
2724 |
- $j = 0; |
2725 |
- while ($j < $i) |
2726 |
- { |
2727 |
- push @blabels, $bknum[$j]; |
2728 |
- $blabels{$bknum[$j]} = $bkname[$j]; |
2729 |
- $j++ |
2730 |
- } |
2731 |
- |
2732 |
- print $q->p ($fm->localise('WORKSTN_SEL_REST_DESC') . " $smbhost/$smbshare/$id"); |
2733 |
- |
2734 |
- print $q->h2 ($fm->localise('BACKUP_CHOICE')); |
2735 |
- |
2736 |
- print $q->start_multipart_form( |
2737 |
- -method => 'POST', |
2738 |
- -action => $q->url (-absolute => 1) |
2739 |
- ); |
2740 |
- |
2741 |
- |
2742 |
- print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
2743 |
- |
2744 |
- esmith::cgi::genWidgetRow( |
2745 |
- $q, |
2746 |
- $q->b($fm->localise('SELECT_BACKUP_FILE')), |
2747 |
- $q->popup_menu ( |
2748 |
- -name => 'backupset', |
2749 |
- -values => [ @blabels ], |
2750 |
- -labels => \%blabels) |
2751 |
- ), |
2752 |
- |
2753 |
- esmith::cgi::genNameValueRow( |
2754 |
- $q, |
2755 |
- $fm->localise('FILTER_EXPRESSION'), |
2756 |
- 'filterexp', |
2757 |
- $filterexp |
2758 |
- ) |
2759 |
- ); |
2760 |
- |
2761 |
- |
2762 |
- print $q->table ({width => "100%", -class => "sme-noborders"}, |
2763 |
- esmith::cgi::genButtonRow( |
2764 |
- $q, |
2765 |
- $q->submit( |
2766 |
- -name => 'action', |
2767 |
- -value => $fm->localise('PERFORM') |
2768 |
- ) |
2769 |
- ) |
2770 |
- ),"\n"; |
2771 |
- |
2772 |
- print $q->hidden( |
2773 |
- -name => 'state', |
2774 |
- -override => 1, |
2775 |
- -default => 'workstn-sel-restore' |
2776 |
- ); |
2777 |
- |
2778 |
- print $q->endform; |
2779 |
- |
2780 |
- |
2781 |
- esmith::cgi::genFooter ($q); |
2782 |
- |
2783 |
- if ($mounted) |
2784 |
- { |
2785 |
- system("/bin/umount", "$mntdir") == 0 |
2786 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2787 |
- } |
2788 |
-} |
2789 |
- |
2790 |
-sub performWorkstnSelRestore |
2791 |
-{ |
2792 |
- my ($q) = @_; |
2793 |
- |
2794 |
- my $rgfilter; |
2795 |
- my $filterexp = $q->param ('filterexp'); |
2796 |
- if ($filterexp =~ /^(.*)$/) |
2797 |
- { |
2798 |
- $filterexp = $1; |
2799 |
- $rgfilter = qr/$filterexp/; |
2800 |
- } |
2801 |
- else |
2802 |
- { |
2803 |
- $filterexp = ""; |
2804 |
- } |
2805 |
- my $seldatebf; |
2806 |
- |
2807 |
- esmith::cgi::genHeaderNonCacheable ($q, |
2808 |
- undef, $fm->localise('WORKSTN_SELECTIVE_RESTORE')); |
2809 |
- |
2810 |
- my $backupwkrec = $conf->get('backupwk'); |
2811 |
- my $smbhost = $backupwkrec->prop('SmbHost'); |
2812 |
- my $smbshare = $backupwkrec->prop('SmbShare'); |
2813 |
- my $login = $backupwkrec->prop('Login'); |
2814 |
- my $password = $backupwkrec->prop('Password'); |
2815 |
- my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; |
2816 |
- my $mntbkdir; |
2817 |
- my $mounted; |
2818 |
- my $key; |
2819 |
- my $id = $backupwkrec->prop('Id') || |
2820 |
- $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
2821 |
- my @flabels; |
2822 |
- my %flabels = (); |
2823 |
- my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; |
2824 |
- my $err; |
2825 |
- |
2826 |
- my $backupkey = $q->param ('backupset'); |
2827 |
- if ($backupkey =~ /^(.*)$/) |
2828 |
- { |
2829 |
- $backupkey = $1; |
2830 |
- } |
2831 |
- else |
2832 |
- { |
2833 |
- die('Unsecure data : ' . $backupkey); |
2834 |
- } |
2835 |
- |
2836 |
- # Mounting backup shared folder |
2837 |
- |
2838 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
2839 |
- { |
2840 |
- esmith::cgi::genResult( |
2841 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
2842 |
- ); |
2843 |
- return; |
2844 |
- } |
2845 |
- else {$mounted = 1} |
2846 |
- |
2847 |
- # Test if backup subdirectory for our server |
2848 |
- |
2849 |
- $mntbkdir = $mntdir . "/$id"; |
2850 |
- unless (-d $mntbkdir) |
2851 |
- { |
2852 |
- if ($mounted) |
2853 |
- { |
2854 |
- system("/bin/umount", "$mntdir") == 0 |
2855 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2856 |
- } |
2857 |
- esmith::cgi::genResult( |
2858 |
- $q, $fm->localise('ERR_NO_HOST_DIR'), $id |
2859 |
- ); |
2860 |
- return; |
2861 |
- } |
2862 |
- |
2863 |
- # Read wanted file list from selected backup |
2864 |
- |
2865 |
- if (open(RD, "-|")) |
2866 |
- { |
2867 |
- my $regex = qr/\[.*\] */; |
2868 |
- while (<RD>) |
2869 |
- { |
2870 |
- $_ =~ s/$regex//; |
2871 |
- if ($filterexp) {next unless m/$rgfilter/}; |
2872 |
- push @flabels, $_; |
2873 |
- } |
2874 |
- |
2875 |
- my $status = close RD ? |
2876 |
- $fm->localise('READ_COMPLETE') |
2877 |
- : ($fm->localise('ERROR_READING_FILE').' : '.$backupkey); |
2878 |
- print $q->p ($status); |
2879 |
- |
2880 |
- } |
2881 |
- else |
2882 |
- { |
2883 |
- select(STDOUT); |
2884 |
- $| = 1; |
2885 |
- |
2886 |
- system ("/usr/bin/dar_manager", "-B", "$mntbkdir/dar-catalog", "-u", "$backupkey") == 0 |
2887 |
- or die ($fm->localise('ERR_EXTRACT')." : ".$!); |
2888 |
- |
2889 |
- if ($mounted) |
2890 |
- { |
2891 |
- system("/bin/umount", "$mntdir") == 0 |
2892 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
2893 |
- } |
2894 |
- exit(0); |
2895 |
- } |
2896 |
- |
2897 |
- print $q->start_multipart_form( |
2898 |
- -method => 'POST', |
2899 |
- -action => $q->url (-absolute => 1) |
2900 |
- ); |
2901 |
- |
2902 |
- print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
2903 |
- |
2904 |
- esmith::cgi::genWidgetRow( |
2905 |
- $q, |
2906 |
- $q->b($fm->localise('SELECT_FILES_TO_RESTORE')), |
2907 |
- $q->scrolling_list ( |
2908 |
- -name => 'restorefiles', |
2909 |
- -values => [ @flabels ], |
2910 |
- -size => 15, |
2911 |
- -multiple => 'true') |
2912 |
- ), |
2913 |
- |
2914 |
- esmith::cgi::genNameValueRow( |
2915 |
- $q, |
2916 |
- $fm->localise('SELECT_DATE_BEFORE'), |
2917 |
- 'seldatebefore', |
2918 |
- $seldatebf |
2919 |
- ) |
2920 |
- ); |
2921 |
- |
2922 |
- print $q->table ({width => "100%", -class => "sme-noborders"}, |
2923 |
- esmith::cgi::genButtonRow( |
2924 |
- $q, |
2925 |
- $q->submit( |
2926 |
- -name => 'action', |
2927 |
- -value => $fm->localise('PERFORM') |
2928 |
- ) |
2929 |
- ) |
2930 |
- ),"\n"; |
2931 |
- |
2932 |
- print $q->hidden( |
2933 |
- -name => 'state', |
2934 |
- -override => 1, |
2935 |
- -default => 'workstn-sel-restore2' |
2936 |
- ); |
2937 |
- |
2938 |
- print $q->hidden( |
2939 |
- -name => 'when', |
2940 |
- -override => 1, |
2941 |
- -value => $seldatebf |
2942 |
- ); |
2943 |
- |
2944 |
- print $q->endform; |
2945 |
- |
2946 |
- esmith::cgi::genFooter ($q); |
2947 |
- |
2948 |
-} |
2949 |
- |
2950 |
-sub performWorkstnSelRestore2 |
2951 |
-{ |
2952 |
- my ($q) = @_; |
2953 |
- |
2954 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
2955 |
- $fm->localise('RESTORE_IN_PROGRESS')); |
2956 |
- |
2957 |
- my @restorelist; |
2958 |
- my $when = $q->param ('seldatebefore'); |
2959 |
- if ($when =~ /^(.*)$/) |
2960 |
- { |
2961 |
- $when = $1; |
2962 |
- } |
2963 |
- else |
2964 |
- { |
2965 |
- die('Unsecure data : ' . $when); |
2966 |
- } |
2967 |
- my $tymd = |
2968 |
- qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/; |
2969 |
- my $thms = |
2970 |
- qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/; |
2971 |
- |
2972 |
- unless (($when =~ m/^$tymd$thms$/) || ($when eq "")) |
2973 |
- { |
2974 |
- esmith::cgi::genResult( |
2975 |
- $q, "$when : " . $fm->localise('ERR_INVALID_SELDATE') |
2976 |
- ); |
2977 |
- return; |
2978 |
- } |
2979 |
- |
2980 |
- my $f; |
2981 |
- foreach $f ($q->param ('restorefiles')) |
2982 |
- { |
2983 |
- if ($f =~ /^(.*)$/) |
2984 |
- { |
2985 |
- push @restorelist, "\"".$1."\""; |
2986 |
- } |
2987 |
- } |
2988 |
- |
2989 |
- # mounting backup shared folder |
2990 |
- |
2991 |
- my $backupwkrec = $conf->get('backupwk'); |
2992 |
- my $login = $backupwkrec->prop('Login'); |
2993 |
- my $password = $backupwkrec->prop('Password'); |
2994 |
- my $id = $backupwkrec->prop('Id') || |
2995 |
- $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; |
2996 |
- my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; |
2997 |
- my $mounted; |
2998 |
- my $VFSType = $backupwkrec->prop('VFSType') || 'cifs'; |
2999 |
- my $smbhost = $backupwkrec->prop('SmbHost'); |
3000 |
- my $smbshare = $backupwkrec->prop('SmbShare'); |
3001 |
- my $err; |
3002 |
- |
3003 |
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) |
3004 |
- { |
3005 |
- esmith::cgi::genResult( |
3006 |
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err |
3007 |
- ); |
3008 |
- return; |
3009 |
- } |
3010 |
- else {$mounted = 1} |
3011 |
- |
3012 |
- # Test if backup subdirectory for our server |
3013 |
- |
3014 |
- my $mntbkdir = $mntdir . "/$id"; |
3015 |
- unless (-d $mntbkdir) |
3016 |
- { |
3017 |
- if ($mounted) |
3018 |
- { |
3019 |
- system("/bin/umount", "$mntdir") == 0 |
3020 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
3021 |
- } |
3022 |
- esmith::cgi::genResult( |
3023 |
- $q, $fm->localise('ERR_NO_HOST_DIR'), $id |
3024 |
- ); |
3025 |
- return; |
3026 |
- } |
3027 |
- |
3028 |
- # backup is online, restoring now |
3029 |
- |
3030 |
- $| = 1; |
3031 |
- my $restorerr; |
3032 |
- |
3033 |
- if (open(RD, "-|")) |
3034 |
- { |
3035 |
- |
3036 |
- #----------------------------------------------------- |
3037 |
- # restore system from uploaded workstation backup file |
3038 |
- #----------------------------------------------------- |
3039 |
- |
3040 |
- print $q->p($fm->localise('FILES_HAVE_BEEN_RESTORED')); |
3041 |
- |
3042 |
- print '<UL>'; |
3043 |
- while (<RD>) |
3044 |
- { |
3045 |
- print "<li>$_</li>\n"; |
3046 |
- } |
3047 |
- |
3048 |
- print '</UL>'; |
3049 |
- my $message; |
3050 |
- if (!close RD) |
3051 |
- { |
3052 |
- $message = $fm->localise('RESTORE_FAILED_MSG'); |
3053 |
- } |
3054 |
- else |
3055 |
- { |
3056 |
- if ($restorerr) |
3057 |
- { |
3058 |
- $message = $fm->localise('RESTORE_FAILED'); |
3059 |
- } |
3060 |
- else |
3061 |
- { |
3062 |
- $message = $fm->localise('RESTORE_COMPLETE'); |
3063 |
- } |
3064 |
- } |
3065 |
- |
3066 |
- print $q->p ($q->b ($message)); |
3067 |
- |
3068 |
- esmith::cgi::genFooter ($q); |
3069 |
- } |
3070 |
- else |
3071 |
- { |
3072 |
- select(STDOUT); |
3073 |
- $| = 1; |
3074 |
- |
3075 |
- if ($when) |
3076 |
- { |
3077 |
- $restorerr = system ("/usr/bin/dar_manager -B $mntbkdir/dar-catalog -w $when -e '-N -R / -w' -r @restorelist"); |
3078 |
- } |
3079 |
- else |
3080 |
- { |
3081 |
- $restorerr = system ("/usr/bin/dar_manager -B $mntbkdir/dar-catalog -e '-N -R / -w' -r @restorelist"); |
3082 |
- } |
3083 |
- |
3084 |
- if ($mounted) |
3085 |
- { |
3086 |
- system("/bin/umount", "$mntdir") == 0 |
3087 |
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); |
3088 |
- } |
3089 |
- |
3090 |
- exit(0); |
3091 |
- } |
3092 |
- return; |
3093 |
-} |
3094 |
- |
3095 |
-sub performReboot () |
3096 |
-{ |
3097 |
- esmith::cgi::genHeaderNonCacheable ($q, undef, |
3098 |
- $fm->localise('SERVER_REBOOT')); |
3099 |
- |
3100 |
- print $q->p ( |
3101 |
- $q->b ($fm->localise('SERVER_WILL_REBOOT')) |
3102 |
- ); |
3103 |
- |
3104 |
- esmith::cgi::genFooter($fm); |
3105 |
- |
3106 |
- esmith::util::backgroundCommand( |
3107 |
- 5, |
3108 |
- "/sbin/e-smith/signal-event", |
3109 |
- "reboot" |
3110 |
- ); |
3111 |
-} |
3112 |
- |
3113 |
-sub CalculateSizes () |
3114 |
-{ |
3115 |
- #------------------------------------------------------------ |
3116 |
- # figure out the size of the tar file. |
3117 |
- #------------------------------------------------------------ |
3118 |
- |
3119 |
- my $tarsize = 0; |
3120 |
- |
3121 |
- # It takes way too much time to do a du on /home/e-smith. So we'll |
3122 |
- # estimate the current size. |
3123 |
- # We do this by checking the quota used by each user on the system. |
3124 |
- |
3125 |
- use Quota; |
3126 |
- use esmith::AccountsDB; |
3127 |
- my $accounts = esmith::AccountsDB->open; |
3128 |
- |
3129 |
- # Get a $dev value appropriate for use in Quota::query call. |
3130 |
- my $dev = Quota::getqcarg("/home/e-smith/files"); |
3131 |
- |
3132 |
- foreach my $user ($accounts->users()) |
3133 |
- { |
3134 |
- my $name = $user->key; |
3135 |
- my $uid = getpwnam($name); |
3136 |
- unless ($uid) |
3137 |
- { |
3138 |
- warn ($fm->localise('NO_UID_FOR_NAME').$name."\n"); |
3139 |
- # We shouldn't ever get here. If we do, we can't get |
3140 |
- # the quota value for this user, so we just skip to |
3141 |
- # the next one. |
3142 |
- next; |
3143 |
- } |
3144 |
- |
3145 |
- # Get current quota settings. |
3146 |
- my ($blocks) = Quota::query($dev, $uid, 0); |
3147 |
- $tarsize += $blocks; |
3148 |
- } |
3149 |
- |
3150 |
- # We add to this the size of root owned firectories, estimated using du. |
3151 |
- # If this takes too long, then the admin only has his or |
3152 |
- # herself to blame! |
3153 |
- |
3154 |
- # Remove /home/e-smith from backup list, and make paths absolute |
3155 |
- my @list = map { "/$_" } grep { !/home\/e-smith/ } @directories; |
3156 |
- open(DU, "-|") |
3157 |
- or exec '/usr/bin/du', '-s', @list; |
3158 |
- |
3159 |
- while (<DU>) |
3160 |
- { |
3161 |
- my ($du) = split(/\s+/); |
3162 |
- $tarsize += $du; |
3163 |
- } |
3164 |
- close DU; |
3165 |
- |
3166 |
- $tarsize = &showSize($tarsize); |
3167 |
- |
3168 |
- #------------------------------------------------------------ |
3169 |
- # figure out the size of the dump files |
3170 |
- #------------------------------------------------------------ |
3171 |
- |
3172 |
- my $dumpsize = 0; |
3173 |
- |
3174 |
- open(DF, "-|") |
3175 |
- or exec '/bin/df', '-P', '-t', 'ext3'; |
3176 |
- |
3177 |
- while (<DF>) |
3178 |
- { |
3179 |
- next unless (/^\//); |
3180 |
- |
3181 |
- (undef, undef, my $s, undef) = split(/\s+/, $_); |
3182 |
- |
3183 |
- $dumpsize += $s; |
3184 |
- } |
3185 |
- |
3186 |
- # increase size by 10% to cope with dump overhead. |
3187 |
- |
3188 |
- $dumpsize *= 1.1; |
3189 |
- |
3190 |
- close DF; |
3191 |
- |
3192 |
- $dumpsize = &showSize($dumpsize); |
3193 |
- |
3194 |
- #------------------------------------------------------------ |
3195 |
- # how much free space is in /tmp |
3196 |
- #------------------------------------------------------------ |
3197 |
- |
3198 |
- my $tmpfree = 0; |
3199 |
- my $halffree = 0; |
3200 |
- |
3201 |
- open(DF, "-|") |
3202 |
- or exec '/bin/df', '-P', '-t', 'ext3', '/tmp'; |
3203 |
- |
3204 |
- while (<DF>) |
3205 |
- { |
3206 |
- next unless (/^\//); |
3207 |
- |
3208 |
- (undef, undef, undef, my $s) = split(/\s+/, $_); |
3209 |
- |
3210 |
- $tmpfree += $s; |
3211 |
- } |
3212 |
- |
3213 |
- close DF; |
3214 |
- |
3215 |
- $halffree = $tmpfree / 2; |
3216 |
- |
3217 |
- $tmpfree = &showSize($tmpfree); |
3218 |
- $halffree = &showSize($halffree); |
3219 |
- |
3220 |
- return ($tarsize, $dumpsize, $tmpfree, $halffree); |
3221 |
-} |
3222 |
- |
3223 |
-sub showSize |
3224 |
-{ |
3225 |
- # convert size to Mb or Gb or Tb :) Remember, df reports in kb. |
3226 |
- |
3227 |
- my $size = shift; |
3228 |
- |
3229 |
- my $Mb = 1024; |
3230 |
- my $Gb = $Mb * $Mb; |
3231 |
- my $Tb = $Mb * $Mb * $Mb; |
3232 |
- |
3233 |
- if ($size >= $Tb) |
3234 |
- { |
3235 |
- $size /= $Tb; |
3236 |
- $size = int($size) . "Tb"; |
3237 |
- } |
3238 |
- elsif ($size >= $Gb) |
3239 |
- { |
3240 |
- $size /= $Gb; |
3241 |
- $size = int($size) . "Gb"; |
3242 |
- } |
3243 |
- elsif ($size >= $Mb) |
3244 |
- { |
3245 |
- $size /= $Mb; |
3246 |
- $size = int($size) . "Mb"; |
3247 |
- } |
3248 |
- else |
3249 |
- { |
3250 |
- $size .= "kb"; |
3251 |
- } |
3252 |
- |
3253 |
- return $size; |
3254 |
-} |
3255 |
- |
3256 |
-sub dmount() |
3257 |
-{ |
3258 |
- # mount dar unit according to dar-workstation configuration |
3259 |
- # return nothing if mount successfull |
3260 |
- |
3261 |
- my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; |
3262 |
- |
3263 |
- if ($VFSType eq 'cifs') |
3264 |
- { |
3265 |
- return ( qx(/bin/mount -t cifs "$host:$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix) ); |
3266 |
- } |
3267 |
- elsif ($VFSType eq 'nfs') |
3268 |
- { |
3269 |
- return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); |
3270 |
- } |
3271 |
- elsif ($VFSType eq 'usb') |
3272 |
- { |
3273 |
- $_[2] = "/" . $share; |
3274 |
- my $device = ""; |
3275 |
- my $blkdev = ""; |
3276 |
- my $vollbl = ""; |
3277 |
- foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { |
3278 |
- $udi =~ m/^(\S+)/; |
3279 |
- my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); |
3280 |
- |
3281 |
- if ($is_mounted eq "false\n") { |
3282 |
- $blkdev = qx(hal-get-property --udi $1 --key block.device); |
3283 |
- if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} |
3284 |
- } |
3285 |
- if ($is_mounted eq "false\n") { |
3286 |
- $vollbl = qx(hal-get-property --udi $1 --key volume.label); |
3287 |
- $vollbl =~ m/^(\S+)/; |
3288 |
- if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} |
3289 |
- } |
3290 |
- |
3291 |
- chomp $vollbl; |
3292 |
- chomp $blkdev; |
3293 |
- $vollbl = lc("media/$vollbl"); |
3294 |
- if ($vollbl eq $share) { |
3295 |
- $device = $blkdev; |
3296 |
- } |
3297 |
- } |
3298 |
- return ( qx(/bin/mount $device "/$share" 2>&1) ); |
3299 |
- } |
3300 |
- else |
3301 |
- { |
3302 |
- return ("Error while mounting $host/$share : $VFSType not supported.\n"); |
3303 |
- } |
3304 |
-} |
3305 |
- |
3306 |
-__DATA__ |
3307 |
-<form> |
3308 |
-</form> |