#!/bin/sh # (C) 2010 by Eugeniy Mikhailov, # vim:set ft=tcl: \ exec tclsh "$0" "$@" set err [catch { # require Tcl version of at least 8.5 since I use 'ni' and 'in' in expressions for lists package require ncgi package require Tcl 8.5 package require sqlite3 package require md5 } errStat ] if { $err } { ::ncgi::header puts "the following error happen: $errStat" exit } ###################### Main script begins ################################# set err [catch { set execution_start_time [clock microseconds] source ./GradeBook_lib.tcl set config_file "./gb_config.tcl" if { [file exists $config_file] && ("$config_file" ne "") } { source $config_file } ::ncgi::parse # defaults set sortCol LastName set user guest set password guest set action defaultview # defaults end # read cookies set user_requested [::ncgi::cookie user] if { $user_requested eq "" } { set user_requested __user_not_set__ } set sortCol [::ncgi::cookie sortCol] set password [::ncgi::cookie password] set action [::ncgi::value action defaultview] # end of read cookies # get remote IP if { [catch {set remote_ip $env(REMOTE_ADDR)} errStat] } { set remote_ip unknown} # get hostname if { [catch {set host_name $env(SERVER_NAME)} errStat] } { set host_name unknown} # script name if { [catch {set script_name $env(SCRIPT_NAME)} errStat] } { set script_name unknown} set script_root_name $script_name # figure out course db filename # script uri if { [catch {set request_uri $env(REQUEST_URI)} errStat] } { set request_uri unknown} regsub -all $script_name $request_uri "" coursedbfname regsub -all {\?.*$} $coursedbfname "" coursedbfname regsub -all {^/} $coursedbfname "" coursedbfname if { $coursedbfname eq "" } { set coursedbfname __DB_not_set__ } set script_name "$script_name/$coursedbfname" set timestamp [timestamp] #CreateGradesTable db #CreateAccessRightsTable db dbg [::ncgi::names] msg_level_info # logon and logoff actions are granted to everyone if { $action == "logon" } { set action [ LogMeOn ] } if { $action == "logoff" } { LogMeOff; set action defaultview } #dbg "[timestamp] user $user_requested DB $coursedbfname version $VERSION from $remote_ip" msg_level_log ::ncgi::header set user [ Authenticate_User $user_requested $password ] dbg "[timestamp] authenticated user $user_requested DB $coursedbfname as $user version $VERSION from $remote_ip" msg_level_log dbg "[timestamp] requested action $action by user $user_requested DB $coursedbfname recognized as $user version $VERSION from $remote_ip" msg_level_log package require json::write set logEntry {} lappend logEntry timestamp [::json::write string [timestamp]] lappend logEntry remoteIP [::json::write string "$remote_ip"] lappend logEntry userName [::json::write string "$user_requested"] if { "$user_requested" eq "$user" } { lappend logEntry userStatus [::json::write string "authenticated"] } else { lappend logEntry userStatus [::json::write string "$user"] } lappend logEntry requestedAction [::json::write string "$action"] lappend logEntry DB [::json::write string "$coursedbfname"] lappend logEntry sortCol [::json::write string "$sortCol"] lappend logEntry programVersion [::json::write string "$VERSION"] lappend logEntry logLevel [::json::write string msg_level_log] set logEntryString [json::write object {*}$logEntry] set fid [open $GradebookServerConfig(log_file) a+] puts $fid "$logEntryString" close $fid set dbfile "$GradebookServerConfig(grades_db_dir)/$coursedbfname" if { [file exists $dbfile] && ("$coursedbfname" ne "") } { sqlite3 db $dbfile htmlHeader puts "" set permission_list [ AccessGroupRights db $user ] htmlTop $permission_list ChoseAction $action $permission_list $user db close } else { htmlHeaderDBSelector set permission_list [list GroupName guest] puts "" if { "$coursedbfname" ne "__DB_not_set__" } { htmlErrorMsg "No requested database {$coursedbfname}. Please, check your url" dbg "Attemt to access non existing database: {$dbfile}" msg_level_info } html_Show_Classes_List $permission_list $user } dbg $permission_list msg_level_info htmlFooter $permission_list puts "" ###################### Main script ends ################################# } errStat ] if { $err } { dbg "Error: $errStat" msg_level_critical htmlErrorMsg "Something went wrong, please, ask admin to have a look at logs" } # vim: ts=2 sw=2 foldmethod=indent: