diff options
author | Rick Balocca <rbalocca@vyatta.com> | 2008-08-06 15:13:04 -0700 |
---|---|---|
committer | Rick Balocca <rbalocca@vyatta.com> | 2008-08-06 15:13:04 -0700 |
commit | bd9e80da61ecf93bc2e4a7ec649d95cfef89d4e2 (patch) | |
tree | f30552e4c6b0b584f6c2ff81cd38ae539d5612c7 /scripts | |
parent | ad73790f163764d737829838e8708a9a9c240151 (diff) | |
parent | b07c0515451f5f429ef10ee2cfc4472ca452a9a9 (diff) | |
download | vyatta-cfg-quagga-bd9e80da61ecf93bc2e4a7ec649d95cfef89d4e2.tar.gz vyatta-cfg-quagga-bd9e80da61ecf93bc2e4a7ec649d95cfef89d4e2.zip |
Merge branch 'islavista' of git:/git/vyatta-cfg-system into islavista
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/dns-forwarding/vyatta-dns-forwarding.pl | 138 | ||||
-rwxr-xr-x | scripts/standalone_root_pw_reset | 4 |
2 files changed, 140 insertions, 2 deletions
diff --git a/scripts/dns-forwarding/vyatta-dns-forwarding.pl b/scripts/dns-forwarding/vyatta-dns-forwarding.pl new file mode 100644 index 00000000..1fb2282a --- /dev/null +++ b/scripts/dns-forwarding/vyatta-dns-forwarding.pl @@ -0,0 +1,138 @@ +#!/usr/bin/perl +# +# Module: vyatta-dns-forwarding.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Mohit Mehta +# Date: August 2008 +# Description: Script to glue Vyatta CLI to dnsmasq daemon +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfig; +use VyattaMisc; +use Getopt::Long; + +use strict; +use warnings; + +my $dnsforwarding_init = '/etc/init.d/dnsmasq'; +my $dnsforwarding_conf = '/etc/dnsmasq.conf'; + +sub dnsforwarding_init { + +} + +sub dnsforwarding_restart { + system("$dnsforwarding_init restart >&/dev/null"); + print "Setting up DNS forwarding.\n"; +} + +sub dnsforwarding_stop { + system("$dnsforwarding_init stop >&/dev/null"); + print "Stopping DNS forwarding.\n"; +} + +sub dnsforwarding_get_constants { + my $output; + + my $date = `date`; + chomp $date; + $output = "#\n# autogenerated by vyatta-dns-forwarding.pl on $date\n#\n"; + return $output; +} + +sub dnsforwarding_get_values { + my $output = ''; + my $config = new VyattaConfig; + + $config->setLevel("service dns-forwarding"); + + my @ignore_interfaces = $config->returnValues("ignore-interface"); + if ($#ignore_interfaces >= 0) { + foreach my $interface (@ignore_interfaces) { + $output .= "except-interface=$interface\n"; + } + } + + my $cache_size = $config->returnValue("cache-size"); + if (defined $cache_size) { + $output .= "cache-size=$cache_size\n"; + } + + return $output; +} + +sub dnsforwarding_write_file { + my ($config) = @_; + + open(my $fh, '>', $dnsforwarding_conf) || die "Couldn't open $dnsforwarding_conf - $!"; + print $fh $config; + close $fh; +} + +sub check_nameserver { + + my $cmd = `grep nameserver /etc/resolv.conf|wc -l`; + return $cmd; +} + +# +# main +# +my $init_dnsforwarding; +my $update_dnsforwarding; +my $stop_dnsforwarding; +my $nameserver; + +GetOptions("init-dnsforwarding!" => \$init_dnsforwarding, + "update-dnsforwarding!" => \$update_dnsforwarding, + "stop-dnsforwarding!" => \$stop_dnsforwarding, + "nameserver!" => \$nameserver); + +if (defined $nameserver) { + my $nameserver_exists = check_nameserver(); + if ($nameserver_exists < 1){ + exit 1; + } else { + exit 0; + } +} + + +if (defined $init_dnsforwarding) { + dnsforwarding_init(); +} + +if (defined $update_dnsforwarding) { + my $config; + + $config = dnsforwarding_get_constants(); + $config .= dnsforwarding_get_values(); + dnsforwarding_write_file($config); + dnsforwarding_restart(); +} + +if (defined $stop_dnsforwarding) { + dnsforwarding_stop(); +} + +exit 0; + +# end of file + diff --git a/scripts/standalone_root_pw_reset b/scripts/standalone_root_pw_reset index b173f22d..336d534d 100755 --- a/scripts/standalone_root_pw_reset +++ b/scripts/standalone_root_pw_reset @@ -70,13 +70,13 @@ cp $CF ${CF}.before_pwrecovery echo "Reseting the root password..." # change system first -newpwd=$(mkpasswd -H md5 vyatta) +newpwd=`mkpasswd -H md5 vyatta` usermod --password "$newpwd" root # escape / in encrypted passwd pw=$(echo $newpwd | sed 's:/:\\/:g') sed -i \ - -e "/^.* user root {/,/}/s/encrypted-password:.*\$/encrypted-password: \"$pw\"/" \ + -e "/^.* user root {/,/}/s/encrypted-password .*\$/encrypted-password \"$pw\"/" \ $CF echo $(date "+%b%e %T") $(hostname) "Root password reset to factory value" \ |