[ Avaa Bypassed ]




Upload:

Command:

www-data@3.144.134.101: ~ $
# Networking functions for Ubuntu 17+, which uses Netplan by default

$netplan_dir = "/etc/netplan";
$sysctl_config = "/etc/sysctl.conf";

do 'linux-lib.pl';

# boot_interfaces()
# Returns a list of all interfaces activated at boot time
sub boot_interfaces
{
my @rv;
foreach my $f (glob("$netplan_dir/*.yaml")) {
	my $yaml = &read_yaml_file($f);
	next if (!$yaml || !@$yaml);
	my ($network) = grep { $_->{'name'} eq 'network' } @$yaml;
	next if (!$network);
	my ($ens) = grep { $_->{'name'} eq 'ethernets' }
			 @{$network->{'members'}};
	next if (!$ens);
	foreach my $e (@{$ens->{'members'}}) {
		my $cfg = { 'name' => $e->{'name'},
			    'fullname' => $e->{'name'},
			    'file' => $f,
			    'yaml' => $e,
			    'line' => $e->{'line'},
			    'eline' => $e->{'eline'},
			    'edit' => 1,
			    'up' => 1 };

		# Is DHCP enabled?
		my ($dhcp) = grep { $_->{'name'} eq 'dhcp4' }
				  @{$e->{'members'}};
		if (&is_true_value($dhcp)) {
			$cfg->{'dhcp'} = 1;
			}
		my ($dhcp6) = grep { $_->{'name'} eq 'dhcp6' }
				  @{$e->{'members'}};
		if (&is_true_value($dhcp6)) {
			$cfg->{'dhcp6'} = 1;
			}

		# Is optional at boot?
		my ($optional) = grep { $_->{'name'} eq 'optional' }
				      @{$e->{'members'}};
		if (&is_true_value($optional)) {
			$cfg->{'up'} = 0;
			}

		# IPv4 and v6 addresses
		my ($addresses) = grep { $_->{'name'} eq 'addresses' }
				       @{$e->{'members'}};
		my @addrs;
		my @addrs6;
		if ($addresses) {
			foreach my $v (@{$addresses->{'value'}}) {
				my ($a) = split(/\//, $v);
				if (&check_ip6address($a)) {
					push(@addrs6, $v);
					}
				elsif (&check_ipaddress($a)) {
					push(@addrs, $v);
					}
				}
			if (!$cfg->{'dhcp'}) {
				my $a = shift(@addrs);
				($cfg->{'address'}, $cfg->{'netmask'}) =
					&split_addr_netmask($a);
				}
			}
		foreach my $a6 (@addrs6) {
			if ($a6 =~ /^(\S+)\/(\d+)$/) {
				push(@{$cfg->{'address6'}}, $1);
				push(@{$cfg->{'netmask6'}}, $2);
				}
			else {
				push(@{$cfg->{'address6'}}, $a6);
				push(@{$cfg->{'netmask6'}}, 64);
				}
			}

		# IPv4 and v4 gateways
		my ($gateway4) = grep { $_->{'name'} eq 'gateway4' }
				      @{$e->{'members'}};
		if ($gateway4) {
			$cfg->{'gateway'} = $gateway4->{'value'};
			}
		my ($gateway6) = grep { $_->{'name'} eq 'gateway6' }
				      @{$e->{'members'}};
		if ($gateway6) {
			$cfg->{'gateway6'} = $gateway6->{'value'};
			}
		$cfg->{'index'} = scalar(@rv);
		push(@rv, $cfg);

		# Nameservers (which are used to generate resolv.conf)
		my ($nameservers) = grep { $_->{'name'} eq 'nameservers' }
                                         @{$e->{'members'}};
		if ($nameservers) {
			my ($nsa) = grep { $_->{'name'} eq 'addresses' }
					 @{$nameservers->{'members'}};
			my ($search) = grep { $_->{'name'} eq 'search' }
					 @{$nameservers->{'members'}};
			if ($nsa && @{$nsa->{'value'}}) {
				$cfg->{'nameserver'} = $nsa->{'value'};
				}
			if ($search && @{$search->{'value'}}) {
				$cfg->{'search'} = $search->{'value'};
				}
			}

		# MAC address
		my ($macaddress) = grep { $_->{'name'} eq 'macaddress' }
                                         @{$e->{'members'}};
		if ($macaddress) {
			$cfg->{'ether'} = $macaddress->{'value'};
			}

		# Static routes
		my ($routes) = grep { $_->{'name'} eq 'routes' }
                                    @{$e->{'members'}};
		if ($routes) {
			$cfg->{'routes'} = $routes;
			}

		# Add IPv4 alias interfaces
		my $i = 0;
		foreach my $aa (@addrs) {
			my $acfg = { 'name' => $cfg->{'name'},
				     'virtual' => $i,
				     'fullname' => $cfg->{'name'}.":".$i,
				     'file' => $f,
				     'edit' => 1,
				     'up' => 1, };
			($acfg->{'address'}, $acfg->{'netmask'}) =
				&split_addr_netmask($aa);
			$acfg->{'index'} = scalar(@rv);
			push(@rv, $acfg);
			$i++;
			}
		}
	}
return @rv;
}

# save_interface(&details, [&all-interfaces])
# Create or update a boot-time interface
sub save_interface
{
my ($iface, $boot) = @_;
$boot ||= [ &boot_interfaces() ];
if ($iface->{'virtual'} ne '') {
	# Find the parent config entry
	my ($parent) = grep { $_->{'fullname'} eq $iface->{'name'} } @$boot;
	$parent || &error("No interface named $iface->{'name'} exists");
	if (!$iface->{'file'}) {
		# Add to complete interface list
		push(@$boot, $iface);
		}
	else {
		# Update in complete list
		my ($oldiface) = grep { $_->{'fullname'} eq
					$iface->{'fullname'} } @$boot;
		$oldiface || &error("No existing interface named $iface->{'fullname'} found");
		$boot->[$oldiface->{'index'}] = $iface;
		}
	&save_interface($parent, $boot);
	}
else {
	# Build interface config lines
	my $id = " " x 8;
	my @lines;
	push(@lines, $id.$iface->{'fullname'}.":");
	my @addrs;
	if (!$iface->{'up'}) {
		push(@lines, $id."    "."optional: true");
		}
	if ($iface->{'dhcp'}) {
		push(@lines, $id."    "."dhcp4: true");
		}
	else {
		push(@addrs, $iface->{'address'}."/".
			     &mask_to_prefix($iface->{'netmask'}));
		}
	if ($iface->{'dhcp6'}) {
		push(@lines, $id."    "."dhcp6: true");
		}
	for(my $i=0; $i<@{$iface->{'address6'}}; $i++) {
		push(@addrs, $iface->{'address6'}->[$i]."/".
			     $iface->{'netmask6'}->[$i]);
		}
	foreach my $a (@$boot) {
		if ($a->{'virtual'} ne '' && $a->{'name'} eq $iface->{'name'}) {
			push(@addrs, $a->{'address'}."/".
				     &mask_to_prefix($a->{'netmask'}));
			}
		}
	if (@addrs) {
		push(@lines, $id."    "."addresses: [".
				&join_addr_list(@addrs)."]");
		}
	if ($iface->{'gateway'}) {
		push(@lines, $id."    "."gateway4: ".$iface->{'gateway'});
		}
	if ($iface->{'gateway6'}) {
		push(@lines, $id."    "."gateway6: ".$iface->{'gateway6'});
		}
	if ($iface->{'nameserver'}) {
		push(@lines, $id."    "."nameservers:");
		push(@lines, $id."        "."addresses: [".
			     &join_addr_list(@{$iface->{'nameserver'}})."]");
		if ($iface->{'search'}) {
			push(@lines, $id."        "."search: [".
			     &join_addr_list(@{$iface->{'search'}})."]");
			}
		}
	if ($iface->{'ether'}) {
		push(@lines, $id."    "."macaddress: ".$iface->{'ether'});
		}
	if ($iface->{'routes'}) {
		push(@lines, &yaml_lines($iface->{'routes'}, $id."    "));
		}

	# Add all extra YAML directives from the original config
	my @poss = ("optional", "dhcp4", "dhcp6", "addresses", "gateway4",
		    "gateway6", "nameservers", "macaddress", "routes");
	if ($iface->{'yaml'}) {
		foreach my $y (@{$iface->{'yaml'}->{'members'}}) {
			next if (&indexof($y->{'name'}, @poss) >= 0);
			push(@lines, &yaml_lines($y, $id."    "));
			}
		}

	if ($iface->{'file'}) {
		# Replacing an existing interface
		my ($old) = grep { $_->{'fullname'} eq $iface->{'fullname'} } @$boot;
		$old || &error("No interface named $iface->{'fullname'} found");
		&lock_file($old->{'file'});
		my $lref = &read_file_lines($old->{'file'});
		splice(@$lref, $old->{'line'},
		       $old->{'eline'} - $old->{'line'} + 1, @lines);
		&flush_file_lines($old->{'file'});
		&unlock_file($old->{'file'});
		}
	else {
		# Adding a new one (possibly to it's own file)
		$iface->{'file'} = $netplan_dir."/".$iface->{'name'}.".yaml";
		&lock_file($iface->{'file'});
		my $lref = &read_file_lines($iface->{'file'});
		my $nline = -1;
		my $eline = -1;
		for(my $i=0; $i<@$lref; $i++) {
			$nline = $i if ($lref->[$i] =~ /^\s*network:/);
			$eline = $i if ($lref->[$i] =~ /^\s*ethernets:/);
			}
		if ($nline < 0) {
			$nline = scalar(@$lref);
			push(@$lref, "network:");
			}
		if ($eline < 0) {
			$eline = $nline + 1;
			splice(@$lref, $nline+1, 0, "    ethernets:");
			}
		splice(@$lref, $eline+1, 0, @lines);
		&flush_file_lines($iface->{'file'});
		&unlock_file($iface->{'file'});
		}
	}
}

# delete_interface(&details)
# Remove a boot-time interface
sub delete_interface
{
my ($iface) = @_;
if ($iface->{'virtual'} ne '') {
	# Just remove the virtual address
	my $boot = [ &boot_interfaces() ];
	my ($parent) = grep { $_->{'fullname'} eq $iface->{'name'} } @$boot;
	$parent || &error("No interface named $iface->{'name'} exists");
	$boot = [ grep { $_->{'fullname'} ne $iface->{'fullname'} } @$boot ];
	&save_interface($parent, $boot);
	}
else {
	# Delete all the lines
	&lock_file($iface->{'file'});
	my $lref = &read_file_lines($iface->{'file'});
	splice(@$lref, $iface->{'line'},
	       $iface->{'eline'} - $iface->{'line'} + 1);
	&flush_file_lines($iface->{'file'});
	if (&is_yaml_empty($iface->{'file'})) {
		&unlink_file($iface->{'file'});
		}
	&unlock_file($iface->{'file'});
	}
}

# is_yaml_empty(file)
# Return 1 if a YAML file contains only network and ethernets line, with no
# other interfaces
sub is_yaml_empty
{
my ($file) = @_;
my $yaml = &read_yaml_file($file);
return 1 if (!$yaml);
my @rest = grep { $_->{'name'} ne 'network' } @$yaml;
return 0 if (@rest);
foreach my $n (@$yaml) {
	my @rest = grep { $_->{'name'} ne 'ethernets' }
			@{$network->{'members'}};
	return 0 if (@rest);
	foreach my $ens (@{$network->{'members'}}) {
		return 0 if (@{$ens->{'members'}});
		}
	}
return 1;
}

sub supports_bonding
{
return 0;	# XXX fix later
}

sub supports_vlans
{
return 0;	# XXX fix later
}

sub boot_iface_hardware
{
return $_[0] =~ /^(eth|em)/;
}

# supports_address6([&iface])
# Returns 1 if managing IPv6 interfaces is supported
sub supports_address6
{
my ($iface) = @_;
return !$iface || $iface->{'virtual'} eq '';
}

# Returns 1, as boot-time interfaces on Debian can exist without an IP (such as
# for bridging)
sub supports_no_address
{
return 1;
}

# Bridge interfaces can be created on debian
sub supports_bridges
{
return 0;	# XXX fix later
}

# can_edit(what)
# Can some boot-time interface parameter be edited?
sub can_edit
{
my ($f) = @_;
return $f ne "mtu";
}

sub can_broadcast_def
{
return 0;
}

# valid_boot_address(address)
# Is some address valid for a bootup interface
sub valid_boot_address
{
return &check_ipaddress_any($_[0]);
}

# get_hostname()
sub get_hostname
{
my $hn = &read_file_contents("/etc/hostname");
$hn =~ s/\r|\n//g;
if ($hn) {
	return $hn;
	}
return &get_system_hostname();
}

# save_hostname(name)
sub save_hostname
{
my ($hostname) = @_;
&system_logged("hostname ".quotemeta($hostname)." >/dev/null 2>&1");
foreach my $f ("/etc/hostname", "/etc/HOSTNAME", "/etc/mailname") {
	if (-r $f) {
		&open_lock_tempfile(HOST, ">$f");
		&print_tempfile(HOST, $hostname,"\n");
		&close_tempfile(HOST);
		}
	}

# Use the hostnamectl command as well
if (&has_command("hostnamectl")) {
	&system_logged("hostnamectl set-hostname ".quotemeta($hostname).
		       " >/dev/null 2>&1");
	}

undef(@main::get_system_hostname);      # clear cache
}

# get_domainname()
sub get_domainname
{
my $d;
&execute_command("domainname", undef, \$d, undef);
chop($d);
return $d;
}

# save_domainname(domain)
sub save_domainname
{
my ($domain) = @_;
&execute_command("domainname ".quotemeta($domain));
}

sub routing_config_files
{
return ( $netplan_dir, $sysctl_config );
}

# routing_input()
# show default router and device
sub routing_input
{
my ($addr, $router) = &get_default_gateway();
my ($addr6, $router6) = &get_default_ipv6_gateway();
my @ifaces = grep { $_->{'virtual'} eq '' } &boot_interfaces();
my @inames = map { $_->{'name'} } @ifaces;

# Show default gateway
print &ui_table_row($text{'routes_default'},
	&ui_radio("gateway_def", $addr ? 0 : 1,
		  [ [ 1, $text{'routes_none'} ],
		    [ 0, $text{'routes_gateway'}." ".
			 &ui_textbox("gateway", $addr, 15)." ".
			 &ui_select("gatewaydev", $router, \@inames) ] ]));

# Show default IPv6 gateway
print &ui_table_row($text{'routes_default6'},
	&ui_radio("gateway6_def", $addr6 ? 0 : 1,
		  [ [ 1, $text{'routes_none'} ],
		    [ 0, $text{'routes_gateway'}." ".
			 &ui_textbox("gateway6", $addr6, 30)." ".
			 &ui_select("gatewaydev6", $router6, \@inames) ] ]));

# Act as router?
my %sysctl;
&read_env_file($sysctl_config, \%sysctl);
print &ui_table_row($text{'routes_forward'},
	&ui_yesno_radio("forward",
			$sysctl{'net.ipv4.ip_forward'} ? 1 : 0));

# Static routes
my $rtable = &ui_columns_start([ $text{'routes_ifc'},
			       $text{'routes_net'},
			       $text{'routes_mask'},
			       $text{'routes_gateway'} ]);
my $i = 0;
@inames = ( "", @inames );
foreach my $b (@ifaces) {
	next if (!$b->{'routes'});
	foreach my $v (@{$b->{'routes'}->{'value'}}) {
		my ($net, $mask) = split(/\//, $v->{'to'});
		$mask = &prefix_to_mask($mask);
		$rtable .= &ui_columns_row([
		    &ui_select("dev_$i", $b->{'fullname'}, \@inames, 1, 0, 1),
		    &ui_textbox("net_$i", $net, 15),
		    &ui_textbox("mask_$i", $mask, 15),
		    &ui_textbox("gw_$i", $v->{'via'}, 15),
		    ]);
		$i++;
		}
	}
$rtable .= &ui_columns_row([
	&ui_select("dev_$i", "", \@inames, 1, 0, 1),
	&ui_textbox("net_$i", "", 15),
	&ui_textbox("mask_$i", "", 15),
	&ui_textbox("gw_$i", "", 15),
	]);
$rtable .= &ui_columns_end();
print &ui_table_row($text{'routes_static'}, $rtable);
}

# parse_routing()
# Save the form generated by routing_input
sub parse_routing
{
# Save IPv4 address
my ($dev, $gw);
if (!$in{'gateway_def'}) {
	&check_ipaddress($in{'gateway'}) ||
		&error(&text('routes_egateway', &html_escape($in{'gateway'})));
	$gw = $in{'gateway'};
	$dev = $in{'gatewaydev'};
	}
&set_default_gateway($gw, $dev);

# Save IPv6 address
my ($dev6, $gw6);
if (!$in{'gateway6_def'}) {
	&check_ip6address($in{'gateway6'}) ||
		&error(&text('routes_egateway6',&html_escape($in{'gateway6'})));
	$gw6 = $in{'gateway6'};
	$dev6 = $in{'gatewaydev6'};
	}
&set_default_ipv6_gateway($gw6, $dev6);

# Save routing flag
my %sysctl;
&lock_file($sysctl_config);
&read_env_file($sysctl_config, \%sysctl);
$sysctl{'net.ipv4.ip_forward'} = $in{'forward'};
&write_env_file($sysctl_config, \%sysctl);
&unlock_file($sysctl_config);

# Save static routes
my @boot =  &boot_interfaces();
foreach my $b (grep { $_->{'virtual'} eq '' } @boot) {
	my @r;
	for(my $i=0; defined($in{"dev_$i"}); $i++) {
		if ($in{"dev_$i"} eq $b->{'fullname'}) {
			&check_ipaddress($in{"net_$i"}) ||
				&error(&text('routes_enet', $in{"net_$i"}));
			&check_ipaddress($in{"mask_$i"}) ||
				&error(&text('routes_emask', $in{"mask_$i"}));
			my $to = $in{"net_$i"}."/".
				 &mask_to_prefix($in{"mask_$i"});
			&check_ipaddress($in{"gw_$i"}) ||
				&error(&text('routes_egateway', $in{"gw_$i"}));
			push(@r, { 'to' => $to, 'via' => $in{"gw_$i"} });
			}
		}
	if (@r) {
		$b->{'routes'} = { 'name' => 'routes',
				   'value' => \@r };
		}
	else {
		delete($b->{'routes'});
		}
	&save_interface($b, \@boot);
	}
}

sub network_config_files
{
return ( "/etc/hostname", "/etc/HOSTNAME", "/etc/mailname" );
}

# apply_network()
# Apply the interface and routing settings
sub apply_network
{
&system_logged("(cd / ; netplan apply) >/dev/null 2>&1");
}

# get_default_gateway()
# Returns the default gateway IP (if one is set) and device (if set) boot time
# settings.
sub get_default_gateway
{
foreach my $iface (&boot_interfaces()) {
	if ($iface->{'gateway'}) {
		return ( $iface->{'gateway'}, $iface->{'fullname'} );
		}
	}
return ( );
}

# set_default_gateway([gateway, device])
# Sets the default gateway to the given IP accessible via the given device,
# in the boot time settings.
sub set_default_gateway
{
my ($gw, $dev) = @_;
foreach my $iface (&boot_interfaces()) {
	if ($iface->{'fullname'} eq $dev && $iface->{'gateway'} ne $gw) {
		# Need to add to this interface
		$iface->{'gateway'} = $gw;
		&save_interface($iface);
		}
	elsif ($iface->{'fullname'} ne $dev && $iface->{'gateway'}) {
		# Need to remove from this interface
		delete($iface->{'gateway'});
		&save_interface($iface);
		}
	}
}

# get_default_ipv6_gateway()
# Returns the default gateway IPv6 address (if one is set) and device (if set)
# boot time settings.
sub get_default_ipv6_gateway
{
foreach my $iface (&boot_interfaces()) {
	if ($iface->{'gateway6'}) {
		return ( $iface->{'gateway6'}, $iface->{'fullname'} );
		}
	}
return ( );
}

# set_default_ipv6_gateway([gateway, device])
# Sets the default IPv6 gateway to the given IP accessible via the given device,
# in the boot time settings.
sub set_default_ipv6_gateway
{
my ($gw, $dev) = @_;
foreach my $iface (&boot_interfaces()) {
	if ($iface->{'fullname'} eq $dev && $iface->{'gateway6'} ne $gw) {
		# Need to add to this interface
		$iface->{'gateway6'} = $gw;
		&save_interface($iface);
		}
	elsif ($iface->{'fullname'} ne $dev && $iface->{'gateway6'}) {
		# Need to remove from this interface
		delete($iface->{'gateway6'});
		&save_interface($iface);
		}
	}
}

# os_save_dns_config(&config)
# On Ubuntu 18+, DNS servers are stored in the Netplan config files
sub os_save_dns_config
{
my ($conf) = @_;
my @boot = &boot_interfaces();
my @fix = grep { $_->{'nameserver'} } @boot;
@fix = @boot if (!@fix);
foreach my $iface (@fix) {
	$iface->{'nameserver'} = $conf->{'nameserver'};
	$iface->{'search'} = $conf->{'domain'};
	&save_interface($iface);
	}
}

# read_yaml_file(file)
# Converts a YAML file into a nested hash ref
sub read_yaml_file
{
my ($file) = @_;
my $lref = &read_file_lines($file, 1);
my $lnum = 0;
my $rv = [ ];
my $parent = { 'members' => $rv,
	       'indent' => -1 };
my $lastdir;
foreach my $origl (@$lref) {
	my $l = $origl;
	$l =~ s/#.*$//;
	if ($l =~ /^(\s*)(\S+):\s*(.*)/) {
		# Name and possibly value
		my $i = length($1);
		if ($i > $lastdir->{'indent'} + 2 &&
		    ref($lastdir->{'value'}) eq 'ARRAY' &&
		    @{$lastdir->{'value'}} &&
		    ref($lastdir->{'value'}->[0]) eq 'HASH') {
			# Another key in the current value hash
			my $v = $lastdir->{'value'};
			$v->[@$v-1]->{$2} = $3;
			&set_parent_elines($lastdir, $lnum);
			}
		else {
			# A regular directive
			my $dir = { 'indent' => length($1),
				    'name' => $2,
				    'value' => $3,
				    'line' => $lnum,
				    'eline' => $lnum,
				    'parent' => $parent,
				    'members' => [],
				  };
			if ($dir->{'value'} =~ /^\[(.*)\]$/) {
				$dir->{'value'} = [ &split_addr_list("$1") ];
				}
			if (!$lastdir || $i == $lastdir->{'indent'}) {
				# At same level as previous directive, which
				# puts it underneath current parent
				push(@{$parent->{'members'}}, $dir);
				}
			elsif ($i > $lastdir->{'indent'}) {
				# A further ident by one level, meaning that it
				# is under the previous directive
				$parent = $lastdir;
				$dir->{'parent'} = $parent;
				push(@{$parent->{'members'}}, $dir);
				}
			elsif ($i < $lastdir->{'indent'}) {
				# Indent has decreased, so this must be under a
				# previous parent directive
				$parent = $parent->{'parent'};
				while($i <= $parent->{'indent'}) {
					$parent = $parent->{'parent'};
					}
				push(@{$parent->{'members'}}, $dir);
				$dir->{'parent'} = $parent;
				}
			$lastdir = $dir;
			&set_parent_elines($parent, $lnum);
			}
		}
	elsif ($l =~ /^(\s*)\-\s*(\S+):\s+(\S.*)$/) {
		# Value that is itself a key-value pair
		# routes:
		#   - to: 1.2.3.4/24
		#     via: 1.2.3.1
		#     metric: 100
		$lastdir->{'value'} ||= [ ];
		my $v = { $2 => $3 };
		push(@{$lastdir->{'value'}}, $v);
		$lastdir->{'eline'} = $lnum;
		&set_parent_elines($parent, $lnum);
		}
	elsif ($l =~ /^(\s*)\-\s*(\S+)\s*$/) {
		# Value-only line that is an extra value for the previous dir
		# addresses:
		#   - 1.2.3.4/24
		#   - 5.6.7.8/24
		$lastdir->{'value'} ||= [ ];
		$lastdir->{'value'} = [ $lastdir->{'value'} ] if (!ref($lastdir->{'value'}));
		push(@{$lastdir->{'value'}}, $2);
		$lastdir->{'eline'} = $lnum;
		&set_parent_elines($parent, $lnum);
		}
	$lnum++;
	}
&cleanup_yaml_parents($rv);
return $rv;
}

# cleanup_yaml_parents(&config)
# Remove all 'parent' fields once parsing is done, as they can't be serialized
sub cleanup_yaml_parents
{
my ($conf) = @_;
foreach my $c (@$conf) {
	delete($c->{'parent'});
	if ($c->{'members'}) {
		&cleanup_yaml_parents($c->{'members'});
		}
	}
}

# yaml_lines(&directive, indent-string)
# Converts a YAML directive into text lines
sub yaml_lines
{
my ($yaml, $id) = @_;
my @rv;
my $v = $id.$yaml->{'name'}.":";
if (ref($yaml->{'value'}) eq 'ARRAY') {
	my @a = @{$yaml->{'value'}};
	if (@a && ref($a[0]) eq 'HASH') {
		# Array of hashes, like for routes
		push(@rv, $v);
		foreach my $a (@a) {
			my @k = sort(keys %$a);
			my $f = shift(@k);
			push(@rv, $id."  - ".$f.": ".$a->{$f});
			foreach my $f (@k) {
				push(@rv, $id."    ".$f.": ".$a->{$f});
				}
			}
		}
	else {
		# Array of strings
		push(@rv, $v." [".&join_addr_list(@a)."]");
		}
	}
elsif (defined($yaml->{'value'})) {
	push(@rv, $v." ".$yaml->{'value'});
	}
else {
	push(@rv, $v);
	}
if ($yaml->{'members'}) {
	foreach my $m (@{$yaml->{'members'}}) {
		push(@rv, &yaml_lines($m, $id."    "));
		}
	}
return @rv;
}

# set_parent_elines(&conf, eline)
sub set_parent_elines
{
my ($c, $eline) = @_;
$c->{'eline'} = $eline;
&set_parent_elines($c->{'parent'}, $eline) if ($c->{'parent'});
}

# split_addr_netmask(addr-string)
# Splits a string like 1.2.3.4/24 into an address and netmask
sub split_addr_netmask
{
my ($a) = @_;
$a =~ s/^'(.*)'$/$1/g;
$a =~ s/^"(.*)"$/$1/g;
if ($a =~ /^([0-9\.]+)\/(\d+)$/) {
	return ($1, &prefix_to_mask($2));
	}
elsif ($a =~ /^([0-9\.]+)\/([0-9\.]+)$/) {
	return ($1, $2);
	}
else {
	return $a;
	}
}

# join_addr_list(addr, ...)
# Returns a string of properly joined addresses 
sub join_addr_list
{
my @rv;
foreach my $a (@_) {
	if ($a =~ /\/|\s|:/) {
		push(@rv, "'$a'");
		}
	else {
		push(@rv, $a);
		}
	}
return join(", ", @rv);
}

# split_addr_list(string)
# Split up a string of properly formatted addresses
sub split_addr_list
{
my ($str) = @_;
my @rv;
foreach my $a (split(/\s*,\s*/, $str)) {
	if ($a =~ /^'(.*)'$/ || $a =~ /^"(.*)"$/) {
		push(@rv, $1);
		}
	else {
		push(@rv, $a);
		}
	}
return @rv;
}

sub is_true_value
{
my ($dir) = @_;
return $dir && $dir->{'value'} =~ /true|yes|1/i;
}

1;

Filemanager

Name Type Size Permission Actions
images Folder 0755
lang Folder 0755
CHANGELOG File 5.55 KB 0644
acl_security.pl File 3.08 KB 0755
apply.cgi File 184 B 0755
backup_config.pl File 1005 B 0755
cgi_args.pl File 752 B 0755
cobalt-linux-lib.pl File 32.85 KB 0755
coherent-linux-lib.pl File 32.85 KB 0755
config File 48 B 0644
config-ALL-linux File 48 B 0644
config-cygwin File 82 B 0644
config-freebsd File 48 B 0644
config-macos File 48 B 0644
config-netbsd File 48 B 0644
config-openbsd File 48 B 0644
config-solaris File 79 B 0644
config-syno-linux File 48 B 0644
config-unixware File 48 B 0644
config-windows File 78 B 0644
config.info File 193 B 0644
config.info.ca File 241 B 0644
config.info.cs File 205 B 0644
config.info.de File 219 B 0644
config.info.es File 175 B 0644
config.info.fa File 255 B 0644
config.info.fr File 246 B 0644
config.info.hu File 0 B 0644
config.info.ja File 68 B 0644
config.info.nl File 197 B 0644
config.info.no File 208 B 0644
config.info.pl File 240 B 0644
config.info.pt_BR File 229 B 0644
config.info.ru File 361 B 0644
config.info.sk File 225 B 0644
config.info.sv File 42 B 0644
config.info.tr File 65 B 0644
config.info.uk File 87 B 0644
config.info.zh File 43 B 0644
config.info.zh_TW File 44 B 0644
create_route.cgi File 1004 B 0755
cygwin-lib.pl File 11.28 KB 0755
debian-linux-lib.pl File 33.58 KB 0755
defaultacl File 114 B 0644
delete_aifcs.cgi File 537 B 0755
delete_bifcs.cgi File 1.44 KB 0755
delete_hosts.cgi File 523 B 0755
delete_ipnodes.cgi File 542 B 0755
delete_routes.cgi File 458 B 0755
edit_aifc.cgi File 5.09 KB 0755
edit_bifc.cgi File 10.42 KB 0755
edit_host.cgi File 1.13 KB 0755
edit_ipnode.cgi File 1.04 KB 0755
edit_range.cgi File 1.34 KB 0755
freebsd-lib.pl File 19.22 KB 0755
gentoo-linux-lib.pl File 8.47 KB 0755
index.cgi File 1.25 KB 0755
interface_chooser.cgi File 3.8 KB 0755
linux-lib.pl File 27.58 KB 0755
list_dns.cgi File 2.3 KB 0755
list_hosts.cgi File 1.36 KB 0755
list_ifcs.cgi File 7.96 KB 0755
list_ipnodes.cgi File 1.07 KB 0755
list_routes.cgi File 3.38 KB 0755
log_parser.pl File 1.24 KB 0755
macos-lib.pl File 11.57 KB 0755
mandrake-linux-lib.pl File 32.85 KB 0755
mod_aifc.cgi File 720 B 0755
module.info File 485 B 0644
module.info.af File 0 B 0644
module.info.af.auto File 123 B 0644
module.info.ar File 0 B 0644
module.info.ar.auto File 170 B 0644
module.info.be File 0 B 0644
module.info.be.auto File 226 B 0644
module.info.bg File 0 B 0644
module.info.bg.auto File 261 B 0644
module.info.ca File 127 B 0644
module.info.ca.auto File 25 B 0644
module.info.cs File 27 B 0644
module.info.cs.auto File 111 B 0644
module.info.da File 0 B 0644
module.info.da.auto File 129 B 0644
module.info.de File 121 B 0644
module.info.de.auto File 19 B 0644
module.info.el File 0 B 0644
module.info.el.auto File 229 B 0644
module.info.es File 30 B 0644
module.info.es.auto File 116 B 0644
module.info.eu File 0 B 0644
module.info.eu.auto File 142 B 0644
module.info.fa File 0 B 0644
module.info.fa.auto File 194 B 0644
module.info.fi File 0 B 0644
module.info.fi.auto File 145 B 0644
module.info.fr File 30 B 0644
module.info.fr.auto File 128 B 0644
module.info.he File 0 B 0644
module.info.he.auto File 161 B 0644
module.info.hr File 0 B 0644
module.info.hr.auto File 148 B 0644
module.info.hu File 34 B 0644
module.info.hu.auto File 148 B 0644
module.info.it File 28 B 0644
module.info.it.auto File 112 B 0644
module.info.ja File 33 B 0644
module.info.ja.auto File 153 B 0644
module.info.ko File 28 B 0644
module.info.ko.auto File 105 B 0644
module.info.lt File 0 B 0644
module.info.lt.auto File 157 B 0644
module.info.lv File 0 B 0644
module.info.lv.auto File 157 B 0644
module.info.ms File 136 B 0644
module.info.ms.auto File 18 B 0644
module.info.mt File 0 B 0644
module.info.mt.auto File 144 B 0644
module.info.nl File 29 B 0644
module.info.nl.auto File 105 B 0644
module.info.no File 31 B 0644
module.info.no.auto File 99 B 0644
module.info.pl File 122 B 0644
module.info.pl.auto File 19 B 0644
module.info.pt File 31 B 0644
module.info.pt.auto File 125 B 0644
module.info.pt_BR File 34 B 0644
module.info.pt_BR.auto File 131 B 0644
module.info.ro File 0 B 0644
module.info.ro.auto File 143 B 0644
module.info.ru File 36 B 0644
module.info.ru.auto File 167 B 0644
module.info.sk File 28 B 0644
module.info.sk.auto File 113 B 0644
module.info.sl File 0 B 0644
module.info.sl.auto File 140 B 0644
module.info.sv File 31 B 0644
module.info.sv.auto File 103 B 0644
module.info.th File 0 B 0644
module.info.th.auto File 327 B 0644
module.info.tr File 30 B 0644
module.info.tr.auto File 130 B 0644
module.info.uk File 0 B 0644
module.info.uk.auto File 223 B 0644
module.info.ur File 0 B 0644
module.info.ur.auto File 210 B 0644
module.info.vi File 0 B 0644
module.info.vi.auto File 170 B 0644
module.info.zh File 21 B 0644
module.info.zh.auto File 90 B 0644
module.info.zh_TW File 24 B 0644
module.info.zh_TW.auto File 96 B 0644
msc-linux-lib.pl File 32.85 KB 0755
net-lib.pl File 12 KB 0755
netbsd-lib.pl File 19.22 KB 0755
netplan-lib.pl File 21.01 KB 0644
open-linux-lib.pl File 7.2 KB 0755
openbsd-lib.pl File 12.6 KB 0755
openmamba-linux-lib.pl File 32.85 KB 0755
pardus-linux-lib.pl File 32.85 KB 0755
rbac-mapping File 180 B 0644
rc.inet1 File 1.95 KB 0644
redhat-linux-lib.pl File 32.85 KB 0755
save_aifc.cgi File 5.78 KB 0755
save_bifc.cgi File 10.12 KB 0755
save_dns.cgi File 3.65 KB 0755
save_host.cgi File 1.18 KB 0755
save_ipnode.cgi File 1.26 KB 0755
save_range.cgi File 1.42 KB 0755
save_routes.cgi File 283 B 0755
slackware-linux-9.1-ALL-lib.pl File 7.85 KB 0755
slackware-linux-lib.pl File 6.71 KB 0755
solaris-lib.pl File 20.79 KB 0755
suse-linux-8.0-lib.pl File 7.31 KB 0755
suse-linux-8.2-lib.pl File 7.31 KB 0755
suse-linux-9.0-lib.pl File 8.74 KB 0755
suse-linux-9.1-lib.pl File 8.74 KB 0755
suse-linux-9.2-ALL-lib.pl File 11.23 KB 0755
suse-linux-lib.pl File 9.08 KB 0755
system_info.pl File 2.42 KB 0644
trustix-linux-lib.pl File 32.85 KB 0755
turbo-linux-lib.pl File 32.85 KB 0755
united-linux-lib.pl File 7.31 KB 0755
unixware-lib.pl File 9.9 KB 0755
windows-lib.pl File 11.28 KB 0755