#!/usr/local/bin/perl
# edit_ports.cgi
# A form for editing ports and other networking options

require './squid-lib.pl';
$access{'portsnets'} || &error($text{'eports_ecannot'});
&header($text{'eports_header'}, "", "edit_ports", 0, 0, 0, &restart_button());
print "<hr>\n";
$conf = &get_config();

print "<form action=save_ports.cgi>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'eports_pano'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";

print "<tr>\n";
if ($squid_version >= 2.3) {
	# Display table of normal ports
	foreach $p (&find_config('http_port', $conf)) {
		push(@ports, @{$p->{'values'}});
		}
	print "<td valign=top><b>$text{'eports_paap'}</b></td><td colspan=3>\n";
	printf "<input type=radio name=ports_def value=1 %s> %s\n",
		@ports ? "" : "checked", $text{'eports_def'};
	printf "<input type=radio name=ports_def value=0 %s> %s<br>\n",
		@ports ? "checked" : "", $text{'eports_sel'};
	print "<table border>\n";
	print "<tr $tb> <td><b>$text{'eports_p'}</b></td>\n",
	      "<td><b>$text{'eports_hia'}</b></td> </tr>\n";
	$i = 0;
	foreach $p (@ports, '') {
		print "<tr $cb>\n";
		printf "<td><input name=port_$i size=6 value='%s'></td> <td>\n",
			$p =~ /(\d+)$/ ? $1 : '';
		printf "<input type=radio name=addr_def_$i value=1 %s> All\n",
			$p =~ /:/ ? '' : 'checked';
		printf "<input type=radio name=addr_def_$i value=0 %s>\n",
			$p =~ /:/ ? 'checked' : '';
		printf "<input name=addr_$i size=20 value='%s'></td>\n",
			$p =~ /^(\S+):/ ? $1 : '';
		print "</tr>\n";
		$i++;
		}

	print "</table></td></tr>\n";
	if ($squid_version >= 2.5) {
		# Display table of SSL ports
		# XXX not done yet
		}
	print "<tr>\n";
	print &opt_input($text{'eports_ip'}, "icp_port", 
				$conf, $text{'default'}, 6);
	}
else {
	print &opt_input($text{'eports_pp'}, "http_port", 
				$conf, $text{'default'}, 6);
	print &opt_input($text{'eports_ip'}, "icp_port", 
				$conf, $text{'default'}, 6);
	print "</tr>\n";

	print "<tr>\n";
	print &opt_input($text{'eports_ita'}, "tcp_incoming_address",
			 $conf, $text{'eports_a'}, 15);
	}

print &opt_input($text{'eports_ota'}, "tcp_outgoing_address",
		 $conf, $text{'eports_a'}, 15);
print "</tr>\n";

print "<tr>\n";
print &opt_input($text{'eports_oua'}, "udp_outgoing_address",
		 $conf, $text{'eports_a'}, 15);
print &opt_input($text{'eports_iua'}, "udp_incoming_address",
		 $conf, $text{'eports_a'}, 15);
print "</tr>\n";

print "<tr>\n";
print &address_input($text{'eports_mg'}, "mcast_groups", $conf, 0);
print &opt_input($text{'eports_trb'}, "tcp_recv_bufsize", $conf,
		 $text{'eports_od'}, 6);
print "</tr>\n";

if ($squid_version >= 2.5) {
	print "<tr>\n";
	print &choice_input($text{'eports_unc'}, "ssl_unclean_shutdown",
			    $conf, "off", $text{'on'},"on", $text{'off'},"off");
	print "</tr>\n";
	}

print "</table></td></tr></table>\n";
print "<input type=submit value=$text{'buttsave'}></form>\n";

print "<hr>\n";
&footer("", $text{'eports_return'});

