File: tkdial

package info (click to toggle)
lg-issue25 5-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,552 kB
  • ctags: 68
  • sloc: tcl: 69; makefile: 37; sh: 4
file content (136 lines) | stat: -rw-r--r-- 3,514 bytes parent folder | download | duplicates (4)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/wish -f
#
# Linux dialer. Shows on/off line, time on-line, and
# pppd process identifier.
#
# (c) 1998 (GPL) Martin Vermeer
#
# User configurable:
#----------------------------------------
set path(pidof) /sbin/pidof
set path(pppd) /usr/sbin/pppd
set path(whoami) /usr/bin/whoami)
#----------------------------------------
# End user config

set seconds 0
set minutes 0
label  .counter -text "0:00" -relief sunken

## Test for root.
#
## Not needed if pppd suid root and /etc/ppp files 
## "options" and connect/disconnect scripts 
## (but NOT the "secrets" file!!! world readable
## (or readable to a group you belong to)
#
# catch "exec $path(whoami)" result
# if {$result != "root"} {
#     set labeltext "Run me as ROOT!"
#     after 10000 exit 
#}

# showpid -- routine to get and show process id, keep track
#            of pppd link up/down status, and reset time
#            counter if down
#
proc showpid {} {
    global pid labeltext status seconds minutes path

    if [catch "exec $path(pidof) pppd" pid] {set pid -1}
    if {$pid != -1} {
        set labeltext "Link pid: ${pid}"
        set status 1
    } else {
        set labeltext "Link Down"
        set status 0; set seconds 0; set minutes 0
    } 
}

# tick -- routine to increment clock by 5 seconds every
#         5 seconds, and minutes every minute.
#         Don't be on-line over an hour :-)
#
proc tick {} {
    global minutes seconds status pid labeltext
    if $status {
        after 5000 tick
        incr seconds 5
        if {$seconds >= 60} { set seconds 0; incr minutes }
    } 
    after 5000 showpid
    .counter config -text [format "%d:%02d" $minutes $seconds]
}

# 
# Find out if there was an old pppd process running:
#
if [catch "exec $path(pidof) pppd" pid] {set pid -1}
if {$pid != -1} {
    set labeltext "Old Link ${pid}"
    set status 1
    tick
} else {
    set labeltext "Link Down"
    set status 0
}

#
# Downcmd -- command to bring down the pppd link
#
proc Downcmd {} {
global status path
    # Get the pids of pppd processes into res:
    if [catch "exec $path(pidof) pppd" res] {set res -1} 
    if {$res != -1} {
        # Some pppd process running; go get'em
        catch "exec kill -9 $res" result
        # Debug code:
        # puts "pid=$res result=$result"
    }
    # Necessary to update $status to realistic value:
    showpid
    # await kill command to take effect:
    while {$status == 1} showpid   
    # don't come out until really down
}

# Upcmd -- Command to bring up the pppd link
#          and start the clock ticking
#
proc Upcmd {} {
    global status path seconds minutes
    # start up pppd:
    if [catch "exec $path(pidof) pppd" res] {set res -1}
    if {$res == -1} {
        # no pppd process running yet; start one
        catch "exec /usr/sbin/pppd"
        set status 1
	# start clock running
	set seconds 0
        set minutes 0
        tick
    }
    if {$res > 0} { 
        set labeltext "Old Link: ${res}" 
        set status 1
    }
}

#
# Define the widgets:
#
label        .name -textvariable labeltext 
radiobutton  .up   -text "Up"   -variable status -value 1 -command Upcmd
radiobutton  .down -text "Down" -variable status -value 0 -command Downcmd
button       .quit -text "Quit" -command exit

#
# Lay out grid geometry:
#
grid .name     -row 0 -column 0 -columnspan 2 -sticky "ew"
grid .up       -row 1 -column 1 -sticky "w"
grid .down     -row 2 -column 1 -sticky "w"
grid .quit     -row 2 -column 0 
grid .counter  -row 1 -column 0 -sticky "ns"