Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
448d18a5
Commit
448d18a5
authored
Aug 18, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) refactor firewall_nat_edit.php
parent
fb74969b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
firewall_nat_edit.php
src/www/firewall_nat_edit.php
+24
-15
No files found.
src/www/firewall_nat_edit.php
View file @
448d18a5
...
@@ -35,6 +35,7 @@ require_once("pfsense-utils.inc");
...
@@ -35,6 +35,7 @@ require_once("pfsense-utils.inc");
* build array with interface options for this form
* build array with interface options for this form
*/
*/
function
formInterfaces
()
{
function
formInterfaces
()
{
global
$config
;
$interfaces
=
array
();
$interfaces
=
array
();
foreach
(
get_configured_interface_with_descr
(
false
,
true
)
as
$if
=>
$ifdesc
)
foreach
(
get_configured_interface_with_descr
(
false
,
true
)
as
$if
=>
$ifdesc
)
$interfaces
[
$if
]
=
$ifdesc
;
$interfaces
[
$if
]
=
$ifdesc
;
...
@@ -97,10 +98,10 @@ $a_nat = &$config['nat']['rule'];
...
@@ -97,10 +98,10 @@ $a_nat = &$config['nat']['rule'];
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'GET'
)
{
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'GET'
)
{
// load form data from config
// load form data from config
if
(
isset
(
$_GET
[
'id'
])
&&
is_numericint
(
$_GET
[
'id'
]))
{
if
(
isset
(
$_GET
[
'id'
])
&&
is_numericint
(
$_GET
[
'id'
])
&&
isset
(
$a_nat
[
$_GET
[
'id'
]])
)
{
$id
=
$_GET
[
'id'
];
$id
=
$_GET
[
'id'
];
$configId
=
$id
;
// load form data from id
$configId
=
$id
;
// load form data from id
}
else
if
(
isset
(
$_GET
[
'dup'
])
&&
is_numericint
(
$_GET
[
'dup'
])){
}
else
if
(
isset
(
$_GET
[
'dup'
])
&&
is_numericint
(
$_GET
[
'dup'
])
&&
isset
(
$a_nat
[
$_GET
[
'id'
]])
){
$after
=
$_GET
[
'dup'
];
$after
=
$_GET
[
'dup'
];
$configId
=
$_GET
[
'dup'
];
// load form data from id
$configId
=
$_GET
[
'dup'
];
// load form data from id
}
}
...
@@ -110,11 +111,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -110,11 +111,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// initialize form and set defaults
// initialize form and set defaults
$pconfig
=
array
();
$pconfig
=
array
();
$pconfig
[
'proto'
]
=
"tcp"
;
$pconfig
[
'proto
col
'
]
=
"tcp"
;
$pconfig
[
'srcbeginport'
]
=
"any"
;
$pconfig
[
'srcbeginport'
]
=
"any"
;
$pconfig
[
'srcendport'
]
=
"any"
;
$pconfig
[
'srcendport'
]
=
"any"
;
$pconfig
[
'interface'
]
=
"wan"
;
$pconfig
[
'interface'
]
=
"wan"
;
if
(
isset
(
$configId
)
&&
isset
(
$a_nat
[
$configId
]))
{
$pconfig
[
'dstbeginport'
]
=
80
;
$pconfig
[
'dstendport'
]
=
80
;
$pconfig
[
'local-port'
]
=
80
;
if
(
isset
(
$configId
))
{
// copy 1-on-1
// copy 1-on-1
foreach
(
array
(
'protocol'
,
'target'
,
'local-port'
,
'descr'
,
'interface'
,
'associated-rule-id'
,
'nosync'
foreach
(
array
(
'protocol'
,
'target'
,
'local-port'
,
'descr'
,
'interface'
,
'associated-rule-id'
,
'nosync'
,
'natreflection'
,
'created'
,
'updated'
)
as
$fieldname
)
{
,
'natreflection'
,
'created'
,
'updated'
)
as
$fieldname
)
{
...
@@ -154,7 +158,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -154,7 +158,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig
[
'src'
]
=
"any"
;
$pconfig
[
'src'
]
=
"any"
;
}
}
// init empty fields
// init empty fields
foreach
(
array
(
"dst"
,
"dstbeginport"
,
"dstendport"
,
"target"
,
"local-port"
,
"natreflection"
,
"descr"
,
"disabled"
,
"nosync"
)
as
$fieldname
)
{
foreach
(
array
(
"dst"
,
"dst
mask"
,
"srcmask"
,
"dst
beginport"
,
"dstendport"
,
"target"
,
"local-port"
,
"natreflection"
,
"descr"
,
"disabled"
,
"nosync"
)
as
$fieldname
)
{
if
(
!
isset
(
$pconfig
[
$fieldname
]))
{
if
(
!
isset
(
$pconfig
[
$fieldname
]))
{
$pconfig
[
$fieldname
]
=
null
;
$pconfig
[
$fieldname
]
=
null
;
}
}
...
@@ -163,7 +167,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -163,7 +167,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig
=
$_POST
;
$pconfig
=
$_POST
;
$input_errors
=
array
();
$input_errors
=
array
();
// save form data
// save form data
if
(
isset
(
$_POST
[
'id'
])
&&
is_numericint
(
$_POST
[
'id'
]))
{
if
(
isset
(
$_POST
[
'id'
])
&&
is_numericint
(
$_POST
[
'id'
])
&&
isset
(
$a_nat
[
$_POST
[
'id'
]])
)
{
$id
=
$_POST
[
'id'
];
$id
=
$_POST
[
'id'
];
}
}
if
(
isset
(
$_POST
[
'after'
])
&&
(
is_numericint
(
$_POST
[
'after'
])
||
$_POST
[
'after'
]
==
"-1"
))
{
if
(
isset
(
$_POST
[
'after'
])
&&
(
is_numericint
(
$_POST
[
'after'
])
||
$_POST
[
'after'
]
==
"-1"
))
{
...
@@ -241,7 +245,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -241,7 +245,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$natent
[
'protocol'
]
=
$pconfig
[
'protocol'
];
$natent
[
'protocol'
]
=
$pconfig
[
'protocol'
];
$natent
[
'interface'
]
=
$pconfig
[
'interface'
];
$natent
[
'interface'
]
=
$pconfig
[
'interface'
];
$natent
[
'descr'
]
=
$pconfig
[
'descr'
];
$natent
[
'descr'
]
=
$pconfig
[
'descr'
];
if
(
!
empty
(
$pconfig
[
'associated-rule-id'
]))
{
$natent
[
'associated-rule-id'
]
=
$pconfig
[
'associated-rule-id'
];
$natent
[
'associated-rule-id'
]
=
$pconfig
[
'associated-rule-id'
];
}
else
{
$natent
[
'associated-rule-id'
]
=
null
;
}
// form processing logic
// form processing logic
$natent
[
'disabled'
]
=
!
empty
(
$pconfig
[
'disabled'
])
?
true
:
false
;
$natent
[
'disabled'
]
=
!
empty
(
$pconfig
[
'disabled'
])
?
true
:
false
;
...
@@ -271,7 +280,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -271,7 +280,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
}
// If we used to have an associated filter rule, but no-longer should have one
// If we used to have an associated filter rule, but no-longer should have one
if
(
!
empty
(
$a_nat
[
$id
][
'associated-rule-id'
])
&&
(
empty
(
$natent
[
'associated-rule-id'
])
||
$natent
[
'associated-rule-id'
]
!=
$a_nat
[
$id
][
'associated-rule-id'
]
)
)
{
if
(
isset
(
$id
)
&&
!
empty
(
$a_nat
[
$id
][
'associated-rule-id'
])
&&
(
empty
(
$natent
[
'associated-rule-id'
])
||
$natent
[
'associated-rule-id'
]
!=
$a_nat
[
$id
][
'associated-rule-id'
]
)
)
{
// Delete the previous rule
// Delete the previous rule
foreach
(
$config
[
'filter'
][
'rule'
]
as
$key
=>
$item
){
foreach
(
$config
[
'filter'
][
'rule'
]
as
$key
=>
$item
){
if
(
isset
(
$item
[
'associated-rule-id'
])
&&
$item
[
'associated-rule-id'
]
==
$a_nat
[
$id
][
'associated-rule-id'
]
){
if
(
isset
(
$item
[
'associated-rule-id'
])
&&
$item
[
'associated-rule-id'
]
==
$a_nat
[
$id
][
'associated-rule-id'
]
){
...
@@ -359,7 +368,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
...
@@ -359,7 +368,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Update the NAT entry now
// Update the NAT entry now
$natent
[
'updated'
]
=
make_config_revision_entry
();
$natent
[
'updated'
]
=
make_config_revision_entry
();
if
(
isset
(
$id
)
&&
isset
(
$a_nat
[
$id
])
)
{
if
(
isset
(
$id
))
{
if
(
isset
(
$a_nat
[
$id
][
'created'
]))
{
if
(
isset
(
$a_nat
[
$id
][
'created'
]))
{
$natent
[
'created'
]
=
$a_nat
[
$id
][
'created'
];
$natent
[
'created'
]
=
$a_nat
[
$id
][
'created'
];
}
}
...
@@ -420,8 +429,8 @@ $( document ).ready(function() {
...
@@ -420,8 +429,8 @@ $( document ).ready(function() {
});
});
// trigger initial form change
// trigger initial form change
$
(
"
#proto
"
).
change
();
// protocol
$
(
"
#nordr
"
).
change
();
// no-rdr
$
(
"
#nordr
"
).
change
();
// no-rdr
$
(
"
#proto
"
).
change
();
// protocol
// show source address when selected
// show source address when selected
<?php
if
(
!
empty
(
$pconfig
[
'srcnot'
])
||
$pconfig
[
'src'
]
!=
"any"
||
$pconfig
[
'srcbeginport'
]
!=
"any"
||
$pconfig
[
'srcendport'
]
!=
"any"
)
:
?>
<?php
if
(
!
empty
(
$pconfig
[
'srcnot'
])
||
$pconfig
[
'src'
]
!=
"any"
||
$pconfig
[
'srcbeginport'
]
!=
"any"
||
$pconfig
[
'srcendport'
]
!=
"any"
)
:
?>
...
@@ -618,7 +627,7 @@ $( document ).ready(function() {
...
@@ -618,7 +627,7 @@ $( document ).ready(function() {
</table>
</table>
</td>
</td>
</tr>
</tr>
<tr
class=
"hidden a
ct_port_select"
name=
"sprtable
"
>
<tr
class=
"hidden a
dvanced_opt_src
"
>
<td><a
id=
"help_for_srcport"
href=
"#"
class=
"showhelp"
><i
class=
"fa fa-info-circle"
></i></a>
<?=
gettext
(
"Source port range"
);
?>
</td>
<td><a
id=
"help_for_srcport"
href=
"#"
class=
"showhelp"
><i
class=
"fa fa-info-circle"
></i></a>
<?=
gettext
(
"Source port range"
);
?>
</td>
<td>
<td>
<table
class=
"table table-condensed"
>
<table
class=
"table table-condensed"
>
...
@@ -873,7 +882,7 @@ $( document ).ready(function() {
...
@@ -873,7 +882,7 @@ $( document ).ready(function() {
</select>
</select>
</td>
</td>
</tr>
</tr>
<?php
if
(
isset
(
$id
)
&&
isset
(
$a_nat
[
$id
])
&&
(
!
isset
(
$_GET
[
'dup'
])
||
!
is_numericint
(
$_GET
[
'dup'
])))
:
?>
<?php
if
(
isset
(
$id
)
&&
(
!
isset
(
$_GET
[
'dup'
])
||
!
is_numericint
(
$_GET
[
'dup'
])))
:
?>
<tr
class=
"act_no_rdr"
>
<tr
class=
"act_no_rdr"
>
<td><i
class=
"fa fa-info-circle text-muted"
></i>
<?=
gettext
(
"Filter rule association"
);
?>
</td>
<td><i
class=
"fa fa-info-circle text-muted"
></i>
<?=
gettext
(
"Filter rule association"
);
?>
</td>
<td>
<td>
...
@@ -904,7 +913,7 @@ $( document ).ready(function() {
...
@@ -904,7 +913,7 @@ $( document ).ready(function() {
<a
href=
"firewall_rules_edit.php?id=
<?=
$linkedrule
;
?>
"
>
<?=
gettext
(
"View the filter rule"
);
?>
</a>
<a
href=
"firewall_rules_edit.php?id=
<?=
$linkedrule
;
?>
"
>
<?=
gettext
(
"View the filter rule"
);
?>
</a>
</td>
</td>
</tr>
</tr>
<?php
elseif
(
(
!
isset
(
$id
)
&&
!
isset
(
$a_nat
[
$id
])
)
||
(
isset
(
$_GET
[
'dup'
])
&&
is_numericint
(
$_GET
[
'dup'
])))
:
<?php
elseif
(
!
isset
(
$id
)
||
(
isset
(
$_GET
[
'dup'
])
&&
is_numericint
(
$_GET
[
'dup'
])))
:
?>
?>
<tr
class=
"act_no_rdr"
>
<tr
class=
"act_no_rdr"
>
<td><a
id=
"help_for_fra"
href=
"#"
class=
"showhelp"
><i
class=
"fa fa-info-circle"
></i></a>
<?=
gettext
(
"Filter rule association"
);
?>
</td>
<td><a
id=
"help_for_fra"
href=
"#"
class=
"showhelp"
><i
class=
"fa fa-info-circle"
></i></a>
<?=
gettext
(
"Filter rule association"
);
?>
</td>
...
@@ -961,8 +970,8 @@ $( document ).ready(function() {
...
@@ -961,8 +970,8 @@ $( document ).ready(function() {
<td>
<td>
<input
name=
"Submit"
type=
"submit"
class=
"btn btn-primary"
value=
"
<?=
gettext
(
"Save"
);
?>
"
/>
<input
name=
"Submit"
type=
"submit"
class=
"btn btn-primary"
value=
"
<?=
gettext
(
"Save"
);
?>
"
/>
<input
type=
"button"
class=
"btn btn-default"
value=
"
<?=
gettext
(
"Cancel"
);
?>
"
onclick=
"window.location.href='
<?=
isset
(
$_SERVER
[
'HTTP_REFERER'
])
?
$_SERVER
[
'HTTP_REFERER'
]
:
'/firewall_nat.php'
;
?>
'"
/>
<input
type=
"button"
class=
"btn btn-default"
value=
"
<?=
gettext
(
"Cancel"
);
?>
"
onclick=
"window.location.href='
<?=
isset
(
$_SERVER
[
'HTTP_REFERER'
])
?
$_SERVER
[
'HTTP_REFERER'
]
:
'/firewall_nat.php'
;
?>
'"
/>
<?php
if
(
isset
(
$id
)
&&
isset
(
$a_nat
[
$id
])
)
:
?>
<?php
if
(
isset
(
$id
))
:
?>
<input
name=
"id"
type=
"hidden"
value=
"
<?=
htmlspecialchars
(
$id
)
;
?>
"
/>
<input
name=
"id"
type=
"hidden"
value=
"
<?=
$id
;
?>
"
/>
<?php
endif
;
?>
<?php
endif
;
?>
<?php
if
(
isset
(
$after
))
:
?>
<?php
if
(
isset
(
$after
))
:
?>
<input
name=
"after"
type=
"hidden"
value=
"
<?=
htmlspecialchars
(
$after
);
?>
"
/>
<input
name=
"after"
type=
"hidden"
value=
"
<?=
htmlspecialchars
(
$after
);
?>
"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment