# ------------------------------------------------------------ # Copyright (c) 2020-2020 # Q.W.Page Associates Inc. # www.qwpage.com # All rights reserved. # ------------------------------------------------------------ ::namspace eval ::qw::mothership2 {} ::itcl::class ::qw::mothership2::nv2_update_handler { /* { */ } method nv3_update_handler {Socket Suffix {Query ""}} { /* { .computer_information { .qw { .app_name app_name_server .release 2.32.3_alpha.20180504 .nameofexecutable D:/nv/nv2.exe .hostname benn7 .sub_product nv2 .ip 192.168.0.158 .nic F4-6D-04-61-A5-CE } .registration { .warning1 {**************************** WARNING ***************************} .warning2 {Uncontrolled changes to this file will render NewViews unusable.} .warning3 {**************************** WARNING ***************************} .serial INTERNAL-BENN-5 .nic F4-6D-04-61-A5-CE .date 20111202 .checksum 31067E07FCA945F31A7EA9B64A224FF4 .customer_number INTERNAL-BENN .maximum_connection_count 5 .nv2_upgrades_expiry_date 20191231 .nv3_release 2.32.3_alpha.20180504 } .customer_support_registration { .nv2_serial_number INTERNAL-BENN-5 .nv2_upgrades_expiry_date 20361231 .customer_number INTERNAL-BENN } .processor { .architecture 4 } .tcl_platform { .osVersion 6.1 .byteOrder littleEndian .threaded 0 .machine intel .platform windows .os {Windows NT} .user benn .wordSize 4 } } */ } ::set rwb1_debug 0; ::upvar #0 Httpd$Socket HttpdArray; ::qw::tclhttpd::decode_query .socket $Socket; ::if {$rwb1_debug} {::qw::tclhttpd::debug_dump $Socket;} ::set Query $HttpdArray(query_sargs); ::if {$rwb1_debug} { ::parray HttpArray; } ::qw::try { ::set Message [::sargs::get $Query .mothership_message]; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.00,Socket==$Socket,Suffix==$Suffix,Message==\n[::sargs::format $Message]";} ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.01,Socket==$Socket,Suffix==$Suffix,Query==$Query";} ::set SubProduct [::sargs::get $Message .computer_information.qw.sub_product]; ::set TclPlatform [::sargs::get $Message .computer_information.tcl_platform.platform]; ::switch -- $SubProduct,$TclPlatform { "nph,windows" { ::set ExecutablePath [::file join c:/ htdocs nv3_executables nv2.32.2.20180308-win32-ix86-nph.exe]; } "crm,windows" { ::set ExecutablePath [::file join c:/ htdocs nv3_executables nv2.32.2.20180308-win32-ix86-crm.exe]; } "nv2,windows" { ::set ExecutablePath [::file join c:/ htdocs nv3_executables nv2.32.2.20180308-win32-ix86-nv2.exe]; } "nph,unix" - "crm,unix" - "nv2,unix" { ::qw::throw "Currently we have no download for \"$SubProduct,$TclPlatform\"."; } default { ::qw::throw "Invalid request \"$SubProduct,$TclPlatform\"."; } } ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.02,ExecutablePath==$ExecutablePath";} ::if {![::file exists $ExecutablePath]} { ::qw::throw "Can't find \"$ExecutablePath\"."; } ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.03";} ::set Result [::sargs]; ::sargs::var::set Result .file.mtime [::file mtime $ExecutablePath]; ::sargs::var::set Result .file.atime [::file atime $ExecutablePath]; ::sargs::var::set Result .file.size [::file size $ExecutablePath]; ::sargs::var::set Result .file.name [::file tail $ExecutablePath]; ::set Command [::sargs::get $Message .command]; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.04,Command==$Command";} ::switch -- $Command { nv3_update_information_get { /* { Returns .file { .mtime 999 .ctime 999 .size 999 .name nv2.32.2.20180308-win32-ix86-nv2.exe } The babyship calls this to find out the name and times of the executable in order to see if it already has downloaded the correct executable. */ } ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.05";} ::qw::tclhttpd::return_data \ .socket $Socket \ .message $Result \ ; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.06";} } nv3_update_download { ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.07";} ::qw::try { ::set Handle [::open $ExecutablePath r]; ::fconfigure $Handle -translation binary; ::set FileData [::read $Handle]; ::close $Handle; } catch Text { ::qw::throw "Can't load $ExecutablePath:$Text"; } ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.08";} ::set Seconds [::clock seconds]; ::set FileData [::qw::base64::encode .data $FileData]; ::set Base64EncodeSeconds [::expr {[::clock seconds]-$Seconds}]; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.09";} ::sargs::var::set Result .file.data $FileData; ::set MilliSeconds [::clock clicks -milliseconds]; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.10";} ::qw::tclhttpd::return_data \ .socket $Socket \ .message $Result \ ; ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.11";} ::set SendResultMilliSeconds [::expr {[::clock clicks -milliseconds]-$MilliSeconds}]; ::if {$rwb1_debug} {::puts "rwb1_debug,SendResultMilliSeconds==$SendResultMilliSeconds";} ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.99"}; } default { ::if {$rwb1_debug} {::puts "rwb1_debug,nv3_download_executable,1000.98";} ::qw::throw "nv3_update - invalid command \"$Command\"."; } } } catch Exception { ::qw::tclhttpd::return_data \ .socket $Socket \ .message [::sargs .exception $Exception] \ ; } } } ::qw::webserver ::qw::mothership2::nv2_update_handler ::qw::mothership2::nv2_update_handler::singleton main;