commit | author | age
|
7c99ef
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
436ed8
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
7c99ef
|
5 |
All rights reserved. |
T |
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class firewall_plugin { |
|
32 |
|
|
33 |
var $plugin_name = 'firewall_plugin'; |
|
34 |
var $class_name = 'firewall_plugin'; |
|
35 |
|
392450
|
36 |
//* This function is called during ispconfig installation to determine |
T |
37 |
// if a symlink shall be created for this plugin. |
|
38 |
function onInstall() { |
|
39 |
global $conf; |
|
40 |
|
80e3c9
|
41 |
if($conf['bastille']['installed'] = true && $conf['services']['firewall'] == true) { |
T |
42 |
return true; |
|
43 |
} else { |
|
44 |
return false; |
|
45 |
} |
392450
|
46 |
|
T |
47 |
} |
|
48 |
|
7c99ef
|
49 |
|
T |
50 |
/* |
|
51 |
This function is called when the plugin is loaded |
|
52 |
*/ |
|
53 |
|
|
54 |
function onLoad() { |
|
55 |
global $app; |
|
56 |
|
|
57 |
/* |
|
58 |
Register for the events |
|
59 |
*/ |
|
60 |
|
|
61 |
//* Mailboxes |
|
62 |
$app->plugins->registerEvent('firewall_insert',$this->plugin_name,'insert'); |
|
63 |
$app->plugins->registerEvent('firewall_update',$this->plugin_name,'update'); |
|
64 |
$app->plugins->registerEvent('firewall_delete',$this->plugin_name,'delete'); |
|
65 |
|
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
function insert($event_name,$data) { |
|
71 |
global $app, $conf; |
|
72 |
|
|
73 |
$this->update($event_name,$data); |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
function update($event_name,$data) { |
|
78 |
global $app, $conf; |
|
79 |
|
|
80 |
$tcp_ports = ''; |
|
81 |
$udp_ports = ''; |
|
82 |
|
663caf
|
83 |
$ports = explode(',',$data['new']['tcp_port']); |
7c99ef
|
84 |
if(is_array($ports)) { |
T |
85 |
foreach($ports as $p) { |
7d5fa8
|
86 |
if(strstr($p,':')) { |
T |
87 |
$p_parts = explode(':',$p); |
|
88 |
$p_clean = intval($p_parts[0]).':'.intval($p_parts[1]); |
|
89 |
} else { |
|
90 |
$p_clean = intval($p); |
|
91 |
} |
b36d50
|
92 |
$tcp_ports .= $p_clean . ' '; |
7c99ef
|
93 |
} |
T |
94 |
} |
|
95 |
$tcp_ports = trim($tcp_ports); |
|
96 |
|
663caf
|
97 |
$ports = explode(',',$data['new']['udp_port']); |
7c99ef
|
98 |
if(is_array($ports)) { |
T |
99 |
foreach($ports as $p) { |
7d5fa8
|
100 |
if(strstr($p,':')) { |
T |
101 |
$p_parts = explode(':',$p); |
|
102 |
$p_clean = intval($p_parts[0]).':'.intval($p_parts[1]); |
|
103 |
} else { |
|
104 |
$p_clean = intval($p); |
|
105 |
} |
b36d50
|
106 |
$udp_ports .= $p_clean . ' '; |
7c99ef
|
107 |
} |
T |
108 |
} |
|
109 |
$udp_ports = trim($udp_ports); |
|
110 |
|
334a9f
|
111 |
$app->load('tpl'); |
7c99ef
|
112 |
$tpl = new tpl(); |
663caf
|
113 |
$tpl->newTemplate('bastille-firewall.cfg.master'); |
7c99ef
|
114 |
|
663caf
|
115 |
$tpl->setVar('TCP_PUBLIC_SERVICES',$tcp_ports); |
J |
116 |
$tpl->setVar('UDP_PUBLIC_SERVICES',$udp_ports); |
7c99ef
|
117 |
|
T |
118 |
file_put_contents('/etc/Bastille/bastille-firewall.cfg',$tpl->grab()); |
|
119 |
$app->log('Writing firewall configuration /etc/Bastille/bastille-firewall.cfg',LOGLEVEL_DEBUG); |
|
120 |
unset($tpl); |
|
121 |
|
663caf
|
122 |
if($data['new']['active'] == 'y') { |
J |
123 |
exec($conf['init_scripts'] . '/' . 'bastille-firewall restart'); |
7c99ef
|
124 |
if(@is_file('/etc/debian_version')) exec('update-rc.d bastille-firewall defaults'); |
T |
125 |
$app->log('Restarting the firewall',LOGLEVEL_DEBUG); |
|
126 |
} else { |
663caf
|
127 |
exec($conf['init_scripts'] . '/' . 'bastille-firewall stop'); |
a57e06
|
128 |
if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove'); |
7c99ef
|
129 |
$app->log('Stopping the firewall',LOGLEVEL_DEBUG); |
T |
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
function delete($event_name,$data) { |
|
136 |
global $app, $conf; |
|
137 |
|
663caf
|
138 |
exec($conf['init_scripts'] . '/' . 'bastille-firewall stop'); |
a57e06
|
139 |
if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove'); |
7c99ef
|
140 |
$app->log('Stopping the firewall',LOGLEVEL_DEBUG); |
T |
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
} // end class |
|
148 |
|
663caf
|
149 |
?> |