diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/dns-forwarding/vyatta-dns-forwarding.pl | 25 | ||||
-rwxr-xr-x | scripts/dynamic-dns/vyatta-dynamic-dns.pl | 12 | ||||
-rwxr-xr-x | scripts/system/vyatta_update_console.pl | 90 | ||||
-rwxr-xr-x | scripts/system/vyatta_update_resolv.pl | 86 | ||||
-rwxr-xr-x | scripts/vyatta-system-nameservers | 2 |
5 files changed, 140 insertions, 75 deletions
diff --git a/scripts/dns-forwarding/vyatta-dns-forwarding.pl b/scripts/dns-forwarding/vyatta-dns-forwarding.pl index b5efd269..217a520a 100755 --- a/scripts/dns-forwarding/vyatta-dns-forwarding.pl +++ b/scripts/dns-forwarding/vyatta-dns-forwarding.pl @@ -63,7 +63,7 @@ sub dnsforwarding_get_values { my $output = ''; my $config = new Vyatta::Config; my $use_dnsmasq_conf = 0; - my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @domain, $server, $ignore_hosts_file); + my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @domains, $server, $ignore_hosts_file); $config->setLevel("service dns forwarding"); @@ -73,7 +73,7 @@ sub dnsforwarding_get_values { @use_nameservers = $config->returnOrigValues("name-server"); $use_system_nameservers = $config->existsOrig("system"); @use_dhcp_nameservers = $config->returnOrigValues("dhcp"); - @domain = $config->listOrigNodes("domain"); + @domains = $config->listOrigNodes("domain"); $ignore_hosts_file = $config->returnOrigValue("ignore-hosts-file"); } else { @@ -82,7 +82,7 @@ sub dnsforwarding_get_values { @use_nameservers = $config->returnValues("name-server"); $use_system_nameservers = $config->exists("system"); @use_dhcp_nameservers = $config->returnValues("dhcp"); - @domain = $config->listNodes("domain"); + @domains = $config->listNodes("domain"); $ignore_hosts_file = $config->exists("ignore-hosts-file"); } @@ -112,7 +112,7 @@ sub dnsforwarding_get_values { my $sys_config = new Vyatta::Config; $sys_config->setLevel("system"); my @system_nameservers; - if ($outside_cli == 1){ + if ($outside_cli == 1) { @system_nameservers = $sys_config->returnOrigValues("name-server"); } else { @system_nameservers = $sys_config->returnValues("name-server"); @@ -123,11 +123,18 @@ sub dnsforwarding_get_values { } } } - if (@domain != 0) { - foreach my $dom (@domain) { - my $ser = $config->returnValue("domain $dom server"); - if (defined ($ser)) { - $output .="server=/$dom/$ser\t# domain-override\n"; + if (@domains != 0) { + foreach my $domain (@domains) { + my @domain_servers; + if ($outside_cli == 1) { + @domain_servers = $config->returnValues("domain $domain server"); + } else { + @domain_servers = $config->returnValues("domain $domain server"); + } + if (@domain_servers > 0) { + foreach my $domain_server (@domain_servers) { + $output .="server=/$domain/$domain_server\t# domain-override\n"; + } } } } diff --git a/scripts/dynamic-dns/vyatta-dynamic-dns.pl b/scripts/dynamic-dns/vyatta-dynamic-dns.pl index 8788730f..83206253 100755 --- a/scripts/dynamic-dns/vyatta-dynamic-dns.pl +++ b/scripts/dynamic-dns/vyatta-dynamic-dns.pl @@ -96,16 +96,24 @@ sub dynamicdns_get_constants { $output .= "ssl=yes\n"; $output .= "pid=$ddclient_run_dir/ddclient_$interface.pid\n"; $output .= "cache=$ddclient_cache_dir/ddclient_$interface.cache\n"; - $output .= "use=if, if=$interface\n\n\n"; return $output; } sub dynamicdns_get_values { - my $output = ''; + my $output; my $config = new Vyatta::Config; $config->setLevel("service dns dynamic interface $interface"); + my $web_url = $config->returnValue("use-web url"); + my $web_skip = $config->returnValue("use-web skip"); + + if ($web_url && $web_skip) { + $output = "use=web, web=$web_url, web-skip='".$web_skip."'\n\n\n"; + } else { + $output = "use=if, if=$interface\n\n\n"; + } + my @services = $config->listNodes("service"); foreach my $service (@services) { $config->setLevel("service dns dynamic interface $interface service $service"); diff --git a/scripts/system/vyatta_update_console.pl b/scripts/system/vyatta_update_console.pl index 0ee6a6e5..7c36ec7f 100755 --- a/scripts/system/vyatta_update_console.pl +++ b/scripts/system/vyatta_update_console.pl @@ -34,13 +34,13 @@ die "$0 expects no arguments\n" if (@ARGV); sub update { my ($old, $new) = @_; - if ( compare($old, $new) != 0) { - move($new, $old) - or die "Can't move $new to $old"; - return 1; + if (compare($old, $new) != 0) { + move($new, $old) + or die "Can't move $new to $old"; + return 1; } else { - unlink($new); - return; + unlink($new); + return; } } @@ -48,14 +48,15 @@ my $INITTAB = "/etc/inittab"; my $TMPTAB = "/tmp/inittab.$$"; sub update_inittab { - open (my $inittab, '<', $INITTAB) - or die "Can't open $INITTAB: $!"; + open(my $inittab, '<', $INITTAB) + or die "Can't open $INITTAB: $!"; - open (my $tmp, '>', $TMPTAB) - or die "Can't open $TMPTAB: $!"; + open(my $tmp, '>', $TMPTAB) + or die "Can't open $TMPTAB: $!"; # Clone original inittab but remove all references to serial lines - print {$tmp} grep { ! /^T|^# Vyatta/ } <$inittab>; + # and Xen consoles + print {$tmp} grep {!/^T|^# Vyatta|^h/} <$inittab>; close $inittab; my $config = new Vyatta::Config; @@ -63,29 +64,38 @@ sub update_inittab { print {$tmp} "# Vyatta console configuration (do not modify)\n"; - my $id = 0; + my $serial_id = 0; + my $xen_id = 0; + foreach my $tty ($config->listNodes()) { - my $speed = $config->returnValue("$tty speed"); - $speed = 9600 unless $speed; - - printf {$tmp} "T%d:23:respawn:", $id; - if ($config->exists("$tty modem")) { - printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; - } else { - printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; - } - - # id field is limited to 4 characters - if (++$id >= 1000) { - warn "Ignoring $tty only 1000 serial devices supported\n"; - last; - } + my $speed = $config->returnValue("$tty speed"); + if ($tty =~ /^hvc\d/) { + $speed = 38400 unless $speed; + printf {$tmp} "h%d:23:respawn:", $xen_id; + printf {$tmp} "/sbin/getty %d %s\n", $speed, $tty; + $xen_id++; + } else { + $speed = 9600 unless $speed; + printf {$tmp} "T%d:23:respawn:", $serial_id; + if ($config->exists("$tty modem")) { + printf {$tmp} "/sbin/mgetty -x0 -s %d %s\n", $speed, $tty; + } else { + printf {$tmp} "/sbin/getty -L %s %d vt100\n", $tty, $speed; + } + + # id field is limited to 4 characters + if (++$serial_id >= 1000) { + warn "Ignoring $tty only 1000 serial devices supported\n"; + last; + } + } } close $tmp; if (update($INITTAB, $TMPTAB)) { - # This is same as telinit q - it tells init to re-examine inittab - kill 1, 1; + + # This is same as telinit q - it tells init to re-examine inittab + kill 1, 1; } } @@ -104,20 +114,20 @@ sub update_grub { my $speed = $config->returnValue("ttyS0 speed"); $speed = "9600" unless defined($speed); - open (my $grub, '<', $GRUBCFG) - or die "Can't open $GRUBCFG: $!"; + open(my $grub, '<', $GRUBCFG) + or die "Can't open $GRUBCFG: $!"; - open (my $tmp, '>', $GRUBTMP) - or die "Can't open $GRUBTMP: $!"; + open(my $tmp, '>', $GRUBTMP) + or die "Can't open $GRUBTMP: $!"; while (<$grub>) { - if (/^serial / ) { - print {$tmp} "serial --unit=0 --speed=$speed\n"; - } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { - print {$tmp} "$1,$speed$2\n"; - } else { - print {$tmp} $_; - } + if (/^serial /) { + print {$tmp} "serial --unit=0 --speed=$speed\n"; + } elsif (/^(.* console=ttyS0),[0-9]+(.*)$/) { + print {$tmp} "$1,$speed$2\n"; + } else { + print {$tmp} $_; + } } close $grub; close $tmp; diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 921052f0..0dfa4bec 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -37,7 +37,7 @@ GetOptions("dhclient-script=i" => \$dhclient_script, my $vc = new Vyatta::Config(); $vc->setLevel('system'); -my @domains; +my @search_domains; my $domain_name = undef; my $disable_dhcp_nameservers = undef; @@ -48,34 +48,39 @@ if ($config_mode == 1) { } if ($dhclient_script == 1) { - @domains = $vc->returnOrigValues('domain-search domain'); + @search_domains = $vc->returnOrigValues('domain-search domain'); $domain_name = $vc->returnOrigValue('domain-name'); } else { - @domains = $vc->returnValues('domain-search domain'); + @search_domains = $vc->returnValues('domain-search domain'); $domain_name = $vc->returnValue('domain-name'); } -if ($dhclient_script == 0 && @domains > 0 && $domain_name && length($domain_name) > 0) { - my @loc; +if ($dhclient_script == 0 && @search_domains > 0 && $domain_name && length($domain_name) > 0) { + my @location; if ($vc->returnOrigValues('domain-search domain') > 0) { - @loc = ["system","domain-name"]; + @location = ["system","domain-name"]; } else { - @loc = ["system","domain-search","domain"]; + @location = ["system","domain-search","domain"]; } - Vyatta::Config::outputError(@loc,"System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed."); + Vyatta::Config::outputError(@location,"System configuration error. Both \'domain-name\' and \'domain-search\' are specified, but only one of these mutually exclusive parameters is allowed."); exit(1); } -my $doms = ''; -foreach my $domain (@domains) { - if (length($doms) > 0) { - $doms .= ' '; +my $search_domain_list = ''; +my $search_includes_system = 0; + +foreach my $domain (@search_domains) { + if (length($search_domain_list) > 0) { + $search_domain_list .= ' '; } - $doms .= $domain; + $search_domain_list .= $domain; + $search_includes_system = 1; } -# add domain names received from dhcp client to domain search in /etc/resolv.conf if domain-name not set in CLI +# add domain searches received from the dhcp client to those already in /etc/resolv.conf, as long as domain-name is not set in the CLI + +my $search_includes_dhcp = 0; if (!defined($domain_name)) { my @dhcp_interfaces_resolv_files = `ls /etc/ | grep resolv.conf.dhclient-new`; @@ -88,20 +93,34 @@ if (!defined($domain_name)) { my @dhcp_domains = split(/\s+/, $search_string, 2); my $dhcp_domain = $dhcp_domains[1]; chomp $dhcp_domain; - $doms .= ' ' . $dhcp_domain; + if (length($search_domain_list) > 0) { + $search_domain_list .= ' '; + } + $search_domain_list .= $dhcp_domain; + $search_includes_dhcp = 1; } } } } my $search = ''; -if (length($doms) > 0) { - $search = "search\t\t$doms\t\t#line generated by $0\n"; +if (length($search_domain_list) > 0) { + my $source; + if ($search_includes_system == 1) { + if ($search_includes_dhcp == 1) { + $source = "(system + dhcp)"; + } else { + $source = "(system)"; + } + } else { + $source = "(dhcp)"; + } + $search = "#line generated by vyatta_update_resolv.pl $source\nsearch\t\t$search_domain_list\n"; } my $domain = ''; if ($domain_name && length($domain_name) > 0) { - $domain = "domain\t\t$domain_name\t\t#line generated by $0\n"; + $domain = "#line generated by vyatta_update_resolv.pl (system)\ndomain\t\t$domain_name\n"; } # update /etc/resolv.conf with name-servers received from dhcp client, done when this script is called @@ -143,7 +162,7 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { if (($ns_in_resolvconf == 0) && !($disable_dhcp_nameservers)) { open (my $rf, '>>', '/etc/resolv.conf') or die "$! error trying to overwrite"; - print $rf "nameserver\t$ns\t\t#nameserver written by $0\n"; + print $rf "#nameserver written by vyatta_update_resolv.pl (dhcp)\nnameserver\t$ns\n"; close $rf; $restart_ntp = 1; } @@ -156,7 +175,16 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { # from dhcp-server, or to remove previous dhcp supplied name-servers if disable-dhcp-nameservers has # been enabled. - my @nameservers_dhcp_in_resolvconf = `grep 'nameserver written' /etc/resolv.conf`; + my $found_old = 0; + + my @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{n;P;}' /etc/resolv.conf`; + for my $old_style_nameservers (@nameservers_dhcp_in_resolvconf) { + if ($old_style_nameservers =~ /#line generated by/){ + @nameservers_dhcp_in_resolvconf = `sed -n '/nameserver written/{P;}' /etc/resolv.conf`; + $found_old = 1; + last; + } + } my @dhcp_nameservers_in_resolvconf; my $count_nameservers_in_resolvconf = 0; for my $count_dhcp_nameserver (@nameservers_dhcp_in_resolvconf) { @@ -166,20 +194,32 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { } if (($#current_dhcp_nameservers < 0) || ($disable_dhcp_nameservers)) { for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { - my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf"; + my $cmd; + chomp $dhcpnameserver; + if ($found_old == 1) { + $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; + } else { + $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; + } system($cmd); $restart_ntp = 1; } } else { for my $dhcpnameserver (@dhcp_nameservers_in_resolvconf) { my $found = 0; + my $cmd; + chomp $dhcpnameserver; for my $currentnameserver (@current_dhcp_nameservers) { if ($dhcpnameserver eq $currentnameserver){ $found = 1; } } if ($found == 0) { - my $cmd = "sed -i '/$dhcpnameserver\t/d' /etc/resolv.conf"; + if ($found_old == 1) { + $cmd = "sed -i '/nameserver\t$dhcpnameserver/d' /etc/resolv.conf"; + } else { + $cmd = "sed -i -n '/nameserver\t$dhcpnameserver/".'{n;x;d;};x;1d;p;${x;p;}'."' /etc/resolv.conf"; + } system($cmd); $restart_ntp = 1; } @@ -221,7 +261,7 @@ foreach my $line (@resolv) { if (length($domain) > 0) { print $r $domain; } - } else { + } elsif ($line !~ /^#line generated by\s/) { print $r $line; } } diff --git a/scripts/vyatta-system-nameservers b/scripts/vyatta-system-nameservers index 74f2c8b6..7b66cf77 100755 --- a/scripts/vyatta-system-nameservers +++ b/scripts/vyatta-system-nameservers @@ -53,7 +53,7 @@ update_system_nameservers () { # find last instance of cli inserted nameserver # insert currently received nameserver immediately after that # this is done to keep system set nameservers priority over dhcp received nameservers - cli_ns_array=($(awk '{if (!$3) print $2}' /etc/resolv.conf)) + cli_ns_array=($(awk '{if (/(dhcp)/) exit 0; if (!$3) print $2}' /etc/resolv.conf)) cli_ns_array_len=${#cli_ns_array[*]} line_num=0 if [ $cli_ns_array_len -gt 0 ]; then |