-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·108 lines (85 loc) · 2.55 KB
/
install
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
#!/usr/bin/php
<?php
// variables
$pwd = realpath( dirname( __FILE__ ) );
$folders = array('fail2ban.d' => 1, 'jail.d' => 1, 'filter.d' => 0, 'action.d' => 0);
$log = '';
checkargs();
function checkargs(){
global $argv, $log;
// check fail2ban installation
if(!is_file('/usr/bin/fail2ban-server') || !is_file('/usr/bin/fail2ban-client')) {
die("Fail2ban is not installed\n");
}
if(!is_dir('/etc/fail2ban')) {
die("Fail2ban is does not have its configuration in /etc/fail2ban\n");
}
if( !isset($argv[1]) ) {
echo "Commands:\n";
echo "./install update - updates the local files from the current fail2filters repo;\n";
echo "./install 1 - installs the fail2filters configuration files into your fail2ban configuration folder (probably /etc/fail2ban);\n";
echo "./install 2 - uninstalls the fail2filters configuration files from your fail2ban configuration folder (probably /etc/fail2ban);\n\n";
echo "WARNING:\n";
echo " - upon 'install' or 'uninstall', fail2filters will empty the fail2ban.d & jail.d folders in your fail2ban configuration folder!\n";
echo " - when using 'update' all your local filters and jails in the fail2filters folder will be deleted.\n";
return;
}
if( strcmp(trim($argv[1]), "update") === 0 ){
echo "Update code from git repo.\n";
$log .= `git reset --hard`;
$log .= `git clean -f`;
$log .= `git pull`;
echo $log."\n";
return;
}
switch(trim($argv[1])){
case 1:
run(1);
break;
case 2:
run(2);
break;
default:
echo "Wrong arguments, Aborting ...\n";
break;
}
}
function run($option){
global $log;
f2f_folders();
if ($option == 1) { f2f_files(); }
else { f2f_files(1); }
echo "Restart fail2ban\n";
$log .= `/usr/bin/fail2ban-client restart`;
echo $log."\n";
}
function f2f_list($folder){
global $pwd;
if(!is_dir("{$pwd}/{$folder}/")) return array();
$list = explode("\n", `ls -lah {$pwd}/{$folder}/ |grep ".conf" |awk '{print \$NF}'`);
array_pop($list);
return $list;
}
function f2f_folders(){
global $pwd, $folders, $log;
foreach($folders as $folder => $delete){
if($delete){
echo "Emptying folder /etc/fail2ban/{$folder}\n";
$log .= `rm -rf /etc/fail2ban/{$folder}/*`;
}
}
}
function f2f_files($uninstall = 0){
global $pwd, $folders, $log;
foreach($folders as $folder => $delete){
$list = f2f_list($folder);
foreach($list as $file){
echo ($uninstall?"Uninstall":"Install")." {$folder}/{$file}\n";
$log .= `rm -rf /etc/fail2ban/{$folder}/{$file}`;
if(!$uninstall) {
$log .= `cp {$pwd}/{$folder}/{$file} /etc/fail2ban/{$folder}/{$file}`;
}
}
}
}
?>