Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding user session check to exec.cgi #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions xmlapi/exec.cgi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/tclsh

load tclrega.so
source querystring.tcl
source session.tcl

proc toString { str } {
set map {
Expand All @@ -22,22 +24,26 @@ puts "Content-Type: text/plain"
puts "Access-Control-Allow-Origin: *"
puts ""


if { [catch {
set content [read stdin]
array set script_result [rega_script $content]

set first 1
set result "\{\n"
foreach name [array names script_result] {
if { 1 != $first } { append result ",\n" } { set first 0 }
set value $script_result($name)
append result " [toString $name]: [toString $value]"
if {[info exists sid] && [check_session $sid]} {
if { [catch {
set content [read stdin]
array set script_result [rega_script $content]

set first 1
set result "\{\n"
foreach name [array names script_result] {
if { 1 != $first } { append result ",\n" } { set first 0 }
set value $script_result($name)
append result " [toString $name]: [toString $value]"
}
append result "\n\}"

puts $result

} errorMessage] } {
puts $errorMessage
}
append result "\n\}"

puts $result

} errorMessage] } {
puts $errorMessage
} else {
puts "{error: no session}"
}
9 changes: 9 additions & 0 deletions xmlapi/querystring.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
catch {
set input $env(QUERY_STRING)
set pairs [split $input &]
foreach pair $pairs {
if {0 != [regexp "^(\[^=]*)=(.*)$" $pair dummy varname val]} {
set $varname $val
}
}
}
13 changes: 13 additions & 0 deletions xmlapi/session.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/tclsh

load tclrega.so

proc check_session sid {
if {[regexp {@([0-9a-zA-Z]{10})@} $sid all sidnr]} {
set res [lindex [rega_script "Write(system.GetSessionVarStr('$sidnr'));"] 1]
if {$res != ""} {
return 1
}
}
return 0
}