From 27607276527af5bbee1c07fd1967a5de8069b12d Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 10 Dec 2007 14:23:41 -0800 Subject: fix for bug 2527: add wrappers for boot-messages commands. --- Makefile.am | 3 ++- scripts/vyatta-show-dmesg | 4 ++++ templates/show/system/boot-messages/all/node.def | 2 +- templates/show/system/boot-messages/node.def | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100755 scripts/vyatta-show-dmesg diff --git a/Makefile.am b/Makefile.am index ac4aa61..c9849cb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,12 +12,13 @@ alloweddir = $(datadir)/vyatta-op/functions/allowed allowed_DATA = functions/allowed/hosts bin_SCRIPTS = scripts/vyatta-show-interfaces -bin_SCRIPTS += scripts/vyatta-show-dmesg-all bin_SCRIPTS += scripts/vyatta-show-version bin_sudo_users_SCRIPTS = scripts/vyatta-show-log bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-all bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-file +bin_sudo_users_SCRIPTS += scripts/vyatta-show-dmesg +bin_sudo_users_SCRIPTS += scripts/vyatta-show-dmesg-all cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/scripts/vyatta-show-dmesg b/scripts/vyatta-show-dmesg new file mode 100755 index 0000000..8a53a94 --- /dev/null +++ b/scripts/vyatta-show-dmesg @@ -0,0 +1,4 @@ +#!/bin/bash + +cat /var/log/dmes? /dev/null + diff --git a/templates/show/system/boot-messages/all/node.def b/templates/show/system/boot-messages/all/node.def index b151fc2..df6795f 100644 --- a/templates/show/system/boot-messages/all/node.def +++ b/templates/show/system/boot-messages/all/node.def @@ -1,2 +1,2 @@ help: Show all kernel boot messages -run: ${vyatta_bindir}/vyatta-show-dmesg-all +run: sudo ${vyatta_bindir}/sudo-users/vyatta-show-dmesg-all diff --git a/templates/show/system/boot-messages/node.def b/templates/show/system/boot-messages/node.def index fb24eeb..b2c25e3 100644 --- a/templates/show/system/boot-messages/node.def +++ b/templates/show/system/boot-messages/node.def @@ -1,2 +1,2 @@ help: Show most recent kernel boot messages -run: cat /var/log/dmes? /dev/null +run: sudo ${vyatta_bindir}/sudo-users/vyatta-show-dmesg -- cgit v1.2.3 From f6ec442f339611df91a79c770483d0e6b13566ff Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 10 Dec 2007 14:40:58 -0800 Subject: fix for bug 2526: show user's history file and add needed packages for tech-support. --- debian/control | 2 ++ functions/tech-support | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index a5c9b9f..020126d 100644 --- a/debian/control +++ b/debian/control @@ -12,6 +12,8 @@ Depends: bash (>= 3.1), ethtool, ntpdate, procps (>= 1:3.2.7-3), + pciutils, + lsof, coreutils (>= 5.97-5.3) Suggests: util-linux (>= 2.13-5), net-tools, diff --git a/functions/tech-support b/functions/tech-support index 46f5827..ba2f22d 100644 --- a/functions/tech-support +++ b/functions/tech-support @@ -158,8 +158,8 @@ sudo ${vyatta_bindir}/sudo-users/iptables -t raw -L -vn header \''show ip route'\' show ip route -header /root/.bash_history -cat /root/.bash_history +header $HOME/.bash_history +cat $HOME/.bash_history header \''show vrrp'\' show vrrp -- cgit v1.2.3 From 688433f5c3da09c9de19fec8d6217764bb5a036c Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 10 Dec 2007 18:56:21 -0800 Subject: add wrappers/symlinks for pipe commands (wrappers are needed for command matching in restricted modes). --- Makefile.am | 4 ++++ debian/vyatta-op.postinst.in | 4 ++++ debian/vyatta-op.postrm.in | 4 ++++ etc/bash_completion.d/10vyatta-op | 2 -- scripts/count | 4 ++++ scripts/match | 4 ++++ scripts/no-match | 4 ++++ scripts/no-more | 4 ++++ 8 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 scripts/count create mode 100755 scripts/match create mode 100755 scripts/no-match create mode 100755 scripts/no-more diff --git a/Makefile.am b/Makefile.am index c9849cb..82d2a53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,10 @@ allowed_DATA = functions/allowed/hosts bin_SCRIPTS = scripts/vyatta-show-interfaces bin_SCRIPTS += scripts/vyatta-show-version +bin_SCRIPTS += scripts/count +bin_SCRIPTS += scripts/match +bin_SCRIPTS += scripts/no-match +bin_SCRIPTS += scripts/no-more bin_sudo_users_SCRIPTS = scripts/vyatta-show-log bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-all diff --git a/debian/vyatta-op.postinst.in b/debian/vyatta-op.postinst.in index 4f0b3b4..626ace2 100644 --- a/debian/vyatta-op.postinst.in +++ b/debian/vyatta-op.postinst.in @@ -8,4 +8,8 @@ bindir=@bindir@ ln -sf /usr/sbin/ethtool ${bindir}/sudo-users/ethtool ln -sf /usr/sbin/dmidecode ${bindir}/sudo-users/dmidecode ln -sf /sbin/iptables ${bindir}/sudo-users/iptables +ln -sf ${bindir}/count /usr/bin/ +ln -sf ${bindir}/match /usr/bin/ +ln -sf ${bindir}/no-match /usr/bin/ +ln -sf ${bindir}/no-more /usr/bin/ diff --git a/debian/vyatta-op.postrm.in b/debian/vyatta-op.postrm.in index f86a7ba..34f21ed 100644 --- a/debian/vyatta-op.postrm.in +++ b/debian/vyatta-op.postrm.in @@ -9,5 +9,9 @@ if [ "$1" = "purge" ]; then rm -f ${bindir}/sudo-users/ethtool rm -f ${bindir}/sudo-users/dmidecode rm -f ${bindir}/sudo-users/iptables + rm -f /usr/bin/count + rm -f /usr/bin/match + rm -f /usr/bin/no-match + rm -f /usr/bin/no-more fi diff --git a/etc/bash_completion.d/10vyatta-op b/etc/bash_completion.d/10vyatta-op index 5a672c3..52be05a 100644 --- a/etc/bash_completion.d/10vyatta-op +++ b/etc/bash_completion.d/10vyatta-op @@ -304,8 +304,6 @@ done eval $nullglob_save unset nullglob_save -alias no-more=cat - _vyatta_op_init $@ ### Local Variables: diff --git a/scripts/count b/scripts/count new file mode 100755 index 0000000..1ab3796 --- /dev/null +++ b/scripts/count @@ -0,0 +1,4 @@ +#!/bin/bash + +wc -l "$@" + diff --git a/scripts/match b/scripts/match new file mode 100755 index 0000000..c452824 --- /dev/null +++ b/scripts/match @@ -0,0 +1,4 @@ +#!/bin/bash + +grep -E -e "$@" + diff --git a/scripts/no-match b/scripts/no-match new file mode 100755 index 0000000..528d80c --- /dev/null +++ b/scripts/no-match @@ -0,0 +1,4 @@ +#!/bin/bash + +grep -E -v -e "$@" + diff --git a/scripts/no-more b/scripts/no-more new file mode 100755 index 0000000..59f51e8 --- /dev/null +++ b/scripts/no-more @@ -0,0 +1,4 @@ +#!/bin/bash + +cat "$@" + -- cgit v1.2.3 From 4a26e01aedbbee2092a0d3c547cb2061d2305a6d Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 11 Dec 2007 10:24:56 -0800 Subject: implement "pipe" commands as functions --- Makefile.am | 4 ---- debian/vyatta-op.postinst.in | 4 ---- debian/vyatta-op.postrm.in | 4 ---- etc/bash_completion.d/10vyatta-op | 21 +++++++++++++++++++++ scripts/count | 4 ---- scripts/match | 4 ---- scripts/no-match | 4 ---- scripts/no-more | 4 ---- 8 files changed, 21 insertions(+), 28 deletions(-) delete mode 100755 scripts/count delete mode 100755 scripts/match delete mode 100755 scripts/no-match delete mode 100755 scripts/no-more diff --git a/Makefile.am b/Makefile.am index 82d2a53..c9849cb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,10 +13,6 @@ allowed_DATA = functions/allowed/hosts bin_SCRIPTS = scripts/vyatta-show-interfaces bin_SCRIPTS += scripts/vyatta-show-version -bin_SCRIPTS += scripts/count -bin_SCRIPTS += scripts/match -bin_SCRIPTS += scripts/no-match -bin_SCRIPTS += scripts/no-more bin_sudo_users_SCRIPTS = scripts/vyatta-show-log bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-all diff --git a/debian/vyatta-op.postinst.in b/debian/vyatta-op.postinst.in index 626ace2..4f0b3b4 100644 --- a/debian/vyatta-op.postinst.in +++ b/debian/vyatta-op.postinst.in @@ -8,8 +8,4 @@ bindir=@bindir@ ln -sf /usr/sbin/ethtool ${bindir}/sudo-users/ethtool ln -sf /usr/sbin/dmidecode ${bindir}/sudo-users/dmidecode ln -sf /sbin/iptables ${bindir}/sudo-users/iptables -ln -sf ${bindir}/count /usr/bin/ -ln -sf ${bindir}/match /usr/bin/ -ln -sf ${bindir}/no-match /usr/bin/ -ln -sf ${bindir}/no-more /usr/bin/ diff --git a/debian/vyatta-op.postrm.in b/debian/vyatta-op.postrm.in index 34f21ed..f86a7ba 100644 --- a/debian/vyatta-op.postrm.in +++ b/debian/vyatta-op.postrm.in @@ -9,9 +9,5 @@ if [ "$1" = "purge" ]; then rm -f ${bindir}/sudo-users/ethtool rm -f ${bindir}/sudo-users/dmidecode rm -f ${bindir}/sudo-users/iptables - rm -f /usr/bin/count - rm -f /usr/bin/match - rm -f /usr/bin/no-match - rm -f /usr/bin/no-more fi diff --git a/etc/bash_completion.d/10vyatta-op b/etc/bash_completion.d/10vyatta-op index 52be05a..d5ea362 100644 --- a/etc/bash_completion.d/10vyatta-op +++ b/etc/bash_completion.d/10vyatta-op @@ -291,6 +291,27 @@ _vyatta_op_run () return $ret } +# "pipe" functions +count () +{ + wc -l "$@" +} + +match () +{ + grep -E -e "$@" +} + +no-match () +{ + grep -E -v -e "$@" +} + +no-more () +{ + cat "$@" +} + # don't initialize if we are in configure mode if [ "$_OFR_CONFIGURE" == "ok" ]; then return 0 diff --git a/scripts/count b/scripts/count deleted file mode 100755 index 1ab3796..0000000 --- a/scripts/count +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -wc -l "$@" - diff --git a/scripts/match b/scripts/match deleted file mode 100755 index c452824..0000000 --- a/scripts/match +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -grep -E -e "$@" - diff --git a/scripts/no-match b/scripts/no-match deleted file mode 100755 index 528d80c..0000000 --- a/scripts/no-match +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -grep -E -v -e "$@" - diff --git a/scripts/no-more b/scripts/no-more deleted file mode 100755 index 59f51e8..0000000 --- a/scripts/no-more +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -cat "$@" - -- cgit v1.2.3 From 91b5edcde0529830306bad473b2a53db3171106d Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 11 Dec 2007 18:53:11 -0800 Subject: add completion/help for pipe commands --- etc/bash_completion.d/10vyatta-op | 91 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/etc/bash_completion.d/10vyatta-op b/etc/bash_completion.d/10vyatta-op index d5ea362..d9cf8d7 100644 --- a/etc/bash_completion.d/10vyatta-op +++ b/etc/bash_completion.d/10vyatta-op @@ -44,6 +44,7 @@ declare -r _vyatta_op_last_comp_init='>>>>>>LASTCOMP<<<<<<' declare _vyatta_op_last_comp=${_vyatta_op_last_comp_init} declare _vyatta_op_node_path declare -a _vyatta_op_noncompletions _vyatta_op_completions +declare -x -a _vyatta_pipe_noncompletions _vyatta_pipe_completions # $1: label # #2...: strings @@ -214,6 +215,19 @@ _vyatta_op_expand () (( COMP_CWORD = ${#COMP_WORDS[@]} )) fi + if _vyatta_pipe_completion "${COMP_WORDS[@]}"; then + if [ "${COMP_WORDS[*]}" == "$_vyatta_op_last_comp" ] ; then + _vyatta_do_pipe_help + COMPREPLY=( "" " " ) + _vyatta_op_last_comp=${_vyatta_op_last_comp_init} + else + COMPREPLY=( "${_vyatta_pipe_completions[@]}" ) + _vyatta_op_last_comp="${COMP_WORDS[*]}" + fi + eval "$restore_shopts" + return + fi + if [ "${COMP_WORDS[*]}" != "$_vyatta_op_last_comp" ] ; then if ! _vyatta_op_set_node_path ; then echo -e \\a @@ -294,22 +308,91 @@ _vyatta_op_run () # "pipe" functions count () { - wc -l "$@" + wc -l } match () { - grep -E -e "$@" + grep -E -e "$1" } no-match () { - grep -E -v -e "$@" + grep -E -v -e "$1" } no-more () { - cat "$@" + cat +} + +# pipe command help +# $1: command +_vyatta_pipe_help () +{ + local help="No help text available" + case "$1" in + count) help="Count the number of lines in the output";; + match) help="Only output lines that match specified pattern";; + no-match) help="Only output lines that do not match specified pattern";; + more) help="Paginate the output";; + no-more) help="Do not paginate the output";; + '') help="Pattern for matching";; + esac + echo -n "$help" +} + +_vyatta_do_pipe_help () +{ + local help='' + if (( ${#_vyatta_pipe_completions[@]} + ${#_vyatta_pipe_noncompletions[@]} + == 0 )); then + return + fi + echo -en "\nPossible completions:" + for comp in "${_vyatta_pipe_completions[@]}" \ + "${_vyatta_pipe_noncompletions[@]}"; do + _vyatta_op_print_help "$comp" "$(_vyatta_pipe_help "$comp")" + done +} + +# pipe completion +# $@: words +_vyatta_pipe_completion () +{ + local -a pipe_cmd=() + local -a all_cmds=( 'count' 'match' 'no-match' 'more' 'no-more' ) + local found=0 + _vyatta_pipe_completions=() + _vyatta_pipe_noncompletions=() + + for word in "$@"; do + if [ "$found" == "1" -o "$word" == "|" ]; then + pipe_cmd+=( "$word" ) + found=1 + fi + done + if (( found == 0 )); then + return 1 + fi + if (( ${#pipe_cmd[@]} == 1 )); then + # "|" only + _vyatta_pipe_completions=( "${all_cmds[@]}" ) + return 0 + fi + if (( ${#pipe_cmd[@]} == 2 )); then + # "|" + _vyatta_pipe_completions=($(compgen -W "${all_cmds[*]}" -- ${pipe_cmd[1]})) + return 0 + fi + if (( ${#pipe_cmd[@]} == 3 )); then + # "|" + case "${pipe_cmd[1]}" in + match|no-match) _vyatta_pipe_noncompletions=( '' );; + esac + return 0 + fi + return 0 } # don't initialize if we are in configure mode -- cgit v1.2.3 From fb94b5aaf0922f656cb9c81d69d10bbcc4dc9091 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Thu, 13 Dec 2007 12:32:29 -0800 Subject: Add "show user", "show arp", and "show host". --- debian/control | 3 ++- templates/show/arp/node.def | 2 ++ templates/show/host/date/node.def | 2 ++ templates/show/host/lookup/node.def | 1 + templates/show/host/lookup/node.tag/node.def | 3 +++ templates/show/host/name/node.def | 2 ++ templates/show/host/node.def | 1 + templates/show/host/os/node.def | 2 ++ templates/show/users/node.def | 2 ++ 9 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 templates/show/arp/node.def create mode 100644 templates/show/host/date/node.def create mode 100644 templates/show/host/lookup/node.def create mode 100644 templates/show/host/lookup/node.tag/node.def create mode 100644 templates/show/host/name/node.def create mode 100644 templates/show/host/node.def create mode 100644 templates/show/host/os/node.def create mode 100644 templates/show/users/node.def diff --git a/debian/control b/debian/control index 020126d..074e6e5 100644 --- a/debian/control +++ b/debian/control @@ -14,7 +14,8 @@ Depends: bash (>= 3.1), procps (>= 1:3.2.7-3), pciutils, lsof, - coreutils (>= 5.97-5.3) + coreutils (>= 5.97-5.3), + host Suggests: util-linux (>= 2.13-5), net-tools, ncurses-bin (>= 5.5-5), diff --git a/templates/show/arp/node.def b/templates/show/arp/node.def new file mode 100644 index 0000000..021f848 --- /dev/null +++ b/templates/show/arp/node.def @@ -0,0 +1,2 @@ +help: Show Address Resolution Protocol Information +run: /usr/sbin/arp -e diff --git a/templates/show/host/date/node.def b/templates/show/host/date/node.def new file mode 100644 index 0000000..6ea4383 --- /dev/null +++ b/templates/show/host/date/node.def @@ -0,0 +1,2 @@ +help: Show host current date +run: /bin/date diff --git a/templates/show/host/lookup/node.def b/templates/show/host/lookup/node.def new file mode 100644 index 0000000..d8368b6 --- /dev/null +++ b/templates/show/host/lookup/node.def @@ -0,0 +1 @@ +help: Lookup host info for host/ipaddress diff --git a/templates/show/host/lookup/node.tag/node.def b/templates/show/host/lookup/node.tag/node.def new file mode 100644 index 0000000..e0dd0df --- /dev/null +++ b/templates/show/host/lookup/node.tag/node.def @@ -0,0 +1,3 @@ +help: Lookup host information for host/ipaddres +allowed: vyatta-allowed-hosts +run: /usr/bin/host $4 diff --git a/templates/show/host/name/node.def b/templates/show/host/name/node.def new file mode 100644 index 0000000..0197d10 --- /dev/null +++ b/templates/show/host/name/node.def @@ -0,0 +1,2 @@ +help: Show host name +run: /bin/hostname diff --git a/templates/show/host/node.def b/templates/show/host/node.def new file mode 100644 index 0000000..65a0694 --- /dev/null +++ b/templates/show/host/node.def @@ -0,0 +1 @@ +help: Show host information diff --git a/templates/show/host/os/node.def b/templates/show/host/os/node.def new file mode 100644 index 0000000..1cfe2ec --- /dev/null +++ b/templates/show/host/os/node.def @@ -0,0 +1,2 @@ +help: Show host operating system details +run: /bin/uname -a diff --git a/templates/show/users/node.def b/templates/show/users/node.def new file mode 100644 index 0000000..6a88319 --- /dev/null +++ b/templates/show/users/node.def @@ -0,0 +1,2 @@ +help: Show user information +run: who -- cgit v1.2.3 From ce1a828a723bd24472f17b27d3ebd9cdcaa2d28e Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 13 Dec 2007 17:15:40 -0800 Subject: workaround for putty's terminal handling --- etc/bash_completion.d/10vyatta-op | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/bash_completion.d/10vyatta-op b/etc/bash_completion.d/10vyatta-op index d9cf8d7..6239302 100644 --- a/etc/bash_completion.d/10vyatta-op +++ b/etc/bash_completion.d/10vyatta-op @@ -31,6 +31,7 @@ test -z "$_vyatta_default_pager" && \ --squeeze-blank-lines\ --buffers=64\ --auto-buffers\ + --no-init\ --no-lessopen" declare -x VYATTA_PAGER=$_vyatta_default_pager -- cgit v1.2.3 From 3b0f0b581c00c7466c36392c89f6edfac5e7e5f1 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 16 Dec 2007 14:59:42 -0800 Subject: Add ethernet bridging show commands. --- templates/show/bridge/node.def | 2 ++ templates/show/bridge/node.tag/macs/node.def | 2 ++ templates/show/bridge/node.tag/node.def | 5 +++++ templates/show/bridge/node.tag/spanning-tree/node.def | 2 ++ 4 files changed, 11 insertions(+) create mode 100644 templates/show/bridge/node.def create mode 100644 templates/show/bridge/node.tag/macs/node.def create mode 100644 templates/show/bridge/node.tag/node.def create mode 100644 templates/show/bridge/node.tag/spanning-tree/node.def diff --git a/templates/show/bridge/node.def b/templates/show/bridge/node.def new file mode 100644 index 0000000..45761f1 --- /dev/null +++ b/templates/show/bridge/node.def @@ -0,0 +1,2 @@ +help: "Show bridging information" +run: sudo brctl show diff --git a/templates/show/bridge/node.tag/macs/node.def b/templates/show/bridge/node.tag/macs/node.def new file mode 100644 index 0000000..4f44832 --- /dev/null +++ b/templates/show/bridge/node.tag/macs/node.def @@ -0,0 +1,2 @@ +help: Show bridge MAC table" +run: sudo brctl showmacs $3 diff --git a/templates/show/bridge/node.tag/node.def b/templates/show/bridge/node.tag/node.def new file mode 100644 index 0000000..d439a03 --- /dev/null +++ b/templates/show/bridge/node.tag/node.def @@ -0,0 +1,5 @@ +help: Show bridge information for a given bridge +allowed: local -a array ; + array=( /sys/class/net/br* ) ; + echo -n ${array[@]##*/} +run: sudo brctl show $3 diff --git a/templates/show/bridge/node.tag/spanning-tree/node.def b/templates/show/bridge/node.tag/spanning-tree/node.def new file mode 100644 index 0000000..2da87a0 --- /dev/null +++ b/templates/show/bridge/node.tag/spanning-tree/node.def @@ -0,0 +1,2 @@ +help: Show bridge spanning tree information" +run: sudo brctl showstp $3 -- cgit v1.2.3