1 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Localnetworks.pm smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Localnetworks.pm |
2 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Localnetworks.pm 2020-04-07 07:05:13.511766797 +0100 |
3 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Localnetworks.pm 2020-04-07 06:44:00.000000000 +0100 |
4 |
@@ -13,9 +13,6 @@ |
5 |
use esmith::util; |
6 |
use esmith::HostsDB; |
7 |
|
8 |
-#use esmith::AccountsDB; |
9 |
-#our $cdb = esmith::ConfigDB->open || die "Couldn't open configuration db"; |
10 |
- |
11 |
my $network_db = esmith::NetworksDB->open() || die("Couldn't open networks db"); |
12 |
my $ret = "OK"; |
13 |
|
14 |
@@ -73,7 +70,6 @@ |
15 |
if ( $trt eq 'ADD1' ) { |
16 |
#Add a network - called after new network details filled in |
17 |
my %ret = add_network($c); |
18 |
- #die(%ret); |
19 |
#Return to list page if success |
20 |
if ((index($ret{ret},"SUCCESS") != -1)) { |
21 |
$trt = "LIST"; |
22 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Portforwarding.pm smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Portforwarding.pm |
23 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Portforwarding.pm 1970-01-01 01:00:00.000000000 +0100 |
24 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/Controller/Portforwarding.pm 2020-04-06 12:31:00.000000000 +0100 |
25 |
@@ -0,0 +1,407 @@ |
26 |
+package SrvMngr::Controller::Portforwarding; |
27 |
+ |
28 |
+use strict; |
29 |
+use warnings; |
30 |
+use Mojo::Base 'Mojolicious::Controller'; |
31 |
+ |
32 |
+use Locale::gettext; |
33 |
+use SrvMngr::I18N; |
34 |
+use SrvMngr qw(theme_list init_session_cgi); |
35 |
+#use Regexp::Common qw /net/; |
36 |
+ |
37 |
+use Data::Dumper; |
38 |
+use esmith::util; |
39 |
+use esmith::HostsDB; |
40 |
+ |
41 |
+our $db = esmith::ConfigDB->open |
42 |
+ || die "Can't open configuration database: $!\n"; |
43 |
+our $tcp_db = esmith::ConfigDB->open('portforward_tcp') |
44 |
+ || die "Can't open portforward_tcp database: $!\n"; |
45 |
+our $udp_db = esmith::ConfigDB->open('portforward_udp') |
46 |
+ || die "Can't open portforward_udp database: $!\n"; |
47 |
+ |
48 |
+ |
49 |
+my %ret = (); |
50 |
+ |
51 |
+use constant FALSE => 0; |
52 |
+use constant TRUE => 1; |
53 |
+ |
54 |
+sub main { |
55 |
+ |
56 |
+ my $c = shift; |
57 |
+ $c->app->log->info( $c->log_req ); |
58 |
+ |
59 |
+ my %pf_datas = (); |
60 |
+ $pf_datas{return} = ""; |
61 |
+ my $title = $c->l('pf_FORM_TITLE'); |
62 |
+ my $modul = ''; |
63 |
+ |
64 |
+ $pf_datas{trt} = 'LIST'; |
65 |
+ |
66 |
+ my @tcpforwards = $tcp_db->get_all; |
67 |
+ my @udpforwards = $udp_db->get_all; |
68 |
+ my $empty = 1 if not @tcpforwards and not @udpforwards; |
69 |
+ |
70 |
+ $c->stash( |
71 |
+ title => $title, |
72 |
+ modul => $modul, |
73 |
+ pf_datas => \%pf_datas, |
74 |
+ tcpforwards =>\@tcpforwards, |
75 |
+ udpforwards =>\@udpforwards, |
76 |
+ empty => $empty |
77 |
+ ); |
78 |
+ $c->render( template => 'portforwarding' ); |
79 |
+} |
80 |
+ |
81 |
+sub do_display { |
82 |
+ |
83 |
+ my $c = shift; |
84 |
+ $c->app->log->info( $c->log_req ); |
85 |
+ #my $pf_datas = $c->stash('pf_datas'); |
86 |
+ my $portforwards = $c->stash('portforwards'); |
87 |
+ |
88 |
+ my $rt = $c->current_route; |
89 |
+ my $trt = ( $c->param('trt') || 'LIST' ); |
90 |
+ |
91 |
+ |
92 |
+ $trt = 'DEL' if ( $rt eq 'portforwardingdel' ); |
93 |
+ $trt = 'ADD' if ( $rt eq 'portforwardingadd' ); |
94 |
+ $trt = 'ADD1' if ( $rt eq 'portforwardingadd1' ); |
95 |
+ $trt = 'DEL1' if ( $rt eq 'portforwardingdel1' ); |
96 |
+ |
97 |
+ my %pf_datas = (); |
98 |
+ my $title = $c->l('pf_FORM_TITLE'); |
99 |
+ my $modul = ''; |
100 |
+ |
101 |
+ |
102 |
+ if ( $trt eq 'ADD' ) { |
103 |
+ # Add a portforward- called from the list panel |
104 |
+ # Nothing to do here...as just need template to display fields to input data. |
105 |
+ |
106 |
+ } |
107 |
+ |
108 |
+ if ( $trt eq 'ADD1' ) { |
109 |
+ #Add a port forward - called after new pf details filled in |
110 |
+ my %ret = add_portforward($c); |
111 |
+ #Return to list page if success |
112 |
+ if ((index($ret{ret},"SUCCESS") != -1)) { |
113 |
+ $trt = "LIST"; |
114 |
+ } else { |
115 |
+ #Error - return to Add page |
116 |
+ $trt = "ADD"; |
117 |
+ } |
118 |
+ $c->stash(ret=>\%ret); |
119 |
+ } |
120 |
+ |
121 |
+ if ( $trt eq 'DEL1' ) { |
122 |
+ ##After Remove clicked on Delete network panel |
123 |
+ my $sport = $c->param("sport") || ''; |
124 |
+ my $proto = $c->param("proto") || ''; |
125 |
+ #work out which protocol |
126 |
+ my $fdb; |
127 |
+ if ($proto eq 'TCP') { |
128 |
+ $fdb = $tcp_db; |
129 |
+ } |
130 |
+ else { |
131 |
+ $fdb = $udp_db; |
132 |
+ } |
133 |
+ #check that the sport is in the db |
134 |
+ my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); |
135 |
+ $entry->delete; |
136 |
+ system( "/sbin/e-smith/signal-event", "portforwarding-update") == 0 |
137 |
+ or ( die($c->l('pf_ERR_NONZERO_RETURN_EVENT'))); |
138 |
+ $trt = "LIST"; |
139 |
+ my %ret = (ret=>"pf_SUCCESS"); |
140 |
+ $c->stash(ret=>\%ret); |
141 |
+ } |
142 |
+ |
143 |
+ if ( $trt eq 'DEL' ) { |
144 |
+ ##Initial delete panel requiring confirmation |
145 |
+ my $sport = $c->param("sport") || ''; |
146 |
+ my $proto = $c->param("proto") || ''; |
147 |
+ $c->stash(sport=>$sport); |
148 |
+ #work out which protocol |
149 |
+ my $fdb; |
150 |
+ if ($proto eq 'TCP') { |
151 |
+ $fdb = $tcp_db; |
152 |
+ } |
153 |
+ else { |
154 |
+ $fdb = $udp_db; |
155 |
+ } |
156 |
+ #pull out details and pass to template |
157 |
+ my $entry = $fdb->get($sport) || die("Unable to find sport and proto $sport $proto"); |
158 |
+ $pf_datas{proto} = $proto; |
159 |
+ $pf_datas{sport} = $sport; |
160 |
+ $pf_datas{dhost} = $entry->prop('DestHost'); |
161 |
+ $pf_datas{dport} = $entry->prop('DestPort') || ''; |
162 |
+ $pf_datas{cmmnt} = $entry->prop('Comment') || ''; |
163 |
+ $pf_datas{allow} = $entry->prop('AllowHosts') || ''; |
164 |
+ } |
165 |
+ |
166 |
+ if ( $trt eq 'LIST' ) { |
167 |
+ #List all the port forwards |
168 |
+ my @tcpforwards = $tcp_db->get_all; |
169 |
+ my @udpforwards = $udp_db->get_all; |
170 |
+ my $empty = 1 if not @tcpforwards and not @udpforwards; |
171 |
+ |
172 |
+ $c->stash( |
173 |
+ tcpforwards =>\@tcpforwards, |
174 |
+ udpforwards =>\@udpforwards, |
175 |
+ empty => $empty |
176 |
+ ); |
177 |
+ |
178 |
+ #my %forwards = (TCP=>@tcpforwards,UDP=>@udpforwards); |
179 |
+ #$c->stash(portforwarding => %forwards); |
180 |
+ } |
181 |
+ |
182 |
+ $pf_datas{'trt'} = $trt; |
183 |
+ $c->stash( title => $title, modul => $modul, pf_datas => \%pf_datas ); |
184 |
+ $c->render( template => 'portforwarding' ); |
185 |
+} |
186 |
+ |
187 |
+sub add_portforward { |
188 |
+ my $c = shift; |
189 |
+ my $sport = $c->param("sport") || ''; |
190 |
+ my $proto = $c->param("proto") || ''; |
191 |
+ #work out which protocol |
192 |
+ my $fdb; |
193 |
+ if ($proto eq 'TCP') { |
194 |
+ $fdb = $tcp_db; |
195 |
+ } |
196 |
+ else { |
197 |
+ $fdb = $udp_db; |
198 |
+ } |
199 |
+ #Get the values |
200 |
+ my $proto = $c->param("proto"); |
201 |
+ my $sport = $c->param("sport"); |
202 |
+ my $dport = $c->param("dport"); |
203 |
+ my $dhost = get_destination_host($c); |
204 |
+ my $cmmnt = $c->param("commnt") || ""; |
205 |
+ my $allow = $c->param("allow") || ""; |
206 |
+ my $deny = (($c->param("allow")) ? "0.0.0.0/0" : ""); |
207 |
+ $proto =~ s/^\s+|\s+$//g; |
208 |
+ $sport =~ s/^\s+|\s+$//g; |
209 |
+ $dport =~ s/^\s+|\s+$//g; |
210 |
+ $dhost =~ s/^\s+|\s+$//g; |
211 |
+ #Validate the values |
212 |
+ %ret=validate_source_port($c) ; unless (index($ret{ret},"SUCCESS")!= -1) {return %ret;} |
213 |
+ %ret=validate_allowed_hosts($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} |
214 |
+ %ret=validate_destination_port($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} |
215 |
+ %ret=validate_destination_host($c) ; if (index($ret{ret},"SUCCESS")== -1) {return %ret;} |
216 |
+ # and then write it to the DB and tell the exec about it. |
217 |
+ my $entry = $fdb->get($sport) || $fdb->new_record($sport, { type => 'forward' }); |
218 |
+ $entry->set_prop('DestHost', $dhost); |
219 |
+ $entry->set_prop('DestPort', $dport) if $dport; |
220 |
+ $entry->set_prop('Comment', $cmmnt); |
221 |
+ $entry->set_prop('AllowHosts', $allow); |
222 |
+ $entry->set_prop('DenyHosts', $deny); |
223 |
+ system( "/sbin/e-smith/signal-event", "portforwarding-update") == 0 |
224 |
+ or ( return (ret=>'pf_ERR_NONZERO_RETURN_EVENT' )); |
225 |
+ my %ret = (ret=>"pf_SUCCESS"); |
226 |
+ return %ret; |
227 |
+ |
228 |
+} |
229 |
+ |
230 |
+sub get_destination_host |
231 |
+{ |
232 |
+ my $q = shift; |
233 |
+ my $dhost = $q->param("dhost"); |
234 |
+ my $localip = $db->get_prop('InternalInterface', 'IPAddress'); |
235 |
+ my $external_ip = $db->get_prop('ExternalInterface', 'IPAddress') || $localip; |
236 |
+ |
237 |
+ if ($dhost =~ /^(127.0.0.1|$localip|$external_ip)$/i) |
238 |
+ { |
239 |
+ # localhost token gets expanded at runtime to current external IP |
240 |
+ $dhost = 'localhost'; |
241 |
+ } |
242 |
+ return $dhost; |
243 |
+} |
244 |
+ |
245 |
+sub validate_source_port { |
246 |
+ my $q = shift; |
247 |
+ my $sport = $q->param('sport'); |
248 |
+ $sport =~ s/^\s+|\s+$//g; |
249 |
+ # If this is a port range, split it up and validate it individually. |
250 |
+ my @ports = (); |
251 |
+ if ($sport =~ /-/) |
252 |
+ { |
253 |
+ @ports = split /-/, $sport; |
254 |
+ if (@ports > 2) |
255 |
+ { |
256 |
+ #$self->debug_msg("found more than 2 ports: @ports"); |
257 |
+ return (ret=>'pf_ERR_BADPORT'); |
258 |
+ } |
259 |
+ } |
260 |
+ else |
261 |
+ { |
262 |
+ push @ports, $sport; |
263 |
+ } |
264 |
+ #$self->debug_msg("the ports array is: @ports"); |
265 |
+ foreach my $port (@ports) |
266 |
+ { |
267 |
+ #$self->debug_msg("looping on port $port"); |
268 |
+ if (! isValidPort($port)) |
269 |
+ { |
270 |
+ #$self->debug_msg("returning: " . $self->localise('ERR_BADPORT')); |
271 |
+ return (ret=>'pf_ERR_BADPORT'); |
272 |
+ } |
273 |
+ } |
274 |
+ # Now, lets screen any duplicates. |
275 |
+ my $protocol = $q->param('protocol'); |
276 |
+ my @forwards = (); |
277 |
+ |
278 |
+ # Grab the existing rules for this protocol. |
279 |
+ if ($protocol eq 'TCP') { |
280 |
+ @forwards = map { $_->key } $tcp_db->get_all; |
281 |
+ } elsif ($protocol eq 'UDP') { |
282 |
+ @forwards = map { $_->key } $udp_db->get_all; |
283 |
+ } |
284 |
+ foreach my $psport (@forwards) |
285 |
+ { |
286 |
+ if (detect_collision($sport, $psport)) |
287 |
+ { |
288 |
+ return (ret=>'pf_ERR_PORT_COLLISION'); |
289 |
+ } |
290 |
+ } |
291 |
+ return (ret=>"pf_SUCCESS"); |
292 |
+} |
293 |
+ |
294 |
+sub detect_collision |
295 |
+{ |
296 |
+ my $port_a = shift; |
297 |
+ my $port_b = shift; |
298 |
+ |
299 |
+ # If they're both single ports, see if they're the same. |
300 |
+ if (($port_a !~ /-/) && ($port_b !~ /-/)) |
301 |
+ { |
302 |
+ return $port_a eq $port_b; |
303 |
+ } |
304 |
+ # If port_a is not a range but port_b is, is a in b? |
305 |
+ elsif ($port_a !~ /-/) |
306 |
+ { |
307 |
+ my ($b1, $b2) = split /-/, $port_b; |
308 |
+ return (($port_a >= $b1) && ($port_a <= $b2)); |
309 |
+ } |
310 |
+ elsif ($port_b !~ /-/) |
311 |
+ { |
312 |
+ my ($a1, $a2) = split /-/, $port_a; |
313 |
+ return (($port_b >= $a1) && ($port_b <= $a2)); |
314 |
+ } |
315 |
+ else |
316 |
+ { |
317 |
+ # They're both ranges. Do they overlap? |
318 |
+ my ($a1, $a2) = split /-/, $port_a; |
319 |
+ my ($b1, $b2) = split /-/, $port_b; |
320 |
+ # They can overlap in two ways. Either a1 is in b, or b1 is in a. |
321 |
+ if (($a1 >= $b1) && ($a1 <= $b2)) |
322 |
+ { |
323 |
+ return TRUE; |
324 |
+ } |
325 |
+ elsif (($b1 >= $a1) && ($b1 <= $a2)) |
326 |
+ { |
327 |
+ return TRUE; |
328 |
+ } |
329 |
+ return FALSE; |
330 |
+ } |
331 |
+} |
332 |
+ |
333 |
+ |
334 |
+sub validate_destination_port { |
335 |
+ my $c = shift; |
336 |
+ my $dport = $c->param('dport'); |
337 |
+ $dport =~ s/^\s+|\s+$//g; |
338 |
+ # If the dport is empty, that's ok. |
339 |
+ return (ret=>'pf_SUCCESS') if not $dport; |
340 |
+ |
341 |
+ # If this is a port range, split it up and validate it individually. |
342 |
+ my @ports = (); |
343 |
+ if ($dport =~ /-/) |
344 |
+ { |
345 |
+ @ports = split /-/, $dport; |
346 |
+ if (@ports > 2) |
347 |
+ { |
348 |
+ #$self->debug_msg("found more than 2 ports: @ports"); |
349 |
+ return (ret=>'pf_ERR_BADPORT'); |
350 |
+ } |
351 |
+ } |
352 |
+ else |
353 |
+ { |
354 |
+ push @ports, $dport; |
355 |
+ } |
356 |
+ #$self->debug_msg("the ports array is: @ports"); |
357 |
+ |
358 |
+ foreach my $port (@ports) |
359 |
+ { |
360 |
+ #$self->debug_msg("looping on port $port"); |
361 |
+ if (! isValidPort($port)) |
362 |
+ { |
363 |
+ #$self->debug_msg("returning: " . $self->localise('ERR_BADPORT')); |
364 |
+ return (ret=>'pf_ERR_BADPORT'); |
365 |
+ } |
366 |
+ } |
367 |
+ return (ret=>'pf_SUCCESS'); |
368 |
+} |
369 |
+ |
370 |
+ |
371 |
+sub isValidPort() { |
372 |
+ my $port = shift; |
373 |
+ |
374 |
+ return FALSE unless defined $port; |
375 |
+ |
376 |
+ if (($port =~ /^\d+$/) && |
377 |
+ ($port > 0) && |
378 |
+ ($port < 65536)) |
379 |
+ { |
380 |
+ return TRUE; |
381 |
+ } |
382 |
+ else { |
383 |
+ return FALSE; |
384 |
+ } |
385 |
+} |
386 |
+ |
387 |
+sub validate_destination_host { |
388 |
+ my $c = shift; |
389 |
+ my $dhost = $c->param('dhost'); |
390 |
+ $dhost =~ s/^\s+|\s+$//g; |
391 |
+ |
392 |
+ my $localip = $db->get_prop('InternalInterface', 'IPAddress'); |
393 |
+ my $external_ip = $db->get_prop('ExternalInterface', 'IPAddress') || $localip; |
394 |
+ |
395 |
+ if ($dhost =~ /^(localhost|127.0.0.1|$localip|$external_ip)$/i) |
396 |
+ { |
397 |
+ # localhost token gets expanded at runtime to current external IP |
398 |
+ $c->param(-name=>'dhost', -value=>'localhost'); |
399 |
+ return (ret=>'pf_SUCCESS'); |
400 |
+ } |
401 |
+ |
402 |
+ my $systemmode = $db->get_value('SystemMode'); |
403 |
+ |
404 |
+ if ($systemmode eq 'serveronly') { |
405 |
+ return (ret=>'pf_IN_SERVERONLY'); |
406 |
+ } |
407 |
+ |
408 |
+ if (isValidIP($dhost)) { |
409 |
+ return (ret=>'pf_SUCCESS'); |
410 |
+ } |
411 |
+ else { |
412 |
+ return (ret=>'pf_ERR_BADIP'); |
413 |
+ } |
414 |
+} |
415 |
+ |
416 |
+sub validate_allowed_hosts { |
417 |
+ my $c = shift; |
418 |
+ my $ahost = $c->param('allow'); |
419 |
+ $ahost =~ s/^\s+|\s+$//g; |
420 |
+ |
421 |
+ my %valid_ahost_list = (ret=>"pf_SUCCESS"); |
422 |
+ |
423 |
+ foreach (split(/[\s,]+/, $ahost)) { |
424 |
+ my $valid_ipnet = 0; |
425 |
+ $valid_ipnet = 1 if ($_ =~ m/^\d+\.\d+\.\d+\.\d+$/); |
426 |
+ $valid_ipnet = 1 if ($_ =~ m/^\d+\.\d+\.\d+\.\d+\/\d+$/); |
427 |
+ %valid_ahost_list = (ret=>"pf_ERR_BADAHOST") if ($valid_ipnet != 1); |
428 |
+ } |
429 |
+ |
430 |
+ return %valid_ahost_list; |
431 |
+} |
432 |
+1; |
433 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/en.pm smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/en.pm |
434 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/en.pm 2020-04-07 07:05:11.686749826 +0100 |
435 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/lib/SrvMngr/I18N/en.pm 2020-04-07 09:29:08.436312695 +0100 |
436 |
@@ -1818,6 +1818,115 @@ |
437 |
handle this nonstandard subnet mask. The simpler specification |
438 |
<b>{$simpleMask}</b> will be used instead. |
439 |
</p>', |
440 |
+ |
441 |
+ 'pf_FORM_TITLE' => |
442 |
+ 'Configure Port Forwarding', |
443 |
+ 'pf_FIRST_PAGE_DESCRIPTION' => |
444 |
+ '<p> |
445 |
+ You can use this panel to modify your firewall rules so |
446 |
+ as to open a specific port on this server and forward it |
447 |
+ to another port on another host. Doing so will permit |
448 |
+ incoming traffic to directly access a private host on |
449 |
+ your LAN. |
450 |
+ </p> |
451 |
+ <p> |
452 |
+ WARNING: Misuse of this feature can seriously compromise the |
453 |
+ security of your network. Do not use this feature |
454 |
+ lightly, or without fully understanding the implications |
455 |
+ of your actions. |
456 |
+ </p> |
457 |
+ ', |
458 |
+ 'pf_CREATE_RULE' => |
459 |
+ 'Create portforwarding rule', |
460 |
+ 'pf_SUMMARY_ADD_DESC' => |
461 |
+ 'The following summarizes the port-forwarding rule |
462 |
+ that you are about to add. If you are satisfied with the rule, |
463 |
+ click the "Add" button. If you are not, click the |
464 |
+ "Cancel" button. |
465 |
+ ', |
466 |
+ 'pf_SUMMARY_REMOVE_DESC' => |
467 |
+ 'The following summarizes the port-forwarding rule |
468 |
+ that you are about to remove. If you are sure you want to |
469 |
+ remove the rule, click the "Remove" button. If not, |
470 |
+ click the "Cancel" button. |
471 |
+ ', |
472 |
+ 'pf_SHOW_FORWARDS' => |
473 |
+ ' |
474 |
+ Below you will find a table summarizing the current |
475 |
+ port-forwarding rules installed on this server. Click on the |
476 |
+ "Remove" link to remove the corresponding rule. |
477 |
+ ', |
478 |
+ 'pf_NO_FORWARDS' => |
479 |
+ 'There are currently no forwarded ports on the system.', |
480 |
+ 'pf_CREATE_PAGE_DESCRIPTION' => |
481 |
+ '<![CDATA[ |
482 |
+ <p>Select the protocol, the port you wish to forward, the |
483 |
+ destination host, and the port on the destination host |
484 |
+ that you wish to forward to. If you wish to specify a port |
485 |
+ range, enter the lower and upper boundaries separated by a |
486 |
+ hyphen. The destination port may be left blank, which will |
487 |
+ instruct the firewall to leave the source port |
488 |
+ unaltered.</p> |
489 |
+ ]]> |
490 |
+ ', |
491 |
+ 'pf_LABEL_SOURCE_PORT' => |
492 |
+ 'Source Port(s)', |
493 |
+ 'pf_LABEL_PROTOCOL' => |
494 |
+ 'Protocol', |
495 |
+ 'pf_LABEL_DESTINATION_PORT' => |
496 |
+ 'Destination Port(s)', |
497 |
+ 'pf_LABEL_DESTINATION_HOST' => |
498 |
+ 'Destination Host IP Address', |
499 |
+ 'pf_LABEL_RULE_COMMENT' => |
500 |
+ 'Rule Comment', |
501 |
+ 'pf_LABEL_ALLOW_HOSTS' => |
502 |
+ 'Allow Hosts', |
503 |
+ 'pf_Port forwarding' => |
504 |
+ 'Port forwarding', |
505 |
+ 'pf_SUCCESS' => |
506 |
+ 'Your change to the port forwarding rules has been |
507 |
+ successfully saved. |
508 |
+ ', |
509 |
+ 'pf_RULE_COMMENT' => |
510 |
+ 'Rule Comment', |
511 |
+ 'pf_ALLOW_HOSTS' => |
512 |
+ 'Allow Hosts', |
513 |
+ 'pf_ERR_NO_MASQ_RECORD' => |
514 |
+ 'Cannot retrieve masq record from the configuration |
515 |
+ database.', |
516 |
+ 'pf_ERR_UNSUPPORTED_MODE' => |
517 |
+ 'Unsupported mode.', |
518 |
+ 'pf_ERR_CANNOT_REMOVE_NORULE' => |
519 |
+ 'Cannot remove non-existant rule.', |
520 |
+ 'pf_ERR_NONZERO_RETURN_EVENT' => |
521 |
+ 'Event returned a non-zero return value.', |
522 |
+ 'pf_ERR_BADPORT' => |
523 |
+ 'The ports must be a positive integer less than |
524 |
+ 65536.', |
525 |
+ 'pf_ERR_BADIP' => |
526 |
+ 'This does not appear to be an IP address. You must use |
527 |
+ dotted-quad notation, and each of the four numbers should be less |
528 |
+ than 256. ie: 192.168.0.5', |
529 |
+ 'pf_ERR_DUPRULE' => |
530 |
+ 'This rule has already been added, it cannot be added |
531 |
+ twice.', |
532 |
+ 'pf_ERR_PORT_COLLISION' => |
533 |
+ ' |
534 |
+ ERROR: This port or port range conflicts with an existing |
535 |
+ rule. Please modify this new rule, or remove the old rule. |
536 |
+ ', |
537 |
+ 'pf_ERR_BADAHOST' => |
538 |
+ ' |
539 |
+ This does not appear to be a valid IP address list. |
540 |
+ ie: 192.168.0.1,192.168.1.1/24 |
541 |
+ ', |
542 |
+ 'pf_IN_SERVERONLY' => |
543 |
+ ' |
544 |
+ This server is currently in serveronly mode and portforwarding |
545 |
+ is possible only to localhost. |
546 |
+ ', |
547 |
+ |
548 |
+ |
549 |
|
550 |
); |
551 |
|
552 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/script/srvmngr.pl smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/script/srvmngr.pl |
553 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/script/srvmngr.pl 2020-04-07 07:05:11.930752095 +0100 |
554 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/script/srvmngr.pl 2020-04-07 09:30:58.028331856 +0100 |
555 |
@@ -114,6 +114,16 @@ |
556 |
$r->post('/localnetworksdel1')->to('localnetworks#do_display')->name('localnetworksdel1'); |
557 |
$r->get('/localnetworksdel1')->to('localnetworks#do_display')->name('localnetworksdel1'); |
558 |
|
559 |
+$r->get('/portforwarding')->to('portforwarding#main')->name('portforwarding'); |
560 |
+$r->post('/portforwarding')->to('portforwarding#do_display')->name('portforwarding'); |
561 |
+$r->post('/portforwardingdel')->to('portforwarding#do_display')->name('portforwardingdel'); |
562 |
+$r->post('/portforwardingadd')->to('portforwarding#do_display')->name('portforwardingadd'); |
563 |
+$r->post('/portforwardingadd1')->to('portforwarding#do_display')->name('portforwardingadd1'); |
564 |
+$r->get('/portforwardingadd1')->to('portforwarding#do_display')->name('portforwardingadd1'); |
565 |
+$r->get('/portforwardingdel')->to('portforwarding#do_display')->name('portforwardingdel'); |
566 |
+$r->post('/portforwardingdel1')->to('portforwarding#do_display')->name('portforwardingdel1'); |
567 |
+$r->get('/portforwardingdel1')->to('portforwarding#do_display')->name('portforwardingdel1'); |
568 |
+ |
569 |
$r->get('/printers')->to('printers#main')->name('printers'); |
570 |
$r->post('/printers')->to('printers#do_display')->name('printeradd'); |
571 |
$r->get('/printers2')->to('printers#do_update')->name('printernet'); |
572 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_ln_list.html.ep smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_ln_list.html.ep |
573 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_ln_list.html.ep 2020-04-07 07:05:13.512766806 +0100 |
574 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_ln_list.html.ep 2020-04-07 06:45:00.000000000 +0100 |
575 |
@@ -50,7 +50,7 @@ |
576 |
%=l 'NETWORK' |
577 |
</th> |
578 |
<th class='sme-border'> |
579 |
- %=l 'SUBNET_MASK' |
580 |
+ %=l 'ln_SUBNET_MASK' |
581 |
</th> |
582 |
|
583 |
<th class='sme-border'> |
584 |
@@ -78,7 +78,8 @@ |
585 |
%= t td => (class => 'sme-border') => $num_hosts |
586 |
%= t td => (class => 'sme-border') => $localnetwork->prop('Router') |
587 |
% if ($removable eq "yes") { |
588 |
- <td class='sme-border'><a href="/server-manager2/localnetworksdel?trt=DEL&localnetwork=<%= $localnetwork->key%>"><%=l 'REMOVE'%></a></td> |
589 |
+ <td class='sme-border'> |
590 |
+ <a href="/server-manager2/localnetworksdel?trt=DEL&localnetwork=<%= $localnetwork->key%>"><%=l 'REMOVE'%></a></td> |
591 |
% } else { |
592 |
<td class='sme-border'> </td> |
593 |
%} |
594 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_add.html.ep smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_add.html.ep |
595 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_add.html.ep 1970-01-01 01:00:00.000000000 +0100 |
596 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_add.html.ep 2020-04-06 07:01:00.000000000 +0100 |
597 |
@@ -0,0 +1,83 @@ |
598 |
+<div id='pf_add'> |
599 |
+ |
600 |
+ % my $retref= $c->stash("ret"); |
601 |
+ % my %ret; |
602 |
+ % unless (length($retref)) {%ret = (ret=>"");} |
603 |
+ % else {%ret = %$retref;} |
604 |
+ |
605 |
+ % my @vars = split(",",$ret{vars}); |
606 |
+ % my $var1 = @vars[0]; |
607 |
+ % my $var2 = @vars[1]; |
608 |
+ % my $var3 = @vars[2]; |
609 |
+ % my $var4 = @vars[3]; |
610 |
+ % my $var5 = @vars[4]; |
611 |
+ % my $var6 = @vars[5]; |
612 |
+ |
613 |
+ %if ($ret{'ret'} eq "") { |
614 |
+ |
615 |
+ %} elsif (index($ret{ret},"SUCCESS") != -1) { |
616 |
+ <div class='success'> |
617 |
+ <h2> Operation Status Report</h2> |
618 |
+ %= $c->l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6); |
619 |
+ </div> |
620 |
+ %} else { |
621 |
+ <div class='sme-error'> |
622 |
+ <h2> Operation Status Report - Error</h2> |
623 |
+ %= $c->l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6); |
624 |
+ </div> |
625 |
+ %} |
626 |
+ <br /> |
627 |
+ % my $btn = l('ADD'); |
628 |
+ |
629 |
+ % if ($config->{debug} == 1) { |
630 |
+ <p> |
631 |
+ %= dumper $c->current_route |
632 |
+ %= dumper $c->stash("ret") |
633 |
+ </p> |
634 |
+ % } |
635 |
+ |
636 |
+ %= form_for '/portforwardingadd1' => (method => 'POST') => begin |
637 |
+ <h2> |
638 |
+ %=l "pf_CREATE_RULE" |
639 |
+ </h2> |
640 |
+ <p> |
641 |
+ %=l "pf_SUMMARY_ADD_DESC" |
642 |
+ </p><br> |
643 |
+ <span class=label> |
644 |
+ %=l "pf_LABEL_PROTOCOL" |
645 |
+ </span><span class=data> |
646 |
+ %=select_field 'proto'=>["TCP","UDP"] |
647 |
+ </span><br><br> |
648 |
+ <span class=label> |
649 |
+ %=l "pf_LABEL_SOURCE_PORT" |
650 |
+ </span><span class=data> |
651 |
+ %=text_field 'sport' |
652 |
+ </span><br><br> |
653 |
+ <span class=label> |
654 |
+ %=l "pf_LABEL_DESTINATION_PORT" |
655 |
+ </span> |
656 |
+ <span class=data> |
657 |
+ %=text_field 'dport' |
658 |
+ </span><br><br> |
659 |
+ <span class=label> |
660 |
+ %=l "pf_LABEL_DESTINATION_HOST" |
661 |
+ </span> |
662 |
+ <span class=data> |
663 |
+ %=text_field 'dhost' |
664 |
+ </span><br><br> |
665 |
+ <span class=label> |
666 |
+ %=l "pf_ALLOW_HOSTS" |
667 |
+ </span> |
668 |
+ <span class=data> |
669 |
+ %=text_field 'allow' |
670 |
+ </span><br><br> |
671 |
+ <span class=label> |
672 |
+ %=l "pf_RULE_COMMENT" |
673 |
+ </span> |
674 |
+ <span class=data> |
675 |
+ %=text_field 'cmmnt' |
676 |
+ </span><br><br> |
677 |
+ %= submit_button "$btn", class => 'action' |
678 |
+ %end |
679 |
+ |
680 |
+</div> |
681 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_del.html.ep smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_del.html.ep |
682 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_del.html.ep 1970-01-01 01:00:00.000000000 +0100 |
683 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_del.html.ep 2020-04-06 06:25:00.000000000 +0100 |
684 |
@@ -0,0 +1,63 @@ |
685 |
+<div id='ln_del'> |
686 |
+ |
687 |
+ % my $btn = l('REMOVE'); |
688 |
+ % my $proto = $pf_datas->{proto}; |
689 |
+ % my $sport = $pf_datas->{sport}; |
690 |
+ % my $dport = $pf_datas->{dport}; |
691 |
+ % my $dhost = $pf_datas->{dhost}; |
692 |
+ % my $cmmnt = $pf_datas->{cmmnt}; |
693 |
+ % my $allow = $pf_datas->{allow}; |
694 |
+ |
695 |
+ % if ($config->{debug} == 1) { |
696 |
+ <p> |
697 |
+ %= dumper $c->current_route |
698 |
+ %= dumper $c->stash("ret") |
699 |
+ %= dumper %$pf_datas |
700 |
+ </p> |
701 |
+ % } |
702 |
+ |
703 |
+ %= form_for '/portforwardingdel1' => (method => 'POST') => begin |
704 |
+ <br> |
705 |
+ %= l "pf_SUMMARY_REMOVE_DESC" |
706 |
+ </p><br> |
707 |
+ <span class=label> |
708 |
+ %=l "pf_LABEL_PROTOCOL" |
709 |
+ </span><span class=data> |
710 |
+ %=$proto |
711 |
+ </span><br><br> |
712 |
+ <span class=label> |
713 |
+ %=l "pf_LABEL_SOURCE_PORT" |
714 |
+ </span><span class=data> |
715 |
+ %=$sport |
716 |
+ </span><br><br> |
717 |
+ <span class=label> |
718 |
+ %=l "pf_LABEL_DESTINATION_HOST" |
719 |
+ </span> |
720 |
+ <span class=data> |
721 |
+ %=$dport |
722 |
+ </span><br><br> |
723 |
+ <span class=label> |
724 |
+ %=l "pf_LABEL_DESTINATION_PORT" |
725 |
+ </span> |
726 |
+ <span class=data> |
727 |
+ %=$dhost |
728 |
+ </span><br><br> |
729 |
+ <span class=label> |
730 |
+ %=l "pf_RULE_COMMENT" |
731 |
+ </span> |
732 |
+ <span class=data> |
733 |
+ %=$cmmnt |
734 |
+ </span><br><br> |
735 |
+ <span class=label> |
736 |
+ %=l "pf_ALLOW_HOSTS" |
737 |
+ </span> |
738 |
+ <span class=data> |
739 |
+ %=$allow |
740 |
+ </span><br><br> |
741 |
+ %#} |
742 |
+ %= hidden_field sport=>$sport |
743 |
+ %= hidden_field proto=>$proto |
744 |
+ %= submit_button "$btn", class => 'action' |
745 |
+ %end |
746 |
+ |
747 |
+</div> |
748 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_list.html.ep smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_list.html.ep |
749 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_list.html.ep 1970-01-01 01:00:00.000000000 +0100 |
750 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/partials/_pf_list.html.ep 2020-04-06 07:35:00.000000000 +0100 |
751 |
@@ -0,0 +1,107 @@ |
752 |
+<div id='pf_list'> |
753 |
+ % my $btn = l('pf_CREATE_RULE'); |
754 |
+ %= form_for '/portforwardingadd' => (method => 'POST') => begin |
755 |
+ |
756 |
+ % my $retref= $c->stash("ret"); |
757 |
+ % my %ret; |
758 |
+ % unless (length($retref)) {%ret = (ret=>"");} |
759 |
+ % else {%ret = %$retref;} |
760 |
+ |
761 |
+ % my $numtcpforwards = @$tcpforwards; |
762 |
+ % my $numudpforwards = @$udpforwards; |
763 |
+ |
764 |
+ % my @vars = split(",",$ret{vars}); |
765 |
+ % my $var1 = @vars[0]; |
766 |
+ % my $var2 = @vars[1]; |
767 |
+ % my $var3 = @vars[2]; |
768 |
+ % my $var4 = @vars[3]; |
769 |
+ % my $var5 = @vars[4]; |
770 |
+ % my $var6 = @vars[5]; |
771 |
+ |
772 |
+ |
773 |
+ |
774 |
+ %if ($ret{ret} eq "") { |
775 |
+ %=l "pf_FIRST_PAGE_DESCRIPTION" |
776 |
+ %} elsif (index($ret{ret},"SUCCESS") != -1) { |
777 |
+ <div class='success'> |
778 |
+ <h2> Operation Status Report</h2> |
779 |
+ %= $c->l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6); |
780 |
+ </div> |
781 |
+ %} else { |
782 |
+ <div class='sme-error'> |
783 |
+ <h2> Operation Status Report - Error</h2> |
784 |
+ %= $c->l($ret{ret},$var1,$var2,$var3,$var4,$var5,$var6); |
785 |
+ </div> |
786 |
+ %} |
787 |
+ <br><br> |
788 |
+ %= submit_button "$btn", class => 'action' |
789 |
+ <br> |
790 |
+ |
791 |
+ % if ($empty){ |
792 |
+ <br> |
793 |
+ %=l 'pf_NO_FORWARDS' |
794 |
+ % } else { |
795 |
+ <br> |
796 |
+ <table class="sme-border"><tbody> |
797 |
+ <tr> |
798 |
+ <th class='sme-border'> |
799 |
+ %=l 'pf_LABEL_PROTOCOL' |
800 |
+ </th> |
801 |
+ <th class='sme-border'> |
802 |
+ %=l 'pf_LABEL_SOURCE_PORT' |
803 |
+ </th> |
804 |
+ |
805 |
+ <th class='sme-border'> |
806 |
+ %=l 'pf_LABEL_DESTINATION_HOST' |
807 |
+ </th> |
808 |
+ |
809 |
+ <th class='sme-border'> |
810 |
+ %=l 'pf_LABEL_DESTINATION_PORT' |
811 |
+ </th> |
812 |
+ |
813 |
+ <th class='sme-border'> |
814 |
+ %=l 'pf_ALLOW_HOSTS' |
815 |
+ </th> |
816 |
+ |
817 |
+ |
818 |
+ <th class='sme-border'> |
819 |
+ %=l 'pf_RULE_COMMENT' |
820 |
+ </th> |
821 |
+ |
822 |
+ <th class='sme-border' '> |
823 |
+ %=l 'ACTION' |
824 |
+ </th> |
825 |
+ </tr> |
826 |
+ |
827 |
+ % my %forwards = (); |
828 |
+ % $forwards{TCP} = $tcpforwards; |
829 |
+ % $forwards{UDP} = $udpforwards; |
830 |
+ |
831 |
+ % foreach my $proto (sort keys %forwards) { |
832 |
+ |
833 |
+ % if (@{ $forwards{$proto} }) { |
834 |
+ % foreach my $entry (@{ $forwards{$proto} }) { |
835 |
+ <tr> |
836 |
+ % my $sport = $entry->key; |
837 |
+ % my $dhost = $entry->prop('DestHost'); |
838 |
+ % my $dport = $entry->prop('DestPort') || ''; |
839 |
+ % my $cmmnt = $entry->prop('Comment') || ''; |
840 |
+ % my $allow = $entry->prop('AllowHosts') || ''; |
841 |
+ %= t td => (class => 'sme-border') => $proto |
842 |
+ %= t td => (class => 'sme-border') => $sport |
843 |
+ %= t td => (class => 'sme-border') => $dhost |
844 |
+ %= t td => (class => 'sme-border') => $dport |
845 |
+ %= t td => (class => 'sme-border') => $allow |
846 |
+ %= t td => (class => 'sme-border') => $cmmnt |
847 |
+ <td class='sme-border'> |
848 |
+ <a href="/server-manager2/portforwardingdel?trt=DEL&sport=<%= $sport%>&proto=<%= $proto%>"><%=l 'REMOVE'%></a></td> |
849 |
+ </tr> |
850 |
+ % } |
851 |
+ % } |
852 |
+ %} |
853 |
+ %= hidden_field 'trt' => $pf_datas->{trt} |
854 |
+ %} |
855 |
+ </tbody> |
856 |
+ </table> |
857 |
+ % end |
858 |
+</div> |
859 |
diff -urN smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/portforwarding.html.ep smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/portforwarding.html.ep |
860 |
--- smeserver-manager-0.1.0.old/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/portforwarding.html.ep 1970-01-01 01:00:00.000000000 +0100 |
861 |
+++ smeserver-manager-0.1.0/root/etc/e-smith/web/panels/manager2/cgi-bin/srvmngr/themes/default/templates/portforwarding.html.ep 2020-04-05 14:15:00.000000000 +0100 |
862 |
@@ -0,0 +1,32 @@ |
863 |
+% layout 'default', title => "Sme server 2 - Port Forwards", share_dir => './'; |
864 |
+ |
865 |
+% content_for 'module' => begin |
866 |
+<div id="module"> |
867 |
+ |
868 |
+ % if ($config->{debug} == 1) { |
869 |
+ <p> |
870 |
+ %= dumper "<pf>".$c->current_route |
871 |
+ %= dumper $c->stash("ret") |
872 |
+ %= dumper $c->stash("portforwarding") |
873 |
+ % my $ref = $pf_datas->{portforwarding}; |
874 |
+ %= dumper $ref->{TCP}->[0]."</pf>" |
875 |
+ </p> |
876 |
+ % } |
877 |
+ |
878 |
+ <h1><%= $title%></h1> |
879 |
+ %= $modul |
880 |
+ |
881 |
+ % if ($pf_datas->{trt} eq 'ADD') { |
882 |
+ %= include 'partials/_pf_add' |
883 |
+ %} elsif ($pf_datas->{trt} eq 'ADD1') { |
884 |
+ %= include 'partials/_pf_add' |
885 |
+ %} elsif ($pf_datas->{trt} eq 'DEL') { |
886 |
+ %= include 'partials/_pf_del' |
887 |
+ %} elsif ($pf_datas->{trt} eq 'DEL1'){ |
888 |
+ %= include 'partials/_pf_list' |
889 |
+ %} else { |
890 |
+ %= include 'partials/_pf_list' |
891 |
+ %} |
892 |
+ |
893 |
+</div> |
894 |
+%end |