line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::freebsd::ezjail Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Freebsd::Ezjail; |
7
|
1
|
|
|
1
|
|
884
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1417
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
list => [ ], |
20
|
|
|
|
|
|
|
start => [ qw(jail_name|$jail_list) ], |
21
|
|
|
|
|
|
|
stop => [ qw(jail_name|$jail_list) ], |
22
|
|
|
|
|
|
|
restart => [ qw(jail_name|$jail_list) ], |
23
|
|
|
|
|
|
|
create => [ qw(jail_name ip_address) ], |
24
|
|
|
|
|
|
|
backup => [ qw(jail_name|$jail_list) ], |
25
|
|
|
|
|
|
|
restore => [ qw(jail_name ip_address archive_tar_gz) ], |
26
|
|
|
|
|
|
|
delete => [ qw(jail_name) ], |
27
|
|
|
|
|
|
|
update => [ ], |
28
|
|
|
|
|
|
|
name_to_id => [ qw(jail_name) ], |
29
|
|
|
|
|
|
|
execute => [ qw(jail_name command) ], |
30
|
|
|
|
|
|
|
console => [ qw(jail_name) ], |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
require_binaries => { |
33
|
|
|
|
|
|
|
'ezjail-admin' => [ ], |
34
|
|
|
|
|
|
|
'jls' => [ ], |
35
|
|
|
|
|
|
|
'jexec' => [ ], |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub name_to_id { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('name_to_id', $jail_name) or return; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
my $out = $self->capture("ezjail-admin list") or return; |
47
|
|
|
|
|
|
|
# STA JID IP Hostname Root Directory |
48
|
|
|
|
|
|
|
# --- ---- --------------- ------------------------------ ------------------------ |
49
|
|
|
|
|
|
|
# DR 13 192.168.X.Y smtpout /usr/jails/smtpout |
50
|
0
|
|
|
|
|
|
for my $line (@$out) { |
51
|
|
|
|
|
|
|
#print "DEBUG line[$line]\n"; |
52
|
0
|
|
|
|
|
|
my @t = split(/\s+/, $line); |
53
|
|
|
|
|
|
|
#print "DEBUG [@t]\n"; |
54
|
0
|
0
|
0
|
|
|
|
if (defined($t[1]) && $t[1] =~ /^\d+$/ && defined($t[3]) && $t[3] =~ /^$jail_name$/) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $t[1]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $self->log->error("name_to_id: jail name not found"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub execute { |
63
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my ($jail_name, $command) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('execute', $jail_name) or return; |
67
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('execute', $command) or return; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $r; |
70
|
0
|
|
|
|
|
|
my @lines = (); |
71
|
0
|
0
|
|
|
|
|
if (ref($jail_name) eq 'ARRAY') { |
72
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
73
|
0
|
0
|
|
|
|
|
my $id = $self->name_to_id($jail) or next; |
74
|
0
|
|
|
|
|
|
my $cmd = "jexec $id $command"; |
75
|
0
|
|
|
|
|
|
$r = $self->SUPER::sudo_execute($cmd); |
76
|
0
|
0
|
|
|
|
|
if ($self->capture_mode) { |
77
|
0
|
|
|
|
|
|
push @lines, $r; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
0
|
|
|
|
|
my $id = $self->name_to_id($jail_name) or return; |
83
|
0
|
|
|
|
|
|
my $cmd = "jexec $id $command"; |
84
|
0
|
|
|
|
|
|
$r = $self->SUPER::sudo_execute($cmd); |
85
|
0
|
0
|
|
|
|
|
if ($self->capture_mode) { |
86
|
0
|
|
|
|
|
|
push @lines, $r; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if ($self->capture_mode) { |
91
|
0
|
|
|
|
|
|
return \@lines; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $r; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub list { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin list"; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub stop { |
106
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
107
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('stop', $jail_name) or return; |
110
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('stop', $jail_name, 'ARRAY', 'SCALAR') |
111
|
|
|
|
|
|
|
or return; |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
114
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
115
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin stop $jail"; |
116
|
0
|
|
|
|
|
|
$self->sudo_system($cmd); |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin stop $jail_name"; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub start { |
127
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
128
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('start', $jail_name) or return; |
131
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('start', $jail_name, 'ARRAY', 'SCALAR') |
132
|
|
|
|
|
|
|
or return; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
135
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
136
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin start $jail"; |
137
|
0
|
|
|
|
|
|
$self->sudo_system($cmd); |
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
return 1; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin start $jail_name"; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub restart { |
148
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restart', $jail_name) or return; |
152
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('restart', $jail_name, 'ARRAY', 'SCALAR') |
153
|
|
|
|
|
|
|
or return; |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
if (ref($jail_name) eq 'ARRAY') { |
156
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
157
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin restart $jail"; |
158
|
0
|
|
|
|
|
|
$self->sudo_system($cmd); |
159
|
|
|
|
|
|
|
} |
160
|
0
|
|
|
|
|
|
return 1; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin restart $jail_name"; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub create { |
169
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
my ($jail_name, $ip_address) = @_; |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('create', $jail_name) or return; |
173
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('create', $ip_address) or return; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin create $jail_name $ip_address"; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub backup { |
181
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
182
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
183
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('backup', $jail_name) or return; |
185
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('backup', $jail_name, 'ARRAY', 'SCALAR') |
186
|
|
|
|
|
|
|
or return; |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
189
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
190
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin archive -f $jail"; |
191
|
0
|
|
|
|
|
|
$self->sudo_system($cmd); |
192
|
|
|
|
|
|
|
} |
193
|
0
|
|
|
|
|
|
return 1; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin archive -f $jail_name"; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub restore { |
202
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
203
|
0
|
|
|
|
|
|
my ($jail_name, $ip_address, $archive_tar_gz) = @_; |
204
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restore', $jail_name) or return; |
206
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restore', $ip_address) or return; |
207
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restore', $archive_tar_gz) or return; |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin create -a $archive_tar_gz $jail_name $ip_address"; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub delete { |
215
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
216
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
217
|
|
|
|
|
|
|
|
218
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('delete', $jail_name) or return; |
219
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('delete', $jail_name, 'ARRAY', 'SCALAR') |
220
|
|
|
|
|
|
|
or return; |
221
|
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
|
if (ref($jail_name) eq 'ARRAY') { |
223
|
0
|
|
|
|
|
|
for my $jail (@$jail_name) { |
224
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin delete -fw $jail"; |
225
|
0
|
|
|
|
|
|
$self->sudo_system($cmd); |
226
|
|
|
|
|
|
|
} |
227
|
0
|
|
|
|
|
|
return 1; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin delete -fw $jail_name"; |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub update { |
236
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin update -u"; |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub console { |
244
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
245
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
246
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
my $cmd = "ezjail-admin console $jail_name"; |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
return $self->sudo_system($cmd); |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
__END__ |