File: xss.in

package info (click to toggle)
afbackup 3.3.8.1beta2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,128 kB
  • ctags: 3,370
  • sloc: ansic: 46,932; sh: 4,654; tcl: 4,199; makefile: 536; csh: 416; perl: 133; sed: 93
file content (218 lines) | stat: -rw-r--r-- 5,832 bytes parent folder | download
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#! /opt/bin/wish
################### Start of $RCSfile: xss.in,v $ ##################
#
# $Source: /home/alb/afbackup/afbackup-3.3.8beta7/RCS/xss.in,v $
# $Id: xss.in,v 1.3 2004/07/08 20:34:48 alb Exp alb $
# $Date: 2004/07/08 20:34:48 $
# $Author: alb $
#
#
####### description ################################################
#
#
#
####################################################################

set prefix "@prefix@"
set TEXTDOMAIN "@PACKAGE@"
set TEXTDOMAINDIR "@commondatadir@/locale"

proc T_ { text } {
  global TEXTDOMAIN TEXTDOMAINDIR

  return [ INTL_gettext $text $TEXTDOMAIN $TEXTDOMAINDIR ]
}

proc TN_ { text } {
  return $text
}

source "@commonshlibdir@/aftcllib.tcl"

if { [ llength $argv ] > 1 } {
  set usagestr [ T_ "Usage" ]
  append usagestr [ TN_ ": " ] [ file tail $argv0 ] { [ <config-file> ]}
  puts stderr $usagestr
  exit 2
}

# user settable section

set BACKUP_HOME_DEFAULT $env(BACKUP_HOME_DEFAULT)

if { [ info exists env(BACKUP_HOME) ] } {
  set BACKUP_HOME $env(BACKUP_HOME)
}

if { [ llength $argv ] == 1 } {
  set configfile [ lindex $argv 0 ]
} else {
  set found 0
  set configfiles "$BACKUP_HOME_DEFAULT/etc/backup.conf $BACKUP_HOME_DEFAULT/lib/backup.conf /etc/buserver.conf /etc/afbuserver.conf /etc/afserver.conf /etc/afbackup/server.conf"
  lappend configfiles "@serverconfdir@/@serverconf@"
  foreach configfile "$configfiles" {
    if { [ file readable $configfile ] } {
      set found 1
      break
    }
  }

  if { ! $found } {
    puts stderr [ T_ "Error: Cannot read configuration file. Exiting." ]
    exit 2
  }
}

proc getparam { pat } {
  global configfile

  set pattern {^[ \t]*}
  append pattern $pat
  append pattern {[ \t]*}


  set errfl [ catch { set fp [ open $configfile r ] } ]
  if { $errfl } {
    puts stderr [ format [ T_ "Error: Cannot open file `%s'.\n" ] $configfile ]
    exit 0
  }

  while { [ gets $fp line ] >= 0 } {
    if { [ regexp -indices $pattern $line i1 ] } {
      close $fp
      set idx [ expr [ lindex $i1 1 ] + 1 ]
      return [ string trim [ string range $line $idx end ] ]
    }
  }

  close $fp
  return ""
}

set replacements {
  { "%V" "vardir" "var" "@servervardir@" }
  { "%L" "libdir" "lib" "@serverlibdir@" }
  { "%I" "logdir" "var" "@serverlogdir@" }
  { "%B" "bindir" "bin" "@serverbindir@" }
  { "%C" "confdir" "lib" "@serverconfdir@" }
}

proc repl_dirs { args } {
  global replacements

  foreach uvar $args {
    upvar $uvar var

    foreach repl $replacements {
	set key [ lindex $repl 0 ]
	set varname [ lindex $repl 1 ]

	global $varname

	set var [ GStr_replSubstring $var $key [ set $varname ] ]
	break
    }
  }
}

set vardir [ getparam {[Vv][Aa][Rr][-_ \t]*[Dd]ire?c?t?o?r?y?:?} ]
if { $vardir == "" } {
  unset vardir
}

foreach repl $replacements {
  set varname [ lindex $repl 1 ]
  set subdir [ lindex $repl 2 ]

  if { ! [ info exists $varname ] } {
    if { [ info exists BACKUP_HOME ] } {
      set $varname "$BACKUP_HOME/$subdir"
    } else {
      set $varname [ lindex $repl 3 ]
    }
  }
}

set statusfile [ getparam {[Ss]tatus[-_ \t]*[Ff]ile:?} ]
if { $statusfile == "" } {
  set statusfile "$vardir/status"
}

set logfile [ getparam {[Ll]ogg?i?n?g?[-_ \t]*[Ff]ile:?} ]
if { [ string range $logfile 0 0 ] == "@" } {
  set logfile [ lindex $logfile 1 ]
  if { [ string trim $logfile ] == "" } {
    unset logfile
  }
}

repl_dirs statusfile logfile

proc update_statusdisplay { } {
  global	statusfile logfile num_log_lines_str prev_log_display

  set success [ catch { set line [ exec tail -1 $statusfile ] } ]
  if { ! $success } {
    .top.stat.stat.label configure -text $line
  }

  if { [ info exists logfile ] } {
    if { ! [ info exists prev_log_display ] } {
      set prev_log_display ""
    }

    set numlines 1
    scan $num_log_lines_str "%d" numlines
    set success [ catch { set lines [ exec tail -$numlines $logfile ] } ]
    if { ! $success } {
      if { $lines != $prev_log_display } {
	.top.log.log.text configure -state normal
	.top.log.log.text delete 0.0 end
	.top.log.log.text insert 0.0 $lines
	.top.log.log.text configure -state disabled
	.top.log.log.text yview end

	set prev_log_display $lines
      }
    }
  }
  
  after 2000 update_statusdisplay
}

set num_log_lines_str 10

frame .top -borderwidth 5
frame .top.stat -borderwidth 5 -relief sunken
label .top.stat.label -text [ T_ "Current server status:" ]
frame .top.stat.stat -borderwidth 2 -relief sunken
label .top.stat.stat.label -width 80
pack .top.stat.label -side top -anchor w
pack .top.stat.stat.label -fill x -side top -expand 1
pack .top.stat.stat -fill x -side top -expand 1
pack .top.stat -fill x
pack .top -fill x
if { [ info exists logfile ] } {
  frame .top.log -borderwidth 5 -relief sunken
  label .top.log.label -text [ T_ "Most recent lines in server's log:" ]
  frame .top.log.log -borderwidth 0
  text .top.log.log.text -width 80 -height $num_log_lines_str -state disabled -xscrollcommand ".top.log.xscroll set" -yscrollcommand ".top.log.log.yscroll set" -wrap none
  scrollbar .top.log.log.yscroll -command ".top.log.log.text yview"
  scrollbar .top.log.xscroll -command ".top.log.log.text xview" -orient horizontal
  frame .top.log.num -borderwidth 0
  label .top.log.num.label -text [ T_ "Number of displayed log lines:" ]
  entry .top.log.num.entry -textvariable num_log_lines_str
  pack .top.log.label -side top -anchor w
  pack .top.log.log.text -side left -expand 1 -fill both
  pack .top.log.log.yscroll -side left -fill y
  pack .top.log.log -fill both -expand 1 -side top
  pack .top.log.xscroll -fill x -side top
  pack .top.log.num.label -side left
  pack .top.log.num.entry -side left -expand 1 -fill x
  pack .top.log.num -side top
  pack .top.log -fill both -expand 1 -side top
  pack .top -fill both -expand 1
}
wm title . [ T_ "AF Backup server status" ]

update_statusdisplay