From f3d8a923cbf42966e4de11d0978f2c9518b90cb3 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 16 Nov 2010 15:56:24 -0800 Subject: Add ability to configure telnet listen-addres Bug 4452 Allow configuring a telnet listen-address either IPv4 or IPv6 (like SSH). Unlike SSH, telnet only supports a single listen-address --- scripts/system/vyatta_update_telnet | 2 +- scripts/telnetd.init | 41 +++++++++++++++++------- templates/service/telnet/listen-address/node.def | 4 +++ templates/service/telnet/node.def | 2 +- 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 templates/service/telnet/listen-address/node.def diff --git a/scripts/system/vyatta_update_telnet b/scripts/system/vyatta_update_telnet index 07d6946f..f50eef79 100755 --- a/scripts/system/vyatta_update_telnet +++ b/scripts/system/vyatta_update_telnet @@ -69,7 +69,7 @@ case "$1" in then echo "Missing port number"; usage fi - exec sudo /opt/vyatta/sbin/telnetd.init restart "$2" + exec sudo /opt/vyatta/sbin/telnetd.init restart $2 $3 ;; disable) diff --git a/scripts/telnetd.init b/scripts/telnetd.init index 81dc2f76..04f65147 100755 --- a/scripts/telnetd.init +++ b/scripts/telnetd.init @@ -13,6 +13,7 @@ declare progname=${0##*/} declare action=$1; shift port=$1; shift +addr=$1; shift : ${port:=23} : ${bb:=/bin/busybox} @@ -31,12 +32,21 @@ running_pid () false } +start_telnetd () +{ + if [ -n "$addr" ] + then $bb telnetd -p $port -b $addr + else $bb telnetd -p $port + fi +} + + start () { local -i pid=$( running_pid ) [ $pid -ne 0 ] && return - $bb telnetd -p $port + start_telnetd } stop () @@ -45,23 +55,32 @@ stop () [ $pid -ne 0 ] && kill $pid } +restart() +{ + local -i pid=$( running_pid ) + if [ $pid -ne 0 ] + then kill $pid + sleep 1 + fi + start_telnetd +} + status () { - pidof $bb | while read pid ; do - f=$(tr '\000' '\t' < /proc/$pid/cmdline | cut -f2) - if [ $f == telnetd ] ; then - echo running - return - fi - done - echo not running - false + local -i pid=$( running_pid ) + if [ $pid -ne 0 ] + then echo running + return + else + echo not running + false + fi } case "$action" in start) start;; stop) stop;; - restart) stop; sleep 1; start;; + restart) restart;; status) status;; *) echo "Usage: $progname {start|stop|restart|status}" exit 1 diff --git a/templates/service/telnet/listen-address/node.def b/templates/service/telnet/listen-address/node.def new file mode 100644 index 00000000..9faea595 --- /dev/null +++ b/templates/service/telnet/listen-address/node.def @@ -0,0 +1,4 @@ +type: ipv4,ipv6 +help: Local addresses telnet should listen on +val_help: ipv4: IP address to listen for incoming connections +val_help: ipv6: IPv6 address to listen for incoming connections diff --git a/templates/service/telnet/node.def b/templates/service/telnet/node.def index 9b2814aa..959a0421 100644 --- a/templates/service/telnet/node.def +++ b/templates/service/telnet/node.def @@ -4,5 +4,5 @@ create: touch /tmp/vyatta-telnet.$PPID delete: /opt/vyatta/sbin/vyatta_update_telnet disable end: if [ -f /tmp/vyatta-telnet.$PPID ]; then rm -f /tmp/vyatta-telnet.$PPID - /opt/vyatta/sbin/vyatta_update_telnet enable $VAR(port/@) + /opt/vyatta/sbin/vyatta_update_telnet enable $VAR(port/@) $VAR(listen-address/@) fi -- cgit v1.2.3