forked from seccubus/seccubus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.pl
executable file
·333 lines (300 loc) · 10.2 KB
/
install.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/usr/bin/env perl
# Copyright 2014 Frank Breedijk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------
# Seccubus installation script
# ------------------------------------------------------------------------------
use strict;
use Getopt::Long;
sub syst($);
sub help(;$);
my (
$base_dir,
$www_dir,
$bin_dir,
$mod_dir,
$scan_dir,
$conf_dir,
$db_dir,
$doc_dir,
$stage_dir,
$stageonly,
$build_root,
$create_dirs,
$owner,
$wwwowner,
$help,
$verbose,
$quiet,
);
my @files = qw(
SeccubusV2.pm
);
my @dirs = qw(
www
SeccubusV2
bin
db
docs
etc
scanners
);
# Ticket #62 - Default locations for config.xml does not include
# /home/seccubus/etc/config.xml
my @patches = qw(
SeccubusV2.pm
etc/config.xml.mysql.example
www/seccubus/json/ConfigTest.pl
);
$base_dir = "/home/seccubus";
$stage_dir = "/tmp/SeccubusV2.stage.$$";
$help = 0;
GetOptions( 'basedir|b=s' => \$base_dir,
'wwwdir|w=s' => \$www_dir,
'bindir=s' => \$bin_dir,
'moddir|m=s' => \$mod_dir,
'scandir|s=s' => \$scan_dir,
'confdir|c=s' => \$conf_dir,
'dbdir|d=s' => \$db_dir,
'docdir=s' => \$doc_dir,
'owner|o=s' => \$owner,
'wwwowner|o=s' => \$wwwowner,
'stage_dir=s' => \$stage_dir,
'stageonly' => \$stageonly,
'buildroot=s' => \$build_root,
'createdirs' => \$create_dirs,
'help|h!' => \$help,
'verbose|v+' => \$verbose,
'quiet|q!' => \$quiet,
);
$verbose++;
$verbose = 0 if $quiet;
$www_dir = "$base_dir/www" unless $www_dir;
$bin_dir = "$base_dir/bin" unless $bin_dir;
$mod_dir = "$base_dir/SeccubusV2" unless $mod_dir;
$scan_dir = "$base_dir/scanners" unless $scan_dir;
$conf_dir = "$base_dir/etc" unless $conf_dir;
$db_dir = "$base_dir/db" unless $db_dir;
$doc_dir = "$base_dir/docs" unless $doc_dir;
$wwwowner = $owner unless $wwwowner;
if ( $build_root && ! $build_root =~ /\/$/ ) {
$build_root .= "/";
}
if ( $help ) {
help();
}
# Check if we have a stage root
print "Checking to see if target paths exists or created\n" if $verbose;
if ( -d "$stage_dir" ) {
print "Stage directory '$stage_dir' exists\n" if $verbose;
} else {
print "Creating stage directory '$stage_dir'\n" if $verbose;
syst("mkdir -p '$stage_dir'");
}
# Copy files to stage_dir
print "Copying files to stage_dir\n" if $verbose;
foreach my $file ( @files ) {
syst("cp $file $stage_dir");
}
print "Copying directories to stage_dir\n" if $verbose;
foreach my $dir ( @dirs ) {
syst("cp -r $dir $stage_dir");
}
print "Patching file paths\n" if $verbose;
foreach my $file ( @patches ) {
$file = "$stage_dir/$file";
syst("sed -i 's:/opt/seccubus/SeccubusV2:$mod_dir:' $file");
syst("sed -i 's:/opt/seccubus/scanners:$scan_dir:' $file");
syst("sed -i 's:/opt/seccubus/bin:$bin_dir:' $file");
syst("sed -i 's:/opt/seccubus/etc:$conf_dir:' $file");
syst("sed -i 's:/opt/seccubus/db:$db_dir:' $file");
}
print "Changing file ownership\n" if $verbose && ( $owner || $wwwowner );
syst("chown -R $owner $stage_dir") if $owner;
syst("chown -R $wwwowner $stage_dir/www") if $wwwowner;
# Quit if stageonly
exit if $stageonly;
# Check to see if paths need to be created
if ( -d "$build_root$base_dir" ) {
print "Basedir '$build_root$base_dir' exists\n" if $verbose;
} else {
if ( $create_dirs ) {
print "Creating basedir '$build_root$base_dir'\n" if $verbose;
syst("mkdir -p '$build_root$base_dir'");
syst("chown $owner $build_root$base_dir") if $owner;
} else {
help("Basedir '$build_root$base_dir' does not exist");
}
}
if ( -d "$build_root$www_dir" ) {
print "Wwwdir '$build_root$www_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $www_dir,$base_dir == 0 ) {
print "Creating wwwdir '$build_root$www_dir'\n" if $verbose;
syst("mkdir -p '$build_root$www_dir'");
syst("chown $wwwowner $build_root$www_dir") if $wwwowner;
} else {
help("Wwwdir '$build_root$www_dir' does not exist");
}
}
if ( -d "$build_root$bin_dir" ) {
print "Bindir '$build_root$bin_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $bin_dir,$base_dir == 0 ) {
print "Creating bindir '$build_root$bin_dir'\n" if $verbose;
syst("mkdir -p '$build_root$bin_dir'");
syst("chown $owner $build_root$bin_dir") if $owner;
} else {
help("Bindir '$build_root$bin_dir' does not exist");
}
}
if ( -d "$build_root$mod_dir" ) {
print "Moddir '$build_root$mod_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $mod_dir,$base_dir == 0 ) {
print "Creating moddir '$build_root$mod_dir'\n" if $verbose;
syst("mkdir -p '$build_root$mod_dir'");
syst("chown $owner $build_root$mod_dir") if $owner;
} else {
help("Moddir '$build_root$mod_dir' does not exist");
}
}
if ( -d "$build_root$scan_dir" ) {
print "Scandir '$build_root$scan_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $scan_dir, $base_dir == 0 ) {
print "Creating scandir '$build_root$scan_dir'\n" if $verbose;
syst("mkdir -p '$build_root$scan_dir'");
syst("chown $owner $build_root$scan_dir") if $owner;
} else {
help("Scandir '$build_root$scan_dir' does not exist");
}
}
if ( -d "$build_root$conf_dir" ) {
print "Confdir '$build_root$conf_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $conf_dir, $base_dir == 0 ) {
print "Creating confdir '$build_root$conf_dir'\n" if $verbose;
syst("mkdir -p '$build_root$conf_dir'");
syst("chown $owner $build_root$conf_dir") if $owner;
} else {
help("Confdir '$build_root$conf_dir' does not exist");
}
}
if ( -d "$build_root$db_dir" ) {
print "Dbdir '$build_root$db_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $db_dir, $base_dir == 0 ) {
print "Creating dbdir '$build_root$db_dir'\n" if $verbose;
syst("mkdir -p '$build_root$db_dir'");
syst("chown $owner $build_root$db_dir") if $owner;
} else {
help("Dbdir '$build_root$db_dir' does not exist");
}
}
if ( -d "$build_root$doc_dir" ) {
print "Docdir '$build_root$doc_dir' exists\n" if $verbose;
} else {
if ( $create_dirs || index $doc_dir, $base_dir == 0 ) {
print "Creating docdir '$build_root$doc_dir'\n" if $verbose;
syst("mkdir -p '$build_root$doc_dir'");
syst("chown $owner $build_root$doc_dir") if $owner;
} else {
help("Docdir '$build_root$doc_dir' does not exist");
}
}
# Moving files
print "Copying files and directories\n" if $verbose;
foreach my $file ( @files ) {
syst("cp -p $stage_dir/$file $build_root$base_dir");
}
syst("cp -p -r $stage_dir/www/* $build_root$www_dir");
syst("cp -p -r $stage_dir/bin/* $build_root$bin_dir");
syst("cp -p -r $stage_dir/SeccubusV2/* $build_root$mod_dir");
syst("cp -p -r $stage_dir/scanners/* $build_root$scan_dir");
syst("cp -p -r $stage_dir/etc/* $build_root$conf_dir");
syst("cp -p -r $stage_dir/db/* $build_root$db_dir");
syst("cp -p -r $stage_dir/docs/* $build_root$doc_dir");
# Link SeccubusV2.pm in www_dir
if ( -e "$build_root$www_dir/seccubus/SeccubusV2.pm" ) {
print "Removing old symbolic links to SeccubusV2.pm in wwwdir/seccubus\n" if $verbose;
syst("rm $build_root$www_dir/seccubus/SeccubusV2.pm");
}
print "Creating symbolic links to SeccubusV2.pm in wwwdir/seccubus\n" if $verbose;
syst("cd $build_root$www_dir/seccubus;ln -s $base_dir/SeccubusV2.pm");
# Clean up stage root
print "Cleaning up...\n" if $verbose;
syst("rm -rf $stage_dir");
# Done
exit;
sub syst($) {
my $cmd = shift;
print "Executing: $cmd\n" if $verbose >1;
my $result = `$cmd 2>&1`;
print "Result: $result\n" if $verbose >2;
print "\n" if $verbose;
}
sub help(;$) {
my $warning = shift;
print "$warning\n" if $warning;
print "
Install.PL - Install SeccubusV2 on your system
Usage: Install.PL [--basedir=<base path>] [--wwwdir=<www path>]
[--bindir=<binary path>] [--moddir=<module path>]
[--scandir=<scanners path>] [--confdir=<configuration path>]
[--dbdir=<database file dir>] [--owner=<file owner>]
[--wwwoner=<www file owner>] [--stage_dir=<stage path>]
[--buildroot=<build root> ] [--createdirs] [--help]
[--verbose] [--quiet]
Options (all optional):
--basedir (-b) - Base directory in which files will be installed
/home/seccubus by default
--wwwdir (-w) - Directory where web server files will be installed
<basedir>/www by default
--bindir - Directory where command line files will be installed
<basedir>/bin by default
--moddir (-m) - Directory where the .pm files will be installed
<basedir>/SeccubusV2 by default
--scandir (-s) - Direcotry where the scanner drivers will be installed
<basedir>/scanners> by default
--confdir (-c) - Directory where configuraiton files will be installed
<basedir>/etc by default
--dbdir (-d) - Directory where database creation and update files will be
installed
<basedir>/db by default
--owner (-o) - Ownership of the files as you would normally specify them for
the chown command
By default the file ownership is not changes and thus defaults
to the user running this script
--wwwowner - Ownership of the files for the webserver as you would
normally specify them for the chown command
By default the file ownership is not changes and thus defaults
to the user running this script
--stage_dir - Directory where the files will be staged first. This option
is usually only used by packagers
/tmp/SeccubusV2.stage.<pid> by default
--stageonly - Stop after the staging is done, do not clean the staging
directory
--buildroot - Create the file and directory structures in this place, but
don't append this to the hard coded paths. This option is
mainly intended for package builders
--createdirs - Create the destination directories. If specified the
destination directories will be created, otherwise the
installation will fail
--help - Displays this information
--verbose (-v) - Generate verbose output. Specify twice for even more output
--quiet (-q) - Do not generate output. Overrides --verbose.
";
exit;
}