/usr/lib/aolserver4/modules/tcl/util.tcl is in aolserver4-daemon 4.5.1-16.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | #
# The contents of this file are subject to the AOLserver Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://aolserver.com/.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is AOLserver Code and related documentation
# distributed by AOL.
#
# The Initial Developer of the Original Code is America Online,
# Inc. Portions created by AOL are Copyright (C) 1999 America Online,
# Inc. All Rights Reserved.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above. If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#
#
# $Header: /cvsroot/aolserver/aolserver/tcl/util.tcl,v 1.5 2007/10/20 16:39:21 gneumann Exp $
#
#
# util.tcl --
#
# Various utilitiy procs.
#
# ns_localtime returns a time as a list of elements, and ns_parsetime
# returns one of those elements
proc ns_parsetime {option time} {
set parts {sec min hour mday mon year wday yday isdst}
set pos [lsearch $parts $option]
if {$pos == -1} {
error "Incorrect option to ns_parsetime: \"$option\" Should be\
one of \"$parts\""
}
return [lindex $time $pos]
}
# ns_findset returns a set with a given name from a list.
proc ns_findset {sets name} {
foreach set $sets {
if {[ns_set name $set] == $name} {
return $set
}
}
return ""
}
# getformdata - make sure an HTML FORM was sent with the request.
proc getformdata {conn formVar} {
upvar $formVar form
set form [ns_conn form $conn]
if {$form eq ""} {
ns_returnbadrequest $conn "Missing HTML FORM data"
return 0
}
return 1
}
proc ns_paren {val} {
if {$val ne ""} {
return "($val)"
} else {
return ""
}
}
proc Paren {val} {
return [ns_paren $val]
}
proc issmallint {value} {
return [ns_issmallint $value]
}
proc ns_issmallint {value} {
return [expr {[regexp {^[0-9]+$} $value] && [string length $value] <= 6}]
}
## Special thanks to Brian Tivol at Hearst New Media Center and MIT
## for providing the core of this code.
proc ns_formvalueput {htmlpiece dataname datavalue} {
set newhtml ""
while {$htmlpiece ne ""} {
if {[string index $htmlpiece 0] == "<"} {
regexp {<([^>]*)>(.*)} $htmlpiece m tag htmlpiece
set tag [string trim $tag]
set CAPTAG [string toupper $tag]
switch -regexp $CAPTAG {
{^INPUT} {
if {[regexp {TYPE=("IMAGE"|"SUBMIT"|"RESET"|IMAGE|SUBMIT|RESET)} $CAPTAG]} {
append newhtml <$tag>
} elseif {[regexp {TYPE=("CHECKBOX"|CHECKBOX|"RADIO"|RADIO)} $CAPTAG]} {
set name [ns_tagelement $tag NAME]
if {$name == $dataname} {
set value [ns_tagelement $tag VALUE]
regsub -all -nocase { *CHECKED} $tag {} tag
if {$value == $datavalue} {
append tag " CHECKED"
}
}
append newhtml <$tag>
} else {
## If it's an INPUT TYPE that hasn't been covered
# (text, password, hidden, other (defaults to text))
## then we add/replace the VALUE tag
set name [ns_tagelement $tag NAME]
if {$name == $dataname} {
ns_tagelementset tag VALUE $datavalue
}
append newhtml <$tag>
}
}
{^TEXTAREA} {
###
# Fill in the middle of this tag
###
set name [ns_tagelement $tag NAME]
if {$name == $dataname} {
while {![regexp -nocase {^<( *)/TEXTAREA} $htmlpiece]} {
regexp {^.[^<]*(.*)} $htmlpiece m htmlpiece
}
append newhtml <$tag>$datavalue
} else {
append newhtml <$tag>
}
}
{^SELECT} {
### Set flags so OPTION and /SELECT know what to look for:
# snam is the variable name, sflg is 1 if nothing's
### been added, smul is 1 if it's MULTIPLE selection
if {[ns_tagelement $tag NAME] == $dataname} {
set inkeyselect 1
set addoption 1
} else {
set inkeyselect 0
set addoption 0
}
append newhtml <$tag>
}
{^OPTION} {
###
# Find the value for this
###
if {$inkeyselect} {
regsub -all -nocase { *SELECTED} $tag {} tag
set value [ns_tagelement $tag VALUE]
regexp {^([^<]*)(.*)} $htmlpiece m txt htmlpiece
if {$value eq ""} {
set value [string trim $txt]
}
if {$value == $datavalue} {
append tag " SELECTED"
set addoption 0
}
append newhtml <$tag>$txt
} else {
append newhtml <$tag>
}
}
{^/SELECT} {
###
# Do we need to add to the end?
###
if {$inkeyselect && $addoption} {
append newhtml "<option selected>$datavalue<$tag>"
} else {
append newhtml <$tag>
}
set inkeyselect 0
set addoption 0
}
{default} {
append newhtml <$tag>
}
}
} else {
regexp {([^<]*)(.*)} $htmlpiece m brandnew htmlpiece
append newhtml $brandnew
}
}
return $newhtml
}
proc ns_tagelement {tag key} {
set qq {"([^"]*)"} ; # Matches what's in quotes
set pp {([^ >]*)} ; # Matches a word (mind yer pp and qq)
if {[regexp -nocase "$key *= *$qq" $tag m name]} {}\
elseif {[regexp -nocase "$key *= *$pp" $tag m name]} {}\
else {set name ""}
return $name
}
# Assumes that the final ">" in the tag has been removed, and
# leaves it removed
proc ns_tagelementset {tagvar key value} {
upvar $tagvar tag
set qq {"([^"]*)"} ; # Matches what's in quotes
set pp {([^ >]*)} ; # Matches a word (mind yer pp and qq)
regsub -all -nocase "$key=$qq" $tag {} tag
regsub -all -nocase "$key *= *$pp" $tag {} tag
append tag " value=\"$value\""
}
# sorts a list of pairs based on the first value in each pair
proc _ns_paircmp {pair1 pair2} {
if {[lindex $pair1 0] > [lindex $pair2 0]} {
return 1
} elseif {[lindex $pair1 0] < [lindex $pair2 0]} {
return -1
} else {
return 0
}
}
# ns_htmlselect ?-multi? ?-sort? ?-labels labels? key values ?selecteddata?
proc ns_htmlselect args {
set multi 0
set sort 0
set labels {}
while {[string index [lindex $args 0] 0] == "-"} {
if {[lindex $args 0] eq "-multi"} {
set multi 1
set args [lreplace $args 0 0]
}
if {[lindex $args 0] eq "-sort"} {
set sort 1
set args [lreplace $args 0 0]
}
if {[lindex $args 0] eq "-labels"} {
set labels [lindex $args 1]
set args [lreplace $args 0 1]
}
}
set key [lindex $args 0]
set values [lindex $args 1]
if {[llength $args] == 3} {
set selecteddata [lindex $args 2]
} else {
set selecteddata ""
}
set select "<SELECT NAME=$key"
if {$multi == 1} {
set size [llength $values]
if {$size > 5} {
set size 5
}
append select " MULTIPLE SIZE=$size"
} else {
if {[llength $values] > 25} {
append select " SIZE=5"
}
}
append select ">\n"
set len [llength $values]
set lvpairs {}
for {set i 0} {$i < $len} {incr i} {
if {$labels eq ""} {
set label [lindex $values $i]
} else {
set label [lindex $labels $i]
}
regsub -all "\"" $label "" label
lappend lvpairs [list $label [lindex $values $i]]
}
if {$sort} {
set lvpairs [lsort -command _ns_paircmp -increasing $lvpairs]
}
foreach lvpair $lvpairs {
append select "<OPTION VALUE=\"[lindex $lvpair 1]\""
if {[lsearch $selecteddata [lindex $lvpair 1]] >= 0} {
append select " SELECTED"
}
append select ">[lindex $lvpair 0]\n"
}
append select "</SELECT>"
return $select
}
proc _ns_fillinmailtemplate {templatebody row} {
set rowsize [ns_set size $row]
for {set i 0} {$i < $rowsize} {incr i} {
set key "#[ns_set key $row $i]#"
regsub -all "&" [ns_set value $row $i] {\\\&} value
regsub -all $key $templatebody $value templatebody
}
return $templatebody
}
proc ns_setexpires args {
# skip over the optional connId parameter: just use the last arg
set secondsarg [expr {[llength $args] - 1}]
ns_set update [ns_conn outputheaders] Expires \
[ns_httptime [expr {[lindex $args $secondsarg] + [ns_time]}]]
}
proc ns_browsermatch args {
# skip over the optional connId parameter: just use the last arg
set globarg [expr {[llength $args] - 1}]
return [string match [lindex $args $globarg] \
[ns_set iget [ns_conn headers] user-agent]]
}
proc ns_set_precision {precision} {
global tcl_precision
set tcl_precision $precision
}
proc ns_updateheader {key value} {
ns_set update [ns_conn outputheaders] $key $value
}
|