forked from poppyred/1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firehole.interfaces.php
executable file
·266 lines (210 loc) · 7.53 KB
/
firehole.interfaces.php
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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.firehol.inc');
$usersmenus=new usersMenus();
if($usersmenus->AsSystemAdministrator==false){
echo FATAL_ERROR_SHOW_128("{ERROR_NO_PRIVS}");
die();
}
if(isset($_GET["interfaces"])){search();exit;}
popup();
function popup(){
unset($_SESSION["postfix_firewall_rules"]);
$users=new usersMenus();
$tpl=new templates();
$page=CurrentPageName();
$rule=$tpl->_ENGINE_parse_body("{rule}");
$t=time();
$interfaces=$tpl->_ENGINE_parse_body("{interfaces}");
$netzone=$tpl->_ENGINE_parse_body("{netzone}");
$local_services=$tpl->_ENGINE_parse_body("{local_services}");
$log=$tpl->_ENGINE_parse_body("{LOG}");
$saved_date=$tpl->_ENGINE_parse_body("{zDate}");
$new_rule=$tpl->_ENGINE_parse_body("{new_rule}");
$name=$tpl->_ENGINE_parse_body("{name}");
$allow_rules=$tpl->_ENGINE_parse_body("{allow_rules}");
$banned_rules=$tpl->_ENGINE_parse_body("{banned_rules}");
$empty_all_firewall_rules=$tpl->javascript_parse_text("{empty_all_firewall_rules}");
$services=$tpl->_ENGINE_parse_body("{services}");
$current_rules=$tpl->_ENGINE_parse_body("{current_rules}");
$options=$tpl->_ENGINE_parse_body("{options}");
$ipaddr=$tpl->javascript_parse_text("{ipaddr}");
$ERROR_IPSET_NOT_INSTALLED=$tpl->javascript_parse_text("{ERROR_IPSET_NOT_INSTALLED}");
$IPSET_INSTALLED=0;
if($users->IPSET_INSTALLED){$IPSET_INSTALLED=1;}
$TB_HEIGHT=450;
$TABLE_WIDTH=920;
$TB2_WIDTH=400;
$ROW1_WIDTH=629;
$ROW2_WIDTH=163;
$t=time();
$buttons="
buttons : [
{name: '$empty', bclass: 'Delz', onpress : EmptyRules},
{name: '$new_rule', bclass: 'Add', onpress : NewIptableRule},
{name: '$allow_rules', bclass: 'Search', onpress : AllowRules},
{name: '$banned_rules', bclass: 'Search', onpress : BannedRules},
{name: '$block_countries', bclass: 'Catz', onpress : block_countries},
{name: '$current_rules', bclass: 'Search', onpress : current_rules},
{name: '$options', bclass: 'Settings', onpress : options$t},
], ";
$html="
<table class='FIREHOLE_INTERFACES_TABLES' style='display: none' id='FIREHOLE_INTERFACES_TABLES' style='width:99%'></table>
<script>
var IptableRow='';
$(document).ready(function(){
$('#FIREHOLE_INTERFACES_TABLES').flexigrid({
url: '$page?interfaces=yes&t=$t',
dataType: 'json',
colModel : [
{display: ' ', name : 'none', width :40, sortable : false, align: 'center'},
{display: '$interfaces', name : 'Interface', width :110, sortable : false, align: 'center'},
{display: '$name', name : 'NICNAME', width :222, sortable : false, align: 'left'},
{display: '$netzone', name : 'netzone', width :222, sortable : false, align: 'left'},
{display: '$local_services', name : 'none2', width :131, sortable : true, align: 'center'},
{display: '$services', name : 'none2', width :97, sortable : true, align: 'center'},
],
$buttons
searchitems : [
{display: '$interfaces', name : 'Interface'},
{display: '$name', name : 'NICNAME'},
{display: '$netzone', name : 'netzone'},
],
sortname: 'Interface',
sortorder: 'desc',
usepager: true,
title: '',
useRp: true,
rp: 15,
showTableToggleBtn: false,
width: '99%',
height: $TB_HEIGHT,
singleSelect: true
});
});
function block_countries(){
var IPSET_INSTALLED=$IPSET_INSTALLED;
if(IPSET_INSTALLED==0){alert('$ERROR_IPSET_NOT_INSTALLED');return;}
Loadjs('system.ipblock.php')
}
function current_rules(){
Loadjs('system.iptables.save.php');
}
var x_EmptyRules= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>3){alert(tempvalue);return;}
IpTablesInboundRuleResfresh();
}
function EmptyRules(){
if(confirm('$empty_all_firewall_rules ?')){
var XHR = new XHRConnection();
XHR.appendData('EmptyAll','yes');
XHR.sendAndLoad('$page', 'POST',x_EmptyRules);
}
}
function NewIptableRule(){
iptables_edit_rules('');
}
function IpTablesInboundRuleResfresh(){
$('#table-$t').flexReload();
}
function AllowRules(){
$('#table-$t').flexOptions({ url: '$page?iptables_rules=yes&t=$t&allow=1' }).flexReload();
}
function BannedRules(){
$('#table-$t').flexOptions({ url: '$page?iptables_rules=yes&t=$t&allow=0' }).flexReload();
}
var x_IptableDelete= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>3){alert(tempvalue);return;}
$('#row'+IptableRow).remove();
}
function options$t(){
Loadjs('$page?options=yes&table=table-$t',true);
}
function IptableDelete(key){
IptableRow=key;
var XHR = new XHRConnection();
XHR.appendData('DeleteIptableRule',key);
XHR.sendAndLoad('$page', 'POST',x_IptableDelete);
}
var x_FirewallDisableRUle= function (obj) {
var tempvalue=obj.responseText;
if(tempvalue.length>3){alert(tempvalue);}
}
function iptables_edit_rules(num){
YahooWin5('800','$page?edit_rule=yes&t=$t&rulemd5='+num,'$rule');
}
function FirewallDisableRUle(ID){
var XHR = new XHRConnection();
XHR.appendData('ID',ID);
if(document.getElementById('enabled_'+ID).checked){XHR.appendData('EnableFwRule',0);}else{XHR.appendData('EnableFwRule',1);}
XHR.sendAndLoad('$page', 'POST',x_FirewallDisableRUle);
}
function EnableLog(ID){
var XHR = new XHRConnection();
XHR.appendData('ID',ID);
if(document.getElementById('enabled_'+ID).checked){XHR.appendData('EnableLog',1);}else{XHR.appendData('EnableLog',0);}
XHR.sendAndLoad('$page', 'POST',x_FirewallDisableRUle);
}
</script>";
echo $html;
}
function search(){
$tpl=new templates();
$MyPage=CurrentPageName();
$q=new mysql();
$database="artica_backup";
$search='%';
$table="nics";
$page=1;
$ORDER=null;
$allow=null;
$total=0;
if($q->COUNT_ROWS($table,$database)==0){json_error_show("no data");;}
$searchstring=string_to_flexquery();
if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}}
if(isset($_POST['page'])) {$page = $_POST['page'];}
$table="(SELECT * FROM nics WHERE isFW=1) as t";
$sql="SELECT COUNT(*) as TCOUNT FROM $table WHERE 1 $searchstring";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,$database));
$total = $ligne["TCOUNT"];
if (isset($_POST['rp'])) {$rp = $_POST['rp'];}
$pageStart = ($page-1)*$rp;
$limitSql = "LIMIT $pageStart, $rp";
$sql="SELECT * FROM $table $ORDER $limitSql";
$results = $q->QUERY_SQL($sql,$database);
if(!$q->ok){json_error_show($q->mysql_error_html(),1);}
if(mysql_num_rows($results)==0){json_error_show("no data $sql");}
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
if(!$q->ok){json_error_show($q->mysql_error);}
$fontsize=18;
$firehole=new firehol();
while ($ligne = mysql_fetch_assoc($results)) {
$mouse="OnMouseOver=\"this.style.cursor='pointer'\" OnMouseOut=\"this.style.cursor='default'\"";
$linkstyle="style='text-decoration:underline'";
$Interface=$ligne["Interface"];
$NICNAME=$ligne["NICNAME"];
$netzone=$ligne["netzone"];
$CountDelocal=$firehole->interface_count_local_services($Interface);
$CountServices=$firehole->interface_count_allowed_services($Interface);
$js="Loadjs('system.nic.edit.php?nic=$Interface')";
$link="<a href=\"javascript:blur();\" OnClick=\"javascript:$js\" style='font-size:{$fontsize}px;text-decoration:underline'>";
$data['rows'][] = array(
'id' => $ligne["Interface"],
'cell' => array(
"<img src='img/folder-network-32.png' valign='middle'>",
"<span style='font-size:18px'>$link$Interface</a></span>",
"<span style='font-size:18px'>$link$NICNAME</a></span>",
"<span style='font-size:18px'>$netzone</span>",
"<span style='font-size:18px'>$CountDelocal</span>",
"<span style='font-size:18px'>$CountServices</span>",
)
);
}
echo json_encode($data);
}