diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-09-16 09:44:30 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-09-16 09:44:30 -0700 |
commit | 8363358c3010d1f7383e3a09c16d071f9ec5b42f (patch) | |
tree | bd8b4de9797259f513e8f09e5dd40679a9a889eb | |
parent | 4b3aad36248f3e5c02646540801ea05536445ce8 (diff) | |
parent | 93f7c1c4d0ec76d81f093b2fc966cf56c17b372b (diff) | |
download | vyatta-op-8363358c3010d1f7383e3a09c16d071f9ec5b42f.tar.gz vyatta-op-8363358c3010d1f7383e3a09c16d071f9ec5b42f.zip |
Merge branch 'islavista' of suva.vyatta.com:/git/vyatta-op into islavista
42 files changed, 613 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index 7499a22..627ed32 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,8 @@ bin_SCRIPTS += scripts/vyatta-tshark-interface-port.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh bin_sudo_users_SCRIPTS += scripts/vyatta-reboot.pl +bin_sudo_users_SCRIPTS += scripts/vyatta-op-dns-forwarding.pl +bin_sudo_users_SCRIPTS += scripts/vyatta-op-dynamic-dns.pl cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/debian/control b/debian/control index ec5e98c..4cf7a5f 100644 --- a/debian/control +++ b/debian/control @@ -7,6 +7,7 @@ Standards-Version: 3.7.2 Package: vyatta-op Architecture: all +Pre-depends: ssmtp Depends: sed (>= 4.1.5), ethtool, traceroute, @@ -19,7 +20,6 @@ Depends: sed (>= 4.1.5), vyatta-bash | bash (>= 3.1), less, libio-prompt-perl, - ssmtp, at Suggests: util-linux (>= 2.13-5), net-tools, diff --git a/debian/vyatta-op.postinst.in b/debian/vyatta-op.postinst.in index e8bab7f..b5d475b 100644 --- a/debian/vyatta-op.postinst.in +++ b/debian/vyatta-op.postinst.in @@ -7,3 +7,6 @@ bindir=@bindir@ # add symlinks for sudo ln -sf /opt/vyatta/bin/vyatta-show-interfaces.pl ${bindir}/sudo-users/vyatta-show-interfaces.pl ln -sf /opt/vyatta/sbin/vyatta-interfaces.pl ${bindir}/sudo-users/vyatta-interfaces.pl + +# rm symlink for sendmail that was added by ssmtp package +rm -f /usr/sbin/sendmail diff --git a/scripts/vyatta-op-dns-forwarding.pl b/scripts/vyatta-op-dns-forwarding.pl new file mode 100644 index 0000000..24a64e6 --- /dev/null +++ b/scripts/vyatta-op-dns-forwarding.pl @@ -0,0 +1,245 @@ +#!/usr/bin/perl +# +# Module: vyatta-op-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 execute op-mode commands for DNS forwarding +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use Getopt::Long; +use VyattaConfig; +use strict; +use warnings; + +my $show_stats_output=""; +my $show_nameservers_output=""; +my $dnsmasq_log='/var/log/dnsmasq.log'; + +sub get_cache_stats { + my ($cache_size, $queries_forwarded, $queries_answered_locally, $entries_inserted, $entries_removed); + + my $grepped_line = `grep 'cache size' $dnsmasq_log`; + my @split_line = split(/\s+/, $grepped_line); + my @temp_split = split(/,/, $split_line[6]); + $cache_size = $temp_split[0]; + @temp_split = split(/\//, $split_line[7]); + $entries_removed = $temp_split[0]; + $entries_inserted = $temp_split[1]; + + $grepped_line = `grep 'queries forwarded' $dnsmasq_log`; + @split_line = split(/\s+/, $grepped_line); + @temp_split = split(/,/, $split_line[6]); + $queries_forwarded = $temp_split[0]; + $queries_answered_locally = $split_line[10]; + + $show_stats_output .= "----------------\n"; + $show_stats_output .= "Cache statistics\n"; + $show_stats_output .= "----------------\n"; + $show_stats_output .= "Cache size: $cache_size\n"; + $show_stats_output .= "Queries forwarded: $queries_forwarded\n"; + $show_stats_output .= "Queries answered locally: $queries_answered_locally\n"; + $show_stats_output .= "Total DNS entries inserted into cache: $entries_inserted\n"; + $show_stats_output .= "DNS entries removed from cache before expiry: $entries_removed\n"; + +} + +sub get_nameserver_stats { + + $show_stats_output .= "\n---------------------\n"; + $show_stats_output .= "Nameserver statistics\n"; + $show_stats_output .= "---------------------\n"; + + my @grepped_lines = `grep ': server' $dnsmasq_log`; + + foreach my $lines (@grepped_lines) { + my @each_line = split(/\s+/, $lines); + my $nameserver_word = $each_line[5]; + my @nameserver_split = split(/#/, $nameserver_word); + my $nameserver = $nameserver_split[0]; + my $queries_sent_word = $each_line[8]; + my @queries_sent_split = split(/,/, $queries_sent_word); + my $queries_sent = $queries_sent_split[0]; + my $queries_retried_failed = $each_line[12]; + + $show_stats_output .= "Server: $nameserver\nQueries sent: $queries_sent\nQueries retried or failed: $queries_retried_failed\n\n"; + + } +} + +sub print_stats { + print $show_stats_output; +} + +sub get_dns_nameservers { + my $vyatta_config = new VyattaConfig; + + $vyatta_config->setLevel("service dns forwarding"); + $vyatta_config->{_active_dir_base} = "/opt/vyatta/config/active/"; + my $use_system_nameservers = $vyatta_config->existsOrig("system"); + my @use_dhcp_nameservers = $vyatta_config->returnOrigValues("dhcp"); + my @use_nameservers = $vyatta_config->returnOrigValues("name-server"); + my @resolv_conf_nameservers = `grep "^nameserver" /etc/resolv.conf`; + my @dnsmasq_conf_nameservers = `grep "server=" /etc/dnsmasq.conf`; + my @dnsmasq_running = `ps ax | grep dnsmasq | grep -v grep`; + + if (!(defined $use_system_nameservers) && (@use_dhcp_nameservers == 0) && (@use_nameservers == 0)) { + + # no specific nameservers specified under DNS forwarding, so dnsmasq is getting nameservers from /etc/resolv.conf + + if (! @resolv_conf_nameservers > 0){ + $show_nameservers_output .= "No DNS servers present to forward queries to.\n"; + if (! @dnsmasq_running > 0){ + $show_nameservers_output .= "DNS forwarding has not been configured either.\n"; + } + } else { + if (! @dnsmasq_running > 0){ + $show_nameservers_output .= "\n**DNS forwarding has not been configured**\n\n"; + } + $show_nameservers_output .= "-----------------------------------------------\n"; + if ( @dnsmasq_running > 0){ + $show_nameservers_output .= " Nameservers configured for DNS forwarding\n"; + } else { + $show_nameservers_output .= " Nameservers NOT configured for DNS forwarding\n"; + } + $show_nameservers_output .= "-----------------------------------------------\n"; + foreach my $line (@resolv_conf_nameservers) { + my @split_line = split(/\s+/, $line); + my $nameserver = $split_line[1]; + my $nameserver_via = "system"; + if (@split_line > 2) { + my @dhclient_resolv_files = `ls /etc/resolv.conf.dhclient-new-*`; + foreach my $each_dhcp_resolv_conf (@dhclient_resolv_files) { + my @ns_dhclient_resolv=`grep "$nameserver\$" $each_dhcp_resolv_conf`; + if ( @ns_dhclient_resolv > 0) { + my @dhclient_file_array = split(/-/, $each_dhcp_resolv_conf); + $nameserver_via = $dhclient_file_array[2]; + chomp $nameserver_via; + $nameserver_via = 'dhcp ' . $nameserver_via; + } + } + } + $show_nameservers_output .= "$nameserver available via '$nameserver_via'\n"; + } + } + $show_nameservers_output .= "\n"; + } else { + + # nameservers specified under DNS forwarding, so dnsmasq getting nameservers from /etc/dnsmasq.conf + + my @active_nameservers; + my $active_nameserver_count = 0; + $show_nameservers_output .= "-----------------------------------------------\n"; + $show_nameservers_output .= " Nameservers configured for DNS forwarding\n"; + $show_nameservers_output .= "-----------------------------------------------\n"; + foreach my $line (@dnsmasq_conf_nameservers) { + my @split_line = split(/=/, $line); + my @nameserver_array = split(/\s+/, $split_line[1]); + my $nameserver = $nameserver_array[0]; + $active_nameservers[$active_nameserver_count] = $nameserver; + $active_nameserver_count++; + my $nameserver_via = $nameserver_array[2]; + if (@nameserver_array > 3){ + my $dhcp_interface = $nameserver_array[3]; + $show_nameservers_output .= "$nameserver available via '$nameserver_via $dhcp_interface'\n"; + } else { + $show_nameservers_output .= "$nameserver available via '$nameserver_via'\n"; + } + } + + # then you need to get nameservers from /etc/resolv.conf that are not in dnsmasq.conf to show them as inactive + + my $active_dnsmasq_nameserver; + my $output_inactive_nameservers = 0; + foreach my $resolv_conf_line (@resolv_conf_nameservers) { + my @resolv_conf_split_line = split(/\s+/, $resolv_conf_line); + my $resolv_conf_nameserver = $resolv_conf_split_line[1]; + $active_dnsmasq_nameserver = 0; + my $resolv_nameserver_via = "system"; + foreach my $dnsmasq_nameserver (@active_nameservers) { + if ($dnsmasq_nameserver eq $resolv_conf_nameserver) { + $active_dnsmasq_nameserver = 1; + } + } + if ($active_dnsmasq_nameserver == 0) { + if ($output_inactive_nameservers == 0){ + $output_inactive_nameservers = 1; + $show_nameservers_output .= "\n-----------------------------------------------\n"; + $show_nameservers_output .= " Nameservers NOT configured for DNS forwarding\n"; + $show_nameservers_output .= "-----------------------------------------------\n"; + } + if (@resolv_conf_split_line > 2) { + my @dhclient_resolv_files = `ls /etc/resolv.conf.dhclient-new-*`; + foreach my $each_dhcp_resolv_conf (@dhclient_resolv_files) { + chomp $each_dhcp_resolv_conf; + my @ns_dhclient_resolv=`grep "$resolv_conf_nameserver\$" $each_dhcp_resolv_conf`; + if ( @ns_dhclient_resolv > 0) { + my @dhclient_file_array = split(/-/, $each_dhcp_resolv_conf); + $resolv_nameserver_via = $dhclient_file_array[2]; + chomp $resolv_nameserver_via; + $resolv_nameserver_via = 'dhcp ' . $resolv_nameserver_via; + } + } + } + + $show_nameservers_output .= "$resolv_conf_nameserver available via '$resolv_nameserver_via'\n"; + } + } + $show_nameservers_output .= "\n"; + } +} + +sub print_nameservers { + print $show_nameservers_output; +} + +# +# main +# +my ($clear_cache, $clear_all, $show_statistics, $show_nameservers); + +GetOptions("clear-cache!" => \$clear_cache, + "clear-all!" => \$clear_all, + "show-statistics!" => \$show_statistics, + "show-nameservers!" => \$show_nameservers); + +if (defined $clear_cache) { + system("kill -1 `pidof dnsmasq`"); +} + +if (defined $clear_all) { + system("/etc/init.d/dnsmasq restart >&/dev/null"); +} + +if (defined $show_statistics) { + system("echo > /var/log/dnsmasq.log; kill -10 `pidof dnsmasq`"); + get_cache_stats; + get_nameserver_stats; + print_stats; +} + +if (defined $show_nameservers) { + get_dns_nameservers; + print_nameservers; +} + +exit 0; + +# end of file diff --git a/scripts/vyatta-op-dynamic-dns.pl b/scripts/vyatta-op-dynamic-dns.pl new file mode 100644 index 0000000..b6460f5 --- /dev/null +++ b/scripts/vyatta-op-dynamic-dns.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# Module: vyatta-op-dynamic-dns.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: September 2008 +# Description: Script to execute op-mode commands for Dynamic DNS +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use Getopt::Long; +use VyattaConfig; +use strict; +use warnings; + +sub print_ddns_stats { + my $ddclient_cache_files = '/var/cache/ddclient/*'; + my @all_cached_entries = `grep "^atime" $ddclient_cache_files 2>/dev/null`; + if (@all_cached_entries > 0){ + foreach my $each_entry (@all_cached_entries) { + my $interface = undef; + if (`ls $ddclient_cache_files | wc -l` == 1) { + my $interface_file = `ls $ddclient_cache_files`; + my @split_on_cache = split(/.cache/, $interface_file); + my @interface_split = split(/_/, $split_on_cache[1]); + $interface = $interface_split[1]; + } else { + my @split_on_cache = split(/.cache:/, $each_entry); + my @interface_split = split(/_/, $split_on_cache[0]); + $interface=$interface_split[1]; + } + print "interface : $interface\n"; + my @split_on_ip = split(/ip=/, $each_entry); + if (@split_on_ip > 1){ + my @ip = split(/,/, $split_on_ip[1]); + print "ip address : $ip[0]\n"; + } + my @split_on_host = split(/host=/, $each_entry); + my @host = split(/,/, $split_on_host[1]); + print "host-name : $host[0]\n"; + my @split_on_atime = split(/atime=/, $each_entry); + my @atime = split(/,/, $split_on_atime[1]); + my $prettytime = scalar(localtime($atime[0])); + print "last update : $prettytime\n"; + my @split_on_status = split(/status=/, $each_entry); + my @status = split(/,/, $split_on_status[1]); + print "update-status: $status[0]\n"; + print "\n"; + } + } else { + print "Dynamic DNS not configured\n"; + } +} + +sub get_ddns_interfaces { + + my $vyatta_config = new VyattaConfig; + $vyatta_config->setLevel("service dns dynamic"); + $vyatta_config->{_active_dir_base} = "/opt/vyatta/config/active/"; + my @ddns_interfaces = $vyatta_config->listOrigNodes("interface"); + @ddns_interfaces = sort(@ddns_interfaces); + return (@ddns_interfaces); + +} + +# +# main +# + +my ($show_status, $update_ddns, $interface, $show_interfaces); + +GetOptions("show-status!" => \$show_status, + "update-ddns!" => \$update_ddns, + "interface=s" => \$interface, + "show-interfaces!" => \$show_interfaces); + +if (defined $show_status) { + print_ddns_stats; +} + +if (defined $update_ddns && defined $interface) { + my @ddns_interfaces = get_ddns_interfaces(); + my $interface_configured = 0; + foreach my $ddns_interface (@ddns_interfaces) { + if ($ddns_interface eq $interface) { + $interface_configured = 1; + } + } + if ($interface_configured == 1) { + system("sudo /opt/vyatta/sbin/vyatta-dynamic-dns.pl --op-mode-update-dynamicdns --interface $interface"); + } else { + print "$interface has not been configured to send Dynamic DNS updates\n"; + } +} + +if (defined $show_interfaces) { + my @ddns_interfaces = get_ddns_interfaces(); + print "@ddns_interfaces\n"; +} + +exit 0; + +# end of file diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl index 7e76fa6..1e4038c 100755 --- a/scripts/vyatta-show-interfaces.pl +++ b/scripts/vyatta-show-interfaces.pl @@ -333,7 +333,7 @@ sub run_clear_intf { print $FILE $clear_file_magic, "\n", time(), "\n"; my ($var, $val); while (($var, $val) = each (%stats)) { - print $FILE $var, ",", $val; + print $FILE $var, ",", $val, "\n"; } close($FILE); } diff --git a/templates/add/node.def b/templates/add/node.def new file mode 100644 index 0000000..39ff67a --- /dev/null +++ b/templates/add/node.def @@ -0,0 +1 @@ +help: Add an object to a service diff --git a/templates/add/raid/node.def b/templates/add/raid/node.def new file mode 100644 index 0000000..26cc4a3 --- /dev/null +++ b/templates/add/raid/node.def @@ -0,0 +1 @@ +help: Add a RAID set element diff --git a/templates/add/raid/node.tag/member/node.def b/templates/add/raid/node.tag/member/node.def new file mode 100644 index 0000000..efa1d45 --- /dev/null +++ b/templates/add/raid/node.tag/member/node.def @@ -0,0 +1 @@ +help: Add a member to a RAID set
\ No newline at end of file diff --git a/templates/add/raid/node.tag/member/node.tag/node.def b/templates/add/raid/node.tag/member/node.tag/node.def new file mode 100644 index 0000000..60eff63 --- /dev/null +++ b/templates/add/raid/node.tag/member/node.tag/node.def @@ -0,0 +1,38 @@ +help: Name of RAID set member to add + +allowed: + raid_set=${COMP_WORDS[2]} + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + membership=`echo $membership | sed -e 's/(F)//g'` + partitions=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep "[0-9]"` + for member in $membership; do + partitions=`echo $partitions | sed -e s/$member//g` + done + partitions=`echo $partitions | sed -e 's/md[0-9]*//g'` + echo "$partitions" + +run: + raid_set=$3 + member_to_add=$5 + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + is_in=`echo $membership | grep $member_to_add` + + partitions=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep "[0-9]"` + partitions=`echo $partitions | sed -e 's/md[0-9]*//g'` + valid_partition=`echo $partitions | grep $member_to_add` + + if [ -z "$membership" ]; then + echo "$raid_set is not a RAID set" + elif [ -n "$is_in" ]; then + echo "$member_to_add is already a member of RAID set $raid_set" + echo "actual members are: $membership" + elif [ -z "$valid_partition" ]; then + echo "$member_to_add is not a valid disk partition" + else + echo "adding member $member_to_add to RAID set $raid_set" + mdadm /dev/$raid_set --add /dev/$member_to_add + if [ $? -ne 0 ]; then + echo "Unable to add member to RAID set" + fi + fi + diff --git a/templates/add/raid/node.tag/node.def b/templates/add/raid/node.tag/node.def new file mode 100644 index 0000000..e0ae4d9 --- /dev/null +++ b/templates/add/raid/node.tag/node.def @@ -0,0 +1,6 @@ +help: Name of RAID set to add object to + +allowed: + local -a array ; + array=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $array diff --git a/templates/clear/dns/forwarding/all/node.def b/templates/clear/dns/forwarding/all/node.def new file mode 100644 index 0000000..b439b78 --- /dev/null +++ b/templates/clear/dns/forwarding/all/node.def @@ -0,0 +1,8 @@ +help: Clear DNS forwarding cache and counters +run: + if ps ax | grep dnsmasq | grep -v grep > /dev/null + then + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --clear-all + else + echo "DNS forwarding not configured" + fi diff --git a/templates/clear/dns/forwarding/cache/node.def b/templates/clear/dns/forwarding/cache/node.def new file mode 100644 index 0000000..8a5f8cc --- /dev/null +++ b/templates/clear/dns/forwarding/cache/node.def @@ -0,0 +1,8 @@ +help: Clear DNS forwarding cache +run: + if ps ax | grep dnsmasq | grep -v grep > /dev/null + then + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --clear-cache + else + echo "DNS forwarding not configured" + fi diff --git a/templates/clear/dns/forwarding/node.def b/templates/clear/dns/forwarding/node.def new file mode 100644 index 0000000..3cc321c --- /dev/null +++ b/templates/clear/dns/forwarding/node.def @@ -0,0 +1 @@ +help: Clear DNS forwarding variables diff --git a/templates/clear/dns/node.def b/templates/clear/dns/node.def new file mode 100644 index 0000000..bca966e --- /dev/null +++ b/templates/clear/dns/node.def @@ -0,0 +1 @@ +help: Clear Domain Name Server (DNS) variables diff --git a/templates/format/disk/node.def b/templates/format/disk/node.def new file mode 100644 index 0000000..664804b --- /dev/null +++ b/templates/format/disk/node.def @@ -0,0 +1 @@ +help: Format a disk drive
\ No newline at end of file diff --git a/templates/format/disk/node.tag/like/node.def b/templates/format/disk/node.tag/like/node.def new file mode 100644 index 0000000..99f73b1 --- /dev/null +++ b/templates/format/disk/node.tag/like/node.def @@ -0,0 +1 @@ +help: Format this disk the same as another disk
\ No newline at end of file diff --git a/templates/format/disk/node.tag/like/node.tag/node.def b/templates/format/disk/node.tag/like/node.tag/node.def new file mode 100644 index 0000000..8927dc8 --- /dev/null +++ b/templates/format/disk/node.tag/like/node.tag/node.def @@ -0,0 +1,59 @@ +help: Name of disk drive to partition it like + +allowed: + local -a disks ; + proto_disk=${COMP_WORDS[2]} + disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + disks=`echo $disks | sed -e s/$proto_disk//g` + echo -n $disks + +run: + proto_disk=$5 + format_disk=$3 + backup_dir=/var/log/vyatta + eligible_format_disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + eligible_proto_disks=`echo $eligible_format_disks | sed -e s/$format_disk//g` + proto_eligible=`echo $eligible_proto_disks | grep $proto_disk` + format_eligible=`echo $eligible_format_disks | grep $format_disk` + busy_check=`sfdisk -R /dev/$format_disk 2>&1` + + if [ $proto_disk = $format_disk ]; then + echo "The two disk drives must be different." + elif [ ! -b /dev/$proto_disk ]; then + echo "Device /dev/$proto_disk does not exist" + elif [ ! -b /dev/$format_disk ]; then + echo "Device /dev/$format_disk does not exist" + elif [ -z "$format_eligible" ]; then + echo "Device $format_disk can not be formatted" + elif [ -z "$proto_eligible" ]; then + echo "Device $proto_disk can not be used as a prototype for $format_disk" + elif [ -n "$busy_check" ]; then + echo "Disk device $format_disk is busy. Can't format it now." + else + echo "This will re-format disk $format_disk so that it has the same disk" + echo "partion sizes and offsets as $proto_disk. This will not copy" + echo "data from $proto_disk to $format_disk. But this will erase all" + echo "data on $format_disk." + echo + echo -n "Do you wish to proceed (yes, NO)? " + read response + if [ "$response" = "yes" ]; then + echo "OK. Re-formating disk drive $format_disk..." + echo "Making backup copy of partitions..." + sfdisk -d /dev/$format_disk > $backup_dir/backup_$format_disk.`date +%F-%R` + sleep 1 + partitions=`cat /proc/partitions | grep $format_disk'[0-9]' | awk '{ print $4 }' | sed 's/[a-z]//g'` + if [ -n "$partitions" ]; then + echo -n "Deleting old partitions..." + for part in $partitions ; do + parted /dev/$format_disk rm $part + done + echo "" + fi + echo "Creating new partitions on $format_disk based on $proto_disk..." + sfdisk -d /dev/$proto_disk | sfdisk --force /dev/$format_disk + echo "Done." + else + echo "OK. Disk drive $format_drive will not be re-formated." + fi + fi
\ No newline at end of file diff --git a/templates/format/disk/node.tag/node.def b/templates/format/disk/node.tag/node.def new file mode 100644 index 0000000..2b77c5b --- /dev/null +++ b/templates/format/disk/node.tag/node.def @@ -0,0 +1,6 @@ +help: Disk drive name + +allowed: + local -a array ; + array=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + echo -n $array diff --git a/templates/format/node.def b/templates/format/node.def new file mode 100644 index 0000000..edb71bd --- /dev/null +++ b/templates/format/node.def @@ -0,0 +1 @@ +help: Format a device
\ No newline at end of file diff --git a/templates/release/dhcp/interface/node.tag/node.def b/templates/release/dhcp/interface/node.tag/node.def index 2fadea2..85773b6 100644 --- a/templates/release/dhcp/interface/node.tag/node.def +++ b/templates/release/dhcp/interface/node.tag/node.def @@ -1,7 +1,7 @@ help: Release DHCP IP address lease for specified interface allowed: local -a array ; - array=( /var/lib/dhcp3/eth* ) ; + array=( /var/lib/dhcp3/eth* /var/lib/dhcp3/br* ) ; echo -n ${array[@]##*/} run: diff --git a/templates/remove/node.def b/templates/remove/node.def new file mode 100644 index 0000000..387e0d2 --- /dev/null +++ b/templates/remove/node.def @@ -0,0 +1 @@ +help: Remove an object from service diff --git a/templates/remove/raid/node.def b/templates/remove/raid/node.def new file mode 100644 index 0000000..2700b93 --- /dev/null +++ b/templates/remove/raid/node.def @@ -0,0 +1 @@ +help: Remove a RAID set element diff --git a/templates/remove/raid/node.tag/member/node.def b/templates/remove/raid/node.tag/member/node.def new file mode 100644 index 0000000..6af665d --- /dev/null +++ b/templates/remove/raid/node.tag/member/node.def @@ -0,0 +1 @@ +help: Remove a member of a RAID set
\ No newline at end of file diff --git a/templates/remove/raid/node.tag/member/node.tag/node.def b/templates/remove/raid/node.tag/member/node.tag/node.def new file mode 100644 index 0000000..d384fd3 --- /dev/null +++ b/templates/remove/raid/node.tag/member/node.tag/node.def @@ -0,0 +1,35 @@ +help: Name of RAID set member to remove + +allowed: + raid_set=${COMP_WORDS[2]} + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + membership=`echo $membership | sed -e 's/(F)//g'` + echo "$membership" + +run: + raid_set=$3 + member_to_remove=$5 + membership=`cat /proc/mdstat | grep $raid_set | sed -e 's/\[.\]//g' | awk '{ print $5 " " $6 }'` + num_members=`echo $membership | wc -w` + is_in=`echo $membership | grep $member_to_remove` + + if [ -z "$membership" ]; then + echo "$raid_set is not a RAID set" + elif [ -z "$is_in" ]; then + echo "$member_to_remove is not a member of RAID set $raid_set" + echo "actual members are: $membership" + elif [ "$num_members" -eq "1" ]; then + echo "Can't remove last member of a RAID set" + else + echo "removing member $member from RAID set $raid_set" + mdadm /dev/$raid_set --fail /dev/$member_to_remove + if [ $? -ne 0 ]; then + echo "Unable to mark member as failed" + else + sleep 1 + mdadm /dev/$raid_set --remove /dev/$member_to_remove + if [ $? -ne 0 ]; then + echo "Unable to remove member from RAID set" + fi + fi + fi diff --git a/templates/remove/raid/node.tag/node.def b/templates/remove/raid/node.tag/node.def new file mode 100644 index 0000000..a8d8485 --- /dev/null +++ b/templates/remove/raid/node.tag/node.def @@ -0,0 +1,6 @@ +help: Name of RAID set to remove object from + +allowed: + local -a array ; + array=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $array diff --git a/templates/renew/dhcp/interface/node.tag/node.def b/templates/renew/dhcp/interface/node.tag/node.def index 9952a49..9e6c037 100644 --- a/templates/renew/dhcp/interface/node.tag/node.def +++ b/templates/renew/dhcp/interface/node.tag/node.def @@ -1,7 +1,7 @@ help: Renew DHCP IP address lease for specified interface allowed: local -a array ; - array=( /var/lib/dhcp3/eth* ) ; + array=( /var/lib/dhcp3/eth* /var/lib/dhcp3/br* ) ; echo -n ${array[@]##*/} run: diff --git a/templates/show/disk/node.def b/templates/show/disk/node.def new file mode 100644 index 0000000..8572a9f --- /dev/null +++ b/templates/show/disk/node.def @@ -0,0 +1 @@ +help: Show status of disk device diff --git a/templates/show/disk/node.tag/format/node.def b/templates/show/disk/node.tag/format/node.def new file mode 100644 index 0000000..e05b4ad --- /dev/null +++ b/templates/show/disk/node.tag/format/node.def @@ -0,0 +1,12 @@ +help: Show disk drive formatting + +run: + disk_dev=$3 + valid_disks=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + is_a_disk=`echo $valid_disks | grep $disk_dev` + + if [ -z "$is_a_disk" ]; then + echo "$disk_dev is not a disk device" + else + fdisk -l /dev/${disk_dev} + fi diff --git a/templates/show/disk/node.tag/node.def b/templates/show/disk/node.tag/node.def new file mode 100644 index 0000000..7e4fe05 --- /dev/null +++ b/templates/show/disk/node.tag/node.def @@ -0,0 +1,7 @@ +help: Disk device name + +allowed: + local -a array ; + array=`cat /proc/partitions | awk '{ if ($4!="name") { print $4 } }' | egrep -v "[0-9]"` + echo -n $array + diff --git a/templates/show/dns/dynamic/node.def b/templates/show/dns/dynamic/node.def new file mode 100644 index 0000000..9a06b38 --- /dev/null +++ b/templates/show/dns/dynamic/node.def @@ -0,0 +1 @@ +help: Show Dynamic DNS information diff --git a/templates/show/dns/dynamic/status/node.def b/templates/show/dns/dynamic/status/node.def new file mode 100644 index 0000000..870c883 --- /dev/null +++ b/templates/show/dns/dynamic/status/node.def @@ -0,0 +1,3 @@ +help: Show Dynamic DNS status +run: + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --show-status diff --git a/templates/show/dns/forwarding/nameservers/node.def b/templates/show/dns/forwarding/nameservers/node.def new file mode 100644 index 0000000..0609f6a --- /dev/null +++ b/templates/show/dns/forwarding/nameservers/node.def @@ -0,0 +1,2 @@ +help: Show DNS forwarding nameservers information +run: sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --show-nameservers diff --git a/templates/show/dns/forwarding/node.def b/templates/show/dns/forwarding/node.def new file mode 100644 index 0000000..eb9ce4b --- /dev/null +++ b/templates/show/dns/forwarding/node.def @@ -0,0 +1 @@ +help: Show DNS forwarding information diff --git a/templates/show/dns/forwarding/statistics/node.def b/templates/show/dns/forwarding/statistics/node.def new file mode 100644 index 0000000..a73b49d --- /dev/null +++ b/templates/show/dns/forwarding/statistics/node.def @@ -0,0 +1,8 @@ +help: Show DNS forwarding statistics +run: + if ps ax | grep dnsmasq | grep -v grep > /dev/null + then + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --show-statistics + else + echo "DNS forwarding not configured" + fi diff --git a/templates/show/dns/node.def b/templates/show/dns/node.def new file mode 100644 index 0000000..45d0e4f --- /dev/null +++ b/templates/show/dns/node.def @@ -0,0 +1 @@ +help: Show Domain Name Server (DNS) information diff --git a/templates/show/raid/node.def b/templates/show/raid/node.def new file mode 100644 index 0000000..d0ec96d --- /dev/null +++ b/templates/show/raid/node.def @@ -0,0 +1,2 @@ +help: Show status of RAID set + diff --git a/templates/show/raid/node.tag/node.def b/templates/show/raid/node.tag/node.def new file mode 100644 index 0000000..bc83a73 --- /dev/null +++ b/templates/show/raid/node.tag/node.def @@ -0,0 +1,16 @@ +help: RAID set name + +allowed: + local -a raid_sets ; + raid_sets=`cat /proc/partitions | grep md | awk '{ print $4 }'` + echo -n $raid_sets + +run: + raid_set_name=$3 + raid_sets=`cat /proc/partitions | grep md | awk '{ print $4 }'` + valid_set=`echo $raid_sets | grep $raid_set_name` + if [ -z $valid_set ]; then + echo "$raid_set_name is not a RAID set" + else + mdadm --detail /dev/${raid_set_name} + fi
\ No newline at end of file diff --git a/templates/update/dns/dynamic/interface/node.def b/templates/update/dns/dynamic/interface/node.def new file mode 100644 index 0000000..c0ef660 --- /dev/null +++ b/templates/update/dns/dynamic/interface/node.def @@ -0,0 +1 @@ +help: Update Dynamic DNS for specified interface diff --git a/templates/update/dns/dynamic/interface/node.tag/node.def b/templates/update/dns/dynamic/interface/node.tag/node.def new file mode 100644 index 0000000..60fb67d --- /dev/null +++ b/templates/update/dns/dynamic/interface/node.tag/node.def @@ -0,0 +1,6 @@ +help: Update Dynamic DNS for specified interface +allowed: + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --show-interfaces +run: + IFNAME=${5} + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --update-ddns --interface "$IFNAME" diff --git a/templates/update/dns/dynamic/node.def b/templates/update/dns/dynamic/node.def new file mode 100644 index 0000000..447fcb5 --- /dev/null +++ b/templates/update/dns/dynamic/node.def @@ -0,0 +1 @@ +help: Update Dynamic DNS information diff --git a/templates/update/dns/node.def b/templates/update/dns/node.def new file mode 100644 index 0000000..b8217f6 --- /dev/null +++ b/templates/update/dns/node.def @@ -0,0 +1 @@ +help: Update DNS information |