forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_config.pl
executable file
·106 lines (91 loc) · 2.59 KB
/
backup_config.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use strict;
use warnings;
require 'acl-lib.pl';
our ($config_directory, %gconfig);
# backup_config_files()
# Returns files and directories that can be backed up
sub backup_config_files
{
my @rv;
# Add primary user and group files
my %miniserv;
&get_miniserv_config(\%miniserv);
push(@rv, $miniserv{'userfile'});
push(@rv, &acl_filename());
# Add all .acl files for users and groups
foreach my $u (&list_users(), &list_groups()) {
if (!$u->{'proto'}) {
push(@rv, "$config_directory/$u->{'name'}.acl",
glob("$config_directory/*/$u->{'name'}.acl"));
}
}
# Add /etc/webmin/config
©_source_dest("$config_directory/config",
"$config_directory/config.aclbackup");
push(@rv, "$config_directory/config.aclbackup");
# Add /etc/webmin/miniserv.conf
©_source_dest("$config_directory/miniserv.conf",
"$config_directory/miniserv.conf.aclbackup");
push(@rv, "$config_directory/miniserv.conf.aclbackup");
return @rv;
}
# pre_backup(&files)
# Called before the files are actually read
sub pre_backup
{
return undef;
}
# post_backup(&files)
# Called after the files are actually read
sub post_backup
{
unlink("$config_directory/config.aclbackup");
unlink("$config_directory/miniserv.conf.aclbackup");
return undef;
}
# pre_restore(&files)
# Called before the files are restored from a backup
sub pre_restore
{
# Remove user and group .acl files
foreach my $u (&list_users(), &list_groups()) {
if (!$u->{'proto'}) {
unlink("$config_directory/$u->{'name'}.acl",
glob("$config_directory/*/$u->{'name'}.acl"));
}
}
return undef;
}
# post_restore(&files)
# Called after the files are restored from a backup
sub post_restore
{
# Splice global config entries for users into real config
my %aclbackup;
&read_file("$config_directory/config.aclbackup", \%aclbackup);
unlink("$config_directory/config.aclbackup");
foreach my $k (keys %gconfig) {
delete($gconfig{$k}) if ($k =~ /^(lang_|notabs_|theme_|ownmods_)/);
}
foreach my $k (keys %aclbackup) {
$gconfig{$k} = $aclbackup{$k} if ($k =~ /^(lang_|notabs_|theme_|ownmods_)/);
}
&write_file("$config_directory/config", \%gconfig);
# Splice miniserv.conf entries for users and password restrictions into
# real config
%aclbackup = ( );
&read_file("$config_directory/miniserv.conf.aclbackup", \%aclbackup);
unlink("$config_directory/miniserv.conf.aclbackup");
my %miniserv;
&get_miniserv_config(\%miniserv);
foreach my $k (keys %miniserv) {
delete($miniserv{$k}) if ($k =~ /^(preroot_|pass_)/);
}
foreach my $k (keys %aclbackup) {
$miniserv{$k} = $aclbackup{$k} if ($k =~ /^(preroot_|pass_)/);
}
&put_miniserv_config(\%miniserv);
&restart_miniserv();
return undef;
}
1;