1 |
slords |
1.1 |
diff -Nur -x '*.orig' -x '*.rej' e-smith-portforwarding-1.2.0/root/etc/e-smith/db/configuration/migrate/10migrateMasqForwards mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/db/configuration/migrate/10migrateMasqForwards |
2 |
|
|
--- e-smith-portforwarding-1.2.0/root/etc/e-smith/db/configuration/migrate/10migrateMasqForwards 1969-12-31 17:00:00.000000000 -0700 |
3 |
|
|
+++ mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/db/configuration/migrate/10migrateMasqForwards 2007-06-26 09:46:46.000000000 -0600 |
4 |
|
|
@@ -0,0 +1,19 @@ |
5 |
|
|
+{ |
6 |
|
|
+ my %FDB; |
7 |
|
|
+ foreach my $proto ('TCP', 'UDP') { |
8 |
|
|
+ $FDB{$proto} = esmith::ConfigDB->open("portforward_" . lc($proto)) |
9 |
slords |
1.2 |
+ || esmith::ConfigDB->create("portforward_" . lc($proto)); |
10 |
slords |
1.1 |
+ |
11 |
|
|
+ my %rules = split ',', $DB->get_prop_and_delete('masq', "${proto}Forwards") |
12 |
|
|
+ || next; |
13 |
|
|
+ |
14 |
|
|
+ foreach my $entry (keys %rules) { |
15 |
|
|
+ my %props = ( type => 'forward' ); |
16 |
|
|
+ my ($addr, $port) = split ':', $rules{$entry}; |
17 |
|
|
+ $props{'DestHost'} = $addr; |
18 |
|
|
+ $props{'DestPort'} = $port if $port; |
19 |
|
|
+ |
20 |
|
|
+ $FDB{$proto}->new_record($entry, \%props); |
21 |
|
|
+ } |
22 |
|
|
+ } |
23 |
|
|
+} |
24 |
|
|
diff -Nur -x '*.orig' -x '*.rej' e-smith-portforwarding-1.2.0/root/etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward |
25 |
|
|
--- e-smith-portforwarding-1.2.0/root/etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward 2005-07-14 10:20:09.000000000 -0600 |
26 |
|
|
+++ mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward 2007-06-26 09:46:46.000000000 -0600 |
27 |
|
|
@@ -6,14 +6,18 @@ |
28 |
|
|
$OUT .= " sed -n '3s/ .*//p')\n"; |
29 |
|
|
$OUT .= " /sbin/iptables --table nat --new-chain $pf_chain\n"; |
30 |
|
|
|
31 |
|
|
+ my %FDB; |
32 |
|
|
+ |
33 |
|
|
foreach my $protocol (qw(tcp udp)) |
34 |
|
|
{ |
35 |
|
|
my $uproto = uc $protocol; |
36 |
|
|
- my $propname = $uproto . "Forwards"; |
37 |
|
|
- my %forwards = split(/,/, $masq{$propname} || ''); |
38 |
|
|
+ $FDB{$protocol} = esmith::ConfigDB->open("portforward_$protocol") |
39 |
|
|
+ || die "Can't open portforward_$protocol database: $!\n"; |
40 |
|
|
+ |
41 |
|
|
+ foreach my $entry ( $FDB{$protocol}->get_all ) { |
42 |
|
|
- foreach my $port (keys %forwards) |
43 |
|
|
- { |
44 |
|
|
- my ($ip, $dport) = split(/:/, $forwards{$port}); |
45 |
|
|
+ my $port = $entry->key; |
46 |
|
|
+ my $ip = $entry->prop('DestHost'); |
47 |
|
|
+ my $dport = $entry->prop('DestPort'); |
48 |
|
|
$port =~ s/-/:/; |
49 |
|
|
|
50 |
|
|
# Map canonical localhost back to our current external IP |
51 |
|
|
diff -Nur -x '*.orig' -x '*.rej' e-smith-portforwarding-1.2.0/root/etc/e-smith/web/functions/portforwarding mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/web/functions/portforwarding |
52 |
|
|
--- e-smith-portforwarding-1.2.0/root/etc/e-smith/web/functions/portforwarding 2003-03-31 11:48:05.000000000 -0700 |
53 |
|
|
+++ mezzanine_patched_e-smith-portforwarding-1.2.0/root/etc/e-smith/web/functions/portforwarding 2007-06-26 09:46:01.000000000 -0600 |
54 |
|
|
@@ -42,7 +42,7 @@ |
55 |
|
|
|
56 |
|
|
<!-- page 0 --> |
57 |
|
|
<page |
58 |
|
|
- name="Front" |
59 |
|
|
+ name="First" |
60 |
|
|
pre-event="print_status_message()"> |
61 |
|
|
<description>FIRST_PAGE_DESCRIPTION</description> |
62 |
|
|
|
63 |
|
|
diff -Nur -x '*.orig' -x '*.rej' e-smith-portforwarding-1.2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/portforwarding.pm mezzanine_patched_e-smith-portforwarding-1.2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/portforwarding.pm |
64 |
|
|
--- e-smith-portforwarding-1.2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/portforwarding.pm 2005-03-17 19:31:37.000000000 -0700 |
65 |
|
|
+++ mezzanine_patched_e-smith-portforwarding-1.2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/portforwarding.pm 2007-06-26 09:46:01.000000000 -0600 |
66 |
|
|
@@ -45,6 +45,10 @@ |
67 |
|
|
our $VERSION = sprintf '%d.%03d', q$Revision: 1.38 $ =~ /: (\d+).(\d+)/; |
68 |
|
|
our $db = esmith::ConfigDB->open |
69 |
|
|
|| die "Can't open configuration database: $!\n"; |
70 |
|
|
+our $tcp_db = esmith::ConfigDB->open('portforward_tcp') |
71 |
|
|
+ || die "Can't open portforward_tcp database: $!\n"; |
72 |
|
|
+our $udp_db = esmith::ConfigDB->open('portforward_udp') |
73 |
|
|
+ || die "Can't open portforward_udp database: $!\n"; |
74 |
|
|
|
75 |
|
|
=head1 NAME |
76 |
|
|
|
77 |
|
|
@@ -102,16 +106,14 @@ |
78 |
|
|
my $self = shift; |
79 |
|
|
my $q = $self->cgi; |
80 |
|
|
|
81 |
|
|
- my $masq = $db->get('masq') |
82 |
|
|
- || return $self->error('ERR_NO_MASQ_RECORD'); |
83 |
|
|
my $empty = 0; |
84 |
|
|
- my %tcpforwards = split /,/, $masq->prop('TCPForwards'); |
85 |
|
|
- my %udpforwards = split /,/, $masq->prop('UDPForwards'); |
86 |
|
|
- $empty = 1 if not %tcpforwards and not %udpforwards; |
87 |
|
|
+ my @tcpforwards = $tcp_db->get_all; |
88 |
|
|
+ my @udpforwards = $udp_db->get_all; |
89 |
|
|
+ $empty = 1 if not @tcpforwards and not @udpforwards; |
90 |
|
|
|
91 |
|
|
my %forwards = (); |
92 |
|
|
- $forwards{TCP} = \%tcpforwards; |
93 |
|
|
- $forwards{UDP} = \%udpforwards; |
94 |
|
|
+ $forwards{TCP} = \@tcpforwards; |
95 |
|
|
+ $forwards{UDP} = \@udpforwards; |
96 |
|
|
|
97 |
|
|
my $systemmode = $db->get_value('SystemMode'); |
98 |
|
|
|
99 |
|
|
@@ -165,10 +167,11 @@ |
100 |
|
|
), "\n ", |
101 |
|
|
); |
102 |
|
|
foreach my $proto (sort keys %forwards) { |
103 |
|
|
- if (%{ $forwards{$proto} }) { |
104 |
|
|
- foreach my $sport (keys %{ $forwards{$proto} }) { |
105 |
|
|
- my ($dhost, $dport) = split /:/, |
106 |
|
|
- $forwards{$proto}->{$sport}; |
107 |
|
|
+ if (@{ $forwards{$proto} }) { |
108 |
|
|
+ foreach my $entry (@{ $forwards{$proto} }) { |
109 |
|
|
+ my $sport = $entry->key; |
110 |
|
|
+ my $dhost = $entry->prop('DestHost'); |
111 |
|
|
+ my $dport = $entry->prop('DestPort') || ''; |
112 |
|
|
print $q->Tr( |
113 |
|
|
esmith::cgi::genSmallCell($q, $proto), |
114 |
|
|
" ", |
115 |
|
|
@@ -248,9 +251,15 @@ |
116 |
|
|
} |
117 |
|
|
# Now, lets screen any duplicates. |
118 |
|
|
my $protocol = $q->param('protocol'); |
119 |
|
|
+ my @forwards = (); |
120 |
|
|
+ |
121 |
|
|
# Grab the existing rules for this protocol. |
122 |
|
|
- my %forwards = split /,/, $db->get_prop('masq', "${protocol}Forwards"); |
123 |
|
|
- foreach my $psport (keys %forwards) |
124 |
|
|
+ if ($protocol eq 'TCP') { |
125 |
|
|
+ @forwards = map { $_->key } $tcp_db->get_all; |
126 |
|
|
+ } elsif ($protocol eq 'UDP') { |
127 |
|
|
+ @forwards = map { $_->key } $udp_db->get_all; |
128 |
|
|
+ } |
129 |
|
|
+ foreach my $psport (@forwards) |
130 |
|
|
{ |
131 |
|
|
if ($self->detect_collision($sport, $psport)) |
132 |
|
|
{ |
133 |
|
|
@@ -558,7 +567,7 @@ |
134 |
|
|
# If the cancel button was pressed, just go back to the start page. |
135 |
|
|
if ($q->param("cancel")) { |
136 |
|
|
$self->debug_msg("the cancel button was pressed"); |
137 |
|
|
- $self->wherenext("Front"); |
138 |
|
|
+ $self->wherenext("First"); |
139 |
|
|
} |
140 |
|
|
else { |
141 |
|
|
# Save the changes. |
142 |
|
|
@@ -577,74 +586,27 @@ |
143 |
|
|
$self->debug_msg("destination_host is $dhost"); |
144 |
|
|
|
145 |
|
|
my $whichforwards = ""; |
146 |
|
|
+ my $fdb; |
147 |
|
|
if ($proto eq 'TCP') { |
148 |
|
|
- $whichforwards = 'TCPForwards'; |
149 |
|
|
+ $fdb = $tcp_db; |
150 |
|
|
} |
151 |
|
|
else { |
152 |
|
|
- $whichforwards = 'UDPForwards'; |
153 |
|
|
+ $fdb = $udp_db; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
- # Port forwarding rules are properties of the masq record under a key |
157 |
|
|
- # of TCPForwards, with each one separated by commas, and the format of |
158 |
|
|
- # each being, "sport,host1:dport" |
159 |
|
|
- my $masq = $db->get('masq') |
160 |
|
|
- || return $self->error('ERR_NO_MASQ_RECORD'); |
161 |
|
|
- $self->debug_msg("fetching $whichforwards property from masq record"); |
162 |
|
|
- $$whichforwards = $masq->prop($whichforwards); |
163 |
|
|
- $self->debug_msg("the db property is $$whichforwards"); |
164 |
|
|
- |
165 |
|
|
if ($mode eq 'create') { |
166 |
|
|
$self->debug_msg("we are in create mode"); |
167 |
|
|
- my $newrule = "$sport,$dhost:$dport"; |
168 |
|
|
- $self->debug_msg("new rule is $newrule"); |
169 |
|
|
- if ($$whichforwards) { |
170 |
|
|
- # Look for an identical rule. |
171 |
|
|
- my $pattern; ($pattern = $newrule) =~ s/\./\\./g; |
172 |
|
|
- $self->debug_msg("looking for a dup rule; pattern $pattern"); |
173 |
|
|
- if ($$whichforwards =~ /$pattern/) { |
174 |
|
|
- $self->debug_msg("found a duplicate rule"); |
175 |
|
|
- return $self->error('ERR_DUPRULE'); |
176 |
|
|
- } |
177 |
|
|
- $$whichforwards .= ','; |
178 |
|
|
- } |
179 |
|
|
- else { |
180 |
|
|
- $$whichforwards = ''; |
181 |
|
|
- } |
182 |
|
|
- $$whichforwards .= $newrule; |
183 |
|
|
- $self->debug_msg("\$\$whichforwards is now $$whichforwards"); |
184 |
|
|
+ my $entry = $fdb->get($sport) || $fdb->new_record($sport, { type => 'forward' }); |
185 |
|
|
+ $entry->set_prop('DestHost', $dhost); |
186 |
|
|
+ $entry->set_prop('DestPort', $dport) if $dport; |
187 |
|
|
} |
188 |
|
|
elsif ($mode eq 'remove') { |
189 |
|
|
$self->debug_msg("we are in remove mode"); |
190 |
|
|
- if (! $$whichforwards) { |
191 |
|
|
- # The category is empty. Nothing to remove. |
192 |
|
|
- return $self->error('ERR_CANNOT_REMOVE_NORULE'); |
193 |
|
|
- } |
194 |
|
|
- my %forwards = split /,/, $$whichforwards; |
195 |
|
|
- $$whichforwards = ""; |
196 |
|
|
- my $found = FALSE; |
197 |
|
|
- foreach my $psport (keys %forwards) { |
198 |
|
|
- my ($pdhost, $pdport) = split /:/, $forwards{$psport}; |
199 |
|
|
- $self->debug_msg("looping on $psport, $pdhost, $pdport"); |
200 |
|
|
- if (($sport eq $psport) && |
201 |
|
|
- ($dport eq $pdport) && |
202 |
|
|
- ($dhost eq $pdhost)) |
203 |
|
|
- { |
204 |
|
|
- $found = TRUE; |
205 |
|
|
- $self->debug_msg("found the rule to remove"); |
206 |
|
|
- } |
207 |
|
|
- else { |
208 |
|
|
- $$whichforwards .= "$psport,$pdhost:$pdport,"; |
209 |
|
|
- $self->debug_msg("\$\$whichforwards is now $$whichforwards"); |
210 |
|
|
- } |
211 |
|
|
- } |
212 |
|
|
- if (! $found) { |
213 |
|
|
- return $self->error('ERR_CANNOT_REMOVE_NORULE'); |
214 |
|
|
- } |
215 |
|
|
- $$whichforwards =~ s/,$//; |
216 |
|
|
+ my $entry = $fdb->get($sport); |
217 |
|
|
+ return $self->error('ERR_CANNOT_REMOVE_NORULE') unless $entry; |
218 |
|
|
+ $entry->delete; |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
- $masq->set_prop("$whichforwards", $$whichforwards); |
222 |
|
|
- |
223 |
|
|
system("/sbin/e-smith/signal-event", |
224 |
|
|
"portforwarding-update") == 0 |
225 |
|
|
|| return $self->error('ERR_NONZERO_RETURN_EVENT'); |