#!/usr/bin/tclsh # # This file is part of Helga. # # Helga is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Helga is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Helga. If not, see . # if { $argc != 2 } { puts "Usage: getSessionUserId.tclsh \"userId\"|\"port\"" exit 1 } set sessionId [string trim [lindex $argv 0]] set dataType [lindex $argv 1] if { $dataType != "userId" && $dataType != "port" } { error "Error: must equal either \"userId\" or \"port\"" } package require mysqltcl set dirName [file dirname [file normalize $argv0]] source "$dirName/sourceConf.tcl" set minTime [expr [clock seconds] - $::SESSION_LENGTH] set db [::mysql::connect -user helgaAdmin -password $::ADMINSQLPASS -db $::SQLDB] set sql "SELECT `" if { $dataType == "userId" } { append sql "userId" } else { append sql "portNumber" } append sql "` FROM `sessions` WHERE `sessionId` = '$sessionId' AND `timestamp` > $minTime" set result [::mysql::sel $db $sql -list] if { $result == "" } { set sql "SELECT * FROM `sessions` WHERE `sessionId` = '$sessionId'" set result [::mysql::sel $db $sql -list] if { $result == "" } { puts "notfound" } else { puts "expired" } } else { set sql "UPDATE `sessions` SET `timestamp` = [clock seconds] WHERE `sessionId` = '$sessionId'" ::mysql::exec $db $sql puts [lindex [lindex $result 0] 0] }