summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_telnet
blob: 0725a85f057bb932574eefa65d2a4ff30f69cc59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /bin/bash
# Script to control telnet daemon parameters
# and block changes when logged in over telnet

# Block changes to telnet daemon when logged in over telnet
pid=$(who -um | awk -F " " '{print $7}')
if ps --pid $(ps --pid $pid -o ppid=) -o cmd= | grep -q telnetd
then
    echo "Please configure telnet settings via ssh or console."
    exit 1
fi

usage() {
    echo "Usage: $0 enable <port>"
    echo "       $0 disable"
    echo "       $0 allow-root {true|false}"
    exit 1;
}

allow-root() {
    case "$1" in
    true) ;;
    false) ;;
        *)  echo "Expect true or false"
	    usage ;;
    esac

    sudo sed -i -e '/^# Pseudo-terminal (telnet)/,$d' /etc/securetty

    if [ $1 = "false" ]; then
	return
    fi

    sudo sh -c "cat >>/etc/securetty" <<EOF
# Pseudo-terminal (telnet)
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
pts/10
pts/11
pts/12
pts/13
pts/14
pts/15
pts/16
pts/17
pts/18
pts/19
EOF

}

case "$1" in
    allow-root) 
	allow-root $2
	;;

    enable)
	if [ -z "$2" ]
	then echo "Missing port number";
	    usage
	fi
	exec sudo /opt/vyatta/sbin/telnetd.init restart "$2"
	;;

    disable)
	exec sudo /opt/vyatta/sbin/telnetd.init stop
	;;

    *)  
	echo "Unknown argument $1";
	usage 
	;;
esac