# Copyright for URLibService (c) 1995 - 2018, # by Gerald Banon. All rights reserved. # Version 2.1 # post (post the URLib local collection - start the servers) # post -x (unpost - stop the servers) # post -r (reset - recreate files like auxdoc/.repositoryProperties.tcl, and post the local collection) # post -f (force - force migration (donīt try to update the remote collection - used when the remote Arquive is down forever) # post -p gjfb 800 (set the port entry to {gjfb 800} and post the local collection) # post -c (update all the cgi scripts) # post -x -u (unpost and download/extract the last version (if any)) # within cygwin under Windows one can use the command: # netstat -ano | grep 'TCP 0.0.0.0:' # puts $argv # puts [llength $argv] set URLibServiceRepository dpi.inpe.br/banon/1998/08.02.08.56 set URLibServiceMetadataRepository dpi.inpe.br/banon/1999/04.02.15.49 ;# used to update metadata in this file set devLoCoInRep dpi.inpe.br/banon/1999/01.09.22.14 ;# used in StartService and DDRoutine set downloadingEnvironmentRepository iconet.com.br/banon/2000/12.30.22.40 set applicationName post set errorTrace 0 ;# value is 0 or 1 - used in ServeLocalCollection, Execute, Submit, MultipleSubmit and CreateEnvironmentArray set acceptCommunicationCounter 0 ;# used in ServeLocalCollection only # some global variables: # accentTable ;# used by SetNoMatch (Search.tcl) # accentTable2 ;# used by SetNoMatch (Search.tcl) # allowedCommandList ## apacheConfDirectoryPath # apacheIconDirectoryPath # apacheLibDirectoryPath # apacheMagicFilePath # apacheMimeTypesFilePath # apachePath # apacheRepository # applicationName ;# values are: start or post # bannerPathArray ;# array of pathes for repositories whose service/type is Banner - indices are banner languages # bannerRoot ;# path of the directory containing files like nextSite, used in CreateBannerSpace and FindBannerPath # bannerSequenceRepList ;# list of repositories whose service/type is Banner Sequence # bib2referRepository # bibpessoal2referRepository # citationKeyRepository # col # commonWords # defaultDocRepository # defaultMetadataRepository # diskSpeed ;# set and use only in GetSiteInformation # environmentArray # homePath # htpasswdPath # inverseTable # ipChangeFlag - set in post and used just in InformURLibSystem # linuxDistribution # loBiMiRep # localURLibClientSocketId # loCoInRep # log # maximumNumberOfEntries ;# used by RemoveMetadata and by CreateRepArray (to compute mostRecentReferences and mostRecentFullTexts) # metadataArray # mostRecentReferences ;# contains the most recent references # mostRecentFullTexts ;# contains the most recent full texts # officialIconRepList ;# list of repositories whose service/type is Access Icon, but not the default icon # pwd # referenceTypeList # referRepository # ${referRepository}::conversionTable # repositoryListForPost ;# set in UpdateRepositoryListForPost # saveFlag ;# used in SaveMetadata # saveMetadata # searchRepository # serverAddress ;# banon-pc2 19050; banon-pc2:1905 (old usage) # ipURLibPort ;# 150.163.2.174 19050; 150.163.2.174;1905 (old usage) # localSite ;# banon-pc2:1905 # startApacheServer # startApplicationInUse ;# used by start and post # tclPath # unZipPath # unZipRepository # URLibServiceRepository # URLibServiceMetadataRepository ## URLibServiceMetadataRepositoryList ;# created in StartService and used in FindTheMostRecentReferences # urlibServiceVersion ;# extracted from the history of the URlibService Repository; set in StartService # zipPath # zipRepository # set processID [list [clock seconds] 0] # homePath if ![regexp "(^.*)/col/$URLibServiceRepository/doc" [pwd] m homePath] { # starting from home cd col/$URLibServiceRepository/doc regexp "(^.*)/col/$URLibServiceRepository/doc" [pwd] m homePath } # homePath, ex: /home/URLib set applicationNameForReverseEngineering post ;# for reverse engineering only set applicationRuningTime [clock format [clock seconds] -format %Y:%m.%d.%H.%M.%S] ;# for reverse engineering only set applicationFileName "'$homePath/col/$URLibServiceRepository/doc/post'" ;# for reverse engineering only # pwd set pwd [pwd] # serverRoot and bannerRoot # bannerRoot is used in CreateEnvironmentArray if [file exist $homePath/readOnlySite] { set serverRoot C:/tmp/URLibService/serverDir file mkdir $serverRoot set bannerRoot C:/tmp/URLibService/bannerDir file mkdir $bannerRoot } else { set serverRoot $homePath/col/$URLibServiceRepository/auxdoc/serverDir set bannerRoot $homePath/col/$URLibServiceRepository/auxdoc/bannerDir file mkdir $bannerRoot } package require http ;# needed with tcl 8.5 lappend auto_path $pwd package require $URLibServiceRepository if [catch { # portEntry (ex: gjfb 800) if ![regexp -- {-[pP] (.*)} $argv m portEntry] {set portEntry {}} # puts --$portEntry-- # Load global variables LoadGlobalVariables $portEntry ;# sources environmentArray # Load global variables - end # puts >>>$environmentArray(ipAddress) # puts >>>$serverAddressWithIP # puts --$zipPath-- if ![regexp -- {-[xX]} $argv] { # not unpost StoreLog {notice} {post (1)} {starting URLibService} file delete $homePath/col/$URLibServiceRepository/auxdoc/pingIPMessage ;# used in ReturnFullServerNameIP if {$tcl_platform(platform) == "unix"} { if [file owned $homePath/@errorLog] { exec chmod g+w $homePath/@errorLog ;# needed by some cgi scripts } file mkdir $homePath/clipboard3 exec chmod g+w $homePath/clipboard3 ;# added by GJFB in 2018-03-30 to allow storing returnPathArray.tcl and missingNextHigherUnitIBIList (see Get) } FindInternetAddress ;# updates environmentArray, serverAddress and serverAddressWithIP - the domain name might be wrong and is fixed using InformURLibSystem return # ipChangeFlag - used in InformURLibSystem only - added by GJFB in 2017-04-28 set ip [lindex $serverAddressWithIP 0] if [file exists $homePath/@previousIP] { Load $homePath/@previousIP previousIP set ipChangeFlag [expr ![string equal $previousIP $ip]] } else { set ipChangeFlag 1 } Store ip $homePath/@previousIP ;# added by GJFB in 2017-04-28 - used at next post - useful to maintain the value of staticFlag even when urlib.net server is down } # puts >>>$environmentArray(ipAddress) # puts >>>$serverAddressWithIP # pid # used by Set, Unset, Lappend, Array, Get and ServeLocalCollection set pid [pid] Store pid ../auxdoc/pid if {$tcl_platform(os) == "Linux"} { if [string equal {iconet.com.br/banon/2005/12.06.21.35} $apacheRepository] { # Apache 1.3.33 coming from Mandrake at dpi.inpe.br if ![file executable $apachePath] { if [file owned $apachePath] { exec chmod 754 $apachePath } } if ![file executable $htpasswdPath] { if [file owned $htpasswdPath] { exec chmod 754 $htpasswdPath } } } } set localSite [ReturnHTTPHost] ;# banon-pc2.dpi.inpe.br or www.urlib.net - uses serverAddress set in LoadGlobalVariables set localSiteWithIP [ReturnHTTPHost $serverAddressWithIP] set urlibPort [lindex $serverAddress end] # Store urlibPort $homePath/@urlibPort ;# used in GetServerAddressFromHTTPHost only - added by GJFB in 2014-06-20 puts {} # serverRoot2ExistenceFlag - just used in this file set serverRoot2ExistenceFlag [file exists $homePath/@serverRoot2] ;# added by GJFB in 2016-04-28 - after an installation @serverRoot2 doesn't exist yet # set xxx $serverRoot2ExistenceFlag # Store xxx C:/tmp/bbb auto 0 a if {!$installInitialCollection && ![regexp -- {-[xX]} $argv]} { ;# just this line changed by GJFB in 2016-04-28 - [regexp -- {-[xX]} $argv] is to avoid creating @serverRoot2 at unpost after installation # Create @serverRoot2 and @serverAddressWithIP set convertedURL [ConvertURLToHexadecimal http://$localSiteWithIP/@serverRoot2] # here, a command like http::geturl $convertedURL -command FindServerRoot -timeout 5000 # is useless - the option -timeout is ignored when the server is off regsub {.$} $urlibPort {0} port ;# 804 -> 800 if ![regexp "0.0.0.0:$port" [exec netstat -an]] { puts "URLibService at <$serverAddress> is not running" set serverRoot2 $serverRoot Store serverAddressWithIP $homePath/@serverAddressWithIP ;# used to restart Apache } else { if [catch {http::geturl $convertedURL} token] { # Apache is not running # http::geturl http://150.163.34.244/@serverRoot2 http::geturl doesn't worl properly with tcl 8.4.11 (na mtc-m15) # http::geturl http://150.163.34.64/@serverRoot2 http::geturl doesn't worl properly with tcl 8.4.11 (na mtc-m15) puts "Apache is not running: $token" set serverRoot2 $serverRoot Store serverAddressWithIP $homePath/@serverAddressWithIP ;# used to restart Apache } else { # Apache is running puts {Apache is running} set serverRoot2 [string trim [http::data $token] \n] http::cleanup $token set convertedURL [ConvertURLToHexadecimal http://$localSiteWithIP/@serverAddressWithIP] set token [http::geturl $convertedURL] set remoteServerAddressWithIP [string trim [http::data $token] \n] http::cleanup $token Store remoteServerAddressWithIP $homePath/@serverAddressWithIP ;# used to restart Apache } } Store serverRoot2 $homePath/@serverRoot2 # Create @serverRoot2 and @serverAddressWithIP - end } set log .window.main.output.log source accentTables.tcl ;# used by SetNoMatch (Search.tcl) SourceLanguage environmentArray if [regexp -- {-[xX]} $argv] { # unpost if ![catch {Info exists startApplicationInUse} flag] { # flag value may be 0 1 (Start Application is running) or empty (URLib port in use) if ![string equal 0 $flag] { set message {cannot unpost - Start Application is running or URLib port is in use} # puts $message # set log "post (2): $message" # Store log $homePath/@errorLog auto 0 a puts [StoreLog {alert} {post (2)} $message] exit } } puts {unposting the URLib local collection...} } else { # Testing lastRepTimeInFractionOfSecond # same code as in CreateIBI if {[info tclversion] > 8.4} { set currentTimeInFractionOfSecond [expr [clock microseconds] / 1000000.] ;# ct Load ../auxdoc/lastRepTimeInFractionOfSecond lastRepTimeInFractionOfSecond if [string equal {} $lastRepTimeInFractionOfSecond] { set lastRepTimeInFractionOfSecond [expr (entier($currentTimeInFractionOfSecond / $temporalResolution)) / (1 / $temporalResolution) - $temporalResolution] ;# [i] = 1, lrt == rct - 1, therefore s == nrt == rnrt == rct } # same code as in CreateSuffix set roundOffCurrentTimeInFractionOfSecond [expr (entier($currentTimeInFractionOfSecond / $temporalResolution)) / (1 / $temporalResolution)] set lastRepTimeInFractionOfSecond [expr (entier($lastRepTimeInFractionOfSecond / $temporalResolution)) / (1 / $temporalResolution)] ;# useful because temporalResolution may have changed and its value increased (e.g., from 0.001 to 0.1) set numberOfFractionalDigits [expr int(log10(1 / $temporalResolution))] # MAX set newRepTimeInFractionOfSecond [Max [format %.${numberOfFractionalDigits}f [expr $lastRepTimeInFractionOfSecond + $temporalResolution]] $roundOffCurrentTimeInFractionOfSecond] ;# t' # puts $newRepTimeInFractionOfSecond ;# t' set delay [expr $newRepTimeInFractionOfSecond - $currentTimeInFractionOfSecond] set delayInMillisecond [expr entier($delay * 1000)] # AFTER if {$delayInMillisecond > 0} { puts "posting should be done after $delayInMillisecond milliseconds" set x2 0; after 5000 {set x2 1}; vwait x2 ;# wait 5 seconds return } } # Testing lastRepTimeInFractionOfSecond - end # puts "posting the URLib local collection at <$serverAddress>..." puts "posting the URLib local collection at <$serverAddressWithIP>..." if [catch {exec $apachePath -v > ../auxdoc/apacheVersion &} message] { # set log "post (3): $message" # puts $log # Store log $homePath/@errorLog auto 0 a puts [StoreLog {alert} {post (3)} "Apache version not found: $message"] puts "to see detailed error message, try to execute the command line: $apachePath -v" exit } # set x2 0; after 5000 {set x2 1}; vwait x2 ;# wait 5 seconds # Load ../auxdoc/apacheVersion apacheVersion # puts $apacheVersion } # postEnvironmentArray if [file exists ../auxdoc/.postEnvironmentArray.tcl] { catch {source ../auxdoc/.postEnvironmentArray.tcl} } if [file exists $homePath/newVersion] { if [info exists postEnvironmentArray(urlibServerAddress)] { unset postEnvironmentArray(urlibServerAddress) } if [info exists postEnvironmentArray(urlibadEMailAddress)] { unset postEnvironmentArray(urlibadEMailAddress) } if [info exists postEnvironmentArray(regionalURLibServerAddress)] { unset postEnvironmentArray(regionalURLibServerAddress) } if [info exists postEnvironmentArray(regionalURLibAdEMailAddress)] { unset postEnvironmentArray(regionalURLibAdEMailAddress) } if {[info exists loCoInRep] && $loCoInRep != "$devLoCoInRep"} { if [file exist ../auxdoc/.urlibServiceVersion.tcl] { source ../auxdoc/.urlibServiceVersion.tcl ;# set urlibServiceVersion } else { set urlibServiceVersion 0 } source $homePath/newVersion ;# set updateLevel if {[string compare $updateLevel(1) $urlibServiceVersion] > 0} { # old version - delete textlog # must be deleted now because start may be used after post # (for example when using updateURLibService) file delete ../auxdoc/textLog } if {[string compare $updateLevel(2) $urlibServiceVersion] > 0} { # old version - reload the whole collection file delete ../auxdoc/.repositoryProperties.tcl file delete ../auxdoc/.referenceTable.tcl file delete ../auxdoc/.wordOccurrenceArray.tcl file delete ../auxdoc/.keyRepositoryList.tcl } if {[string compare $updateLevel(8) $urlibServiceVersion] > 0} { # old version - reload metadataRep file delete ../auxdoc/.wordOccurrenceArray.tcl } if {[string compare $updateLevel(12) $urlibServiceVersion] > 0} { # old version - reload repositoryProperties file delete ../auxdoc/.repositoryProperties.tcl } } } if [file exists ../auxdoc/.postEnvironmentArray.tcl] { set installInitialCollection 0 # Clean the clipboards and progressDir if ![regexp -- {-[xX]} $argv] { file delete -force $homePath/clipboard file mkdir $homePath/clipboard file delete -force $homePath/clipboard2 ;# same code is now in PutDocumentOnClipboard file mkdir $homePath/clipboard2 file delete -force $homePath/col/$URLibServiceRepository/doc/progressDir file mkdir $homePath/col/$URLibServiceRepository/doc/progressDir } # Clean the clipboards and progressDir - end } else { set installInitialCollection 1 ;# install MakeAllCgiScripts 0 } # Set urlibServerAddress if ![info exists postEnvironmentArray(urlibServerAddress)] { # not used anymore since 2007 (see GetURLibServerAddress) # 150.163.2.14:80 set postEnvironmentArray(urlibServerAddress) {33 {0 0 0} {1 0 0} {2 0 0} {3 0 0} {4 0 0} {5 0 0} {6 0 0} {7 0 0} {8 0 0} {9 0 0} {10 0 0} {11 0 0} {12 0 0} {13 3 {4 8 10}} {14 3 {4 8 10}} {15 5 {3 15}} {16 8 {1 5 11}} {17 9 9} {18 10 7} {19 11 12} {20 12 2} {21 13 6} {22 13 6} {23 14 14} {24 14 14} {25 15 13} {26 15 13} {27 15 13} {28 15 13} {29 15 13} {30 15 13} {31 15 13} {32 15 13} {33 15 13} {34 15 13} {35 15 13} {36 15 13} {37 15 13} {38 15 13} {39 15 13} {40 15 13} {41 15 13} {42 15 13} {43 15 13} {44 15 13} {45 15 13} {46 15 13} {47 15 13} {48 15 13} {49 15 13} {50 15 13} {51 15 13} {52 15 13} {53 15 13} {54 15 13} {55 15 13} {56 15 13} {57 15 13} {58 15 13} {59 15 13} {60 15 13} {61 15 13} {62 15 13} {63 15 13} {64 15 13} {65 15 13} {66 15 13} {67 15 13} {68 15 13} {69 15 13} {70 15 13} {71 15 13} {72 15 13} {73 15 13} {74 15 13} {75 15 13} {76 15 13} {77 15 13} {78 15 13} {79 15 13} {80 15 13} {81 15 13} {82 15 13} {83 15 13} {84 15 13} {85 15 13} {86 15 13} {87 15 13} {88 15 13} {89 15 13} {90 15 13} {91 15 13} {92 15 13} {93 15 13}} } # Set urlibServerAddress - end # Set sampledDocumentDBServerAddress if ![info exists postEnvironmentArray(sampledDocumentDBServerAddress)] { set postEnvironmentArray(sampledDocumentDBServerAddress) $postEnvironmentArray(urlibServerAddress) } # Set sampledDocumentDBServerAddress - end if ![info exists postEnvironmentArray(urlibadEMailAddress)] { ## banon@iconet.com.br # set postEnvironmentArray(urlibadEMailAddress) {33 {0 0 0} {1 0 0} {2 0 0} {3 0 0} {4 0 0} {5 0 0} {6 0 0} {7 0 0} {8 0 0} {9 0 0} {10 0 0} {11 0 0} {12 0 0} {13 2 {13 17}} {14 2 {13 17}} {15 2 {13 17}} {16 2 {13 17}} {17 2 {13 17}} {18 2 {13 17}} {19 2 {13 17}} {20 2 {13 17}} {21 2 {13 17}} {22 2 {13 17}} {23 2 {13 17}} {24 2 {13 17}} {25 2 {13 17}} {26 2 {13 17}} {27 2 {13 17}} {28 2 {13 17}} {29 2 {13 17}} {30 2 {13 17}} {31 3 6} {32 3 6} {33 3 6} {34 3 6} {35 3 6} {36 3 6} {37 3 6} {38 3 6} {39 3 6} {40 3 6} {41 3 6} {42 3 6} {43 3 6} {44 3 6} {45 3 6} {46 3 6} {47 3 6} {48 3 6} {49 3 6} {50 3 6} {51 3 6} {52 3 6} {53 3 6} {54 3 6} {55 3 6} {56 3 6} {57 3 6} {58 3 6} {59 3 6} {60 3 6} {61 3 6} {62 3 6} {63 3 6} {64 4 2} {65 6 {1 18}} {66 8 {8 14}} {67 8 {8 14}} {68 9 11} {69 9 11} {70 9 11} {71 9 11} {72 10 7} {73 10 7} {74 10 7} {75 10 7} {76 11 16} {77 14 {3 5 10}} {78 17 {4 9 15}} {79 17 {4 9 15}} {80 17 {4 9 15}} {81 18 19} {82 18 19} {83 19 12} {84 19 12} {85 19 12} {86 19 12} {87 19 12} {88 19 12} {89 19 12} {90 19 12} {91 19 12} {92 19 12} {93 19 12}} # urlibservice@gmail.com set postEnvironmentArray(urlibadEMailAddress) {33 {0 0 0} {1 0 0} {2 0 0} {3 0 0} {4 0 0} {5 0 0} {6 0 0} {7 0 0} {8 0 0} {9 0 0} {10 0 0} {11 0 0} {12 0 0} {13 1 19} {14 1 19} {15 1 19} {16 1 19} {17 1 19} {18 1 19} {19 1 19} {20 1 19} {21 1 19} {22 1 19} {23 1 19} {24 1 19} {25 1 19} {26 1 19} {27 1 19} {28 1 19} {29 1 19} {30 1 19} {31 2 13} {32 2 13} {33 2 13} {34 2 13} {35 2 13} {36 2 13} {37 2 13} {38 2 13} {39 2 13} {40 2 13} {41 2 13} {42 2 13} {43 2 13} {44 2 13} {45 2 13} {46 2 13} {47 2 13} {48 2 13} {49 2 13} {50 2 13} {51 2 13} {52 2 13} {53 2 13} {54 2 13} {55 2 13} {56 2 13} {57 2 13} {58 2 13} {59 2 13} {60 2 13} {61 2 13} {62 2 13} {63 2 13} {64 3 16} {65 4 5} {66 6 {11 20}} {67 6 {11 20}} {68 8 {7 12}} {69 8 {7 12}} {70 9 14} {71 9 14} {72 12 {4 10 17}} {73 12 {4 10 17}} {74 12 {4 10 17}} {75 14 {3 18}} {76 16 {15 22}} {77 16 {15 22}} {78 17 21} {79 17 21} {80 17 21} {81 19 {2 8}} {82 20 6} {83 20 6} {84 21 1} {85 22 9} {86 22 9} {87 22 9} {88 22 9} {89 22 9} {90 22 9} {91 22 9} {92 22 9} {93 22 9}} } # regionalURLibServerAddress - not used for the moment (should be used with banners) if ![info exists postEnvironmentArray(regionalURLibServerAddress)] { set postEnvironmentArray(regionalURLibServerAddress) $postEnvironmentArray(urlibServerAddress) } # sampledDocumentRegionalDBServerAddress - not used for the moment if ![info exists postEnvironmentArray(sampledDocumentRegionalDBServerAddress)] { set postEnvironmentArray(sampledDocumentRegionalDBServerAddress) $postEnvironmentArray(urlibServerAddress) } if ![info exists postEnvironmentArray(regionalURLibAdEMailAddress)] { set postEnvironmentArray(regionalURLibAdEMailAddress) $postEnvironmentArray(urlibadEMailAddress) } # SAVE StoreArray postEnvironmentArray ../auxdoc/.postEnvironmentArray.tcl # SAVE - end if [regexp -- {-[rR]} $argv] { # reset (may be necessarily after a "disk quota exceeded") # to force reset after an integrity alert and clean up once and for all the integrity alert, $homePath/@missingDirectoryList must be removed if [file exists $homePath/@missingDirectoryList] { Load $homePath/@missingDirectoryList fileContent # examples of fileContent: dir1A and dir1B/dir2A and dir1B/dir2B/dir3A and dir1B/dir2B/dir3B/dir4A set missingDirectoryList {} foreach dir $fileContent { if ![file isdirectory $homePath/col/$dir] {lappend missingDirectoryList $dir} } if [string equal {} $missingDirectoryList] { file delete $homePath/@missingDirectoryList } else { set list [join $missingDirectoryList \n] set message "reset not done; the following directories are missing and should be first retrieved:\n$list" puts [StoreLog {alert} {post (4)} $message] Store list $homePath/@missingDirectoryList } } if ![file exists $homePath/@missingDirectoryList] { file delete ../auxdoc/.repositoryProperties.tcl file delete ../auxdoc/.referenceTable.tcl file delete ../auxdoc/.wordOccurrenceArray.tcl file delete ../auxdoc/.keyRepositoryList.tcl file delete $homePath/@homePath ;# in order to update the cgi scripts at reset } } set repositoryListForPost {} if [file exists ../auxdoc/.repositoryListForPost.tcl] { source ../auxdoc/.repositoryListForPost.tcl ;# set the global variable repositoryListForPost } # puts [info exists loCoInRep] if ![regexp -- {-[xX]} $argv] { # Add migrated repositories # see "Zip repositories" in the administrator page cd $homePath set fileList [glob -nocomplain repositoryListForPostFromZipArchive*] cd $pwd if ![string equal {} $fileList] { if {$tcl_platform(platform) == "unix"} { foreach {userName groupName} [lrange [exec ls -l | grep post$] 2 3] {break} if 0 { # time consuming cd $homePath exec chmod -R g+w col exec chmod -R g+s col exec chgrp -R $groupName col cd $pwd } } set fileContent2 [MakeCgiScript $URLibServiceRepository {} update mirror.tcl {CreateMirror 1} cgi2 0] foreach file $fileList { Load $homePath/$file fileContent set repositoryList2 [split $fileContent \n] regsub {repositoryListForPostFromZipArchive} $file {} archiveName Load $homePath/serverAddressWithIPOfZipArchive$archiveName remoteServerAddressWithIP set repositoryList2 [split $fileContent \n] set repositoryList3 {} ;# list of repositories completely transferred set repositoryList4 {} ;# list of repositories not completely transferred foreach rep $repositoryList2 { if {$tcl_platform(platform) == "unix"} { cd $homePath exec chmod -R g+w col/$rep exec chmod -R g+s col/$rep exec chgrp -R $groupName col/$rep cd $pwd } # if ![TestContentType $rep Metadata] # Load $homePath/col/$rep/service/type repContentType if [regexp {Metadata} $repContentType] { # metadata repository Load $homePath/col/$rep/service/reference repReference regsub {../../../../../../col/} $repReference {} repName if [info exists metadataRepArray($repName)] { lappend metadataRepArray($repName) $rep } else { set metadataRepArray($repName) $rep } } else { # Update cgi2/update # useful when migrating a repository from one host collection to another using archive.zip created from the administrator page set updateFilePath $homePath/col/$rep/auxdoc/cgi2/update if [file exists $updateFilePath] { Load $updateFilePath fileContent if ![string equal $fileContent2 $fileContent] { Store fileContent2 $updateFilePath if {$tcl_platform(platform) == "unix"} { if [file owned $updateFilePath] {exec chmod 774 $updateFilePath} } } } # Update cgi2/update - end if [regexp -- {-[fF]} $argv] { # force migration (ignore the remote collection - it might be down forever) lappend repositoryList3 $rep set transferableFlag 1 StoreService transferableFlag $rep transferableFlag 1 1 ;# (B) } elseif {![GetDocumentState $rep] || ![info exists loCoInRep]} { # the document is not the original or the variable loCoInRep doesn't exist # file delete $homePath/col/$rep/service/transferableFlag lappend repositoryList3 $rep } else { # Update remote host collection # metadataRep # set metadataRep [FindMetadataRep $rep] # registrationPassword if [LoadService $rep registrationPassword registrationPassword 1 1] { # corrupted password # set log "post: $rep has a corrupted registration password" # puts $log # Store log $homePath/@errorLog auto 0 a puts [StoreLog {alert} {post (5)} "$rep has a corrupted registration password"] continue } set transferableFlag 0 ;# must remain 0 in A # Delete the remote host collection field value # SUBMIT # set message [Execute $remoteServerAddressWithIP [list UpdateHostCollectionFieldValue $rep $metadataRep $codedPassword {} $transferableFlag]] # set message [Execute $remoteServerAddressWithIP [list UpdateHostCollectionFieldValue $rep $registrationPassword {} $transferableFlag] 0] ;# not async # set message [Execute $remoteServerAddressWithIP [list UpdateHostCollectionFieldValue $rep $registrationPassword {} $transferableFlag]] set message [Execute $remoteServerAddressWithIP [list UpdateHostCollectionFieldValue $rep $registrationPassword $loCoInRep $transferableFlag]] # Delete the remote host collection field value - end if [string equal {transferable} $message] { lappend repositoryList3 $rep # Create a new registration password regsub {0\.} [expr [SortRandomNumber]/double(233280)] {} registrationPassword StoreService registrationPassword $rep registrationPassword 1 1 # Create a new registration password - end set transferableFlag 1 ;# end of transfer; must be 1 in B StoreService transferableFlag $rep transferableFlag 1 1 # set metadataList {} # set metadata2List {} # UpdateMetadataField $metadataRep transferableflag $transferableFlag metadataList metadata2List 1 # AddMetadata $metadataList } else { lappend repositoryList4 $rep if [string equal {} $message] { # set log "post: while processing $rep, UpdateHostCollectionFieldValue returned empty" puts [StoreLog {alert} {post (6)} "while processing $rep, UpdateHostCollectionFieldValue returned empty"] } else { # set log "post: while processing $rep, UpdateHostCollectionFieldValue returned the following message: $message" puts [StoreLog {alert} {post (7)} "while processing $rep, UpdateHostCollectionFieldValue returned the following message: $message"] } # puts $log # Store log $homePath/@errorLog auto 0 a } # Update remote host collection - end } } } set fullRepositoryList3 $repositoryList3 foreach rep $repositoryList3 { set fullRepositoryList3 [concat $fullRepositoryList3 $metadataRepArray($rep)] ;# adds the metadata repositories } set repositoryListForPost [concat $repositoryListForPost $fullRepositoryList3] ;# adds list of repositories completely transferred set numberOfUncompleteTransfer [llength $repositoryList4] if $numberOfUncompleteTransfer { # set log "post: transfer not completed with the archive $archiveName from $remoteServerAddressWithIP #the number of uncomplete transfer is $numberOfUncompleteTransfer" # puts $log # Store log $homePath/@errorLog auto 0 a puts [StoreLog {alert} {post (8)} "transfer not completed with the archive $archiveName from $remoteServerAddressWithIP: the number of uncomplete transfer is $numberOfUncompleteTransfer"] set fullRepositoryList4 $repositoryList4 foreach rep $repositoryList4 { set fullRepositoryList4 [concat $fullRepositoryList4 $metadataRepArray($rep)] ;# adds the metadata repositories } set fullRepositoryList4 [join $fullRepositoryList4 \n] Store fullRepositoryList4 $homePath/$file ;# list of repositories not completely transferred } else { file delete $homePath/$file file delete $homePath/serverAddressWithIPOfZipArchive$archiveName } } } # Add migrated repositories - end } # lappend repositoryListForPost {} ;# add here the list of repositories to be reloaded # referenceTable if [file exists ../auxdoc/.referenceTable.tcl] { if [catch {source ../auxdoc/.referenceTable.tcl}] { # .referenceTable.tcl has been corrupted file delete ../auxdoc/.referenceTable.tcl } } if {![file exists ../auxdoc/.referenceTable.tcl] || ![string equal {} $repositoryListForPost]} { if [file exists ../auxdoc/.referenceTable.tcl] { foreach rep $repositoryListForPost { UpdateReferenceTable $rep } } else { CreateRepositoryList foreach rep $repositoryList { UpdateReferenceTable $rep 0 } } # UpdateReferenceFileForLoCoInRep # StoreArray referenceTable ../auxdoc/.referenceTable.tcl SaveReferenceTable 1 } # repositoryProperties if [file exists ../auxdoc/.repositoryProperties.tcl] { catch {source ../auxdoc/.repositoryProperties.tcl} ;# .repositoryProperties.tcl might have been corrupted } if ![info exists repositoryProperties($URLibServiceRepository,history)] { # repositoryProperties has been corrupted puts {.repositoryProperties.tcl has been removed or is corrupted} puts {.repositoryProperties.tcl will be recreated} file delete ../auxdoc/.repositoryProperties.tcl } if {![file exists ../auxdoc/.repositoryProperties.tcl] || ![string equal {} $repositoryListForPost]} { if [file exists ../auxdoc/.repositoryProperties.tcl] { set repositoryList2 $repositoryListForPost } else { CreateRepositoryList set repositoryList2 $repositoryList } file delete ../auxdoc/.copyOfRepositoryProperties.tcl foreach rep $repositoryList2 { # if ![regexp {^[^/]+/[^/]+/\d{4,}/\d{2}\.\d{2}\.\d{2}\.\d{2}($|\.\d{2}$|\.\d{2}\.\d{3}$)} $rep] # if ![regexp {^[^/]+/[^/]+/\d{4,}/\d{2}\.\d{2}\.\d{2}\.\d{2}($|\.\d{2}$|\.\d{2}\.\d{1,}$)} $rep] { # not the repository syntax # ../auxdoc/.repositoryListForPost.tcl might be corrupted # set log "\[[clock format [clock seconds] -format %Y:%m.%d.%H.%M.%S]\] post (9):\n--$rep-- has not the repository syntax\nUpdateRepositoryProperties was not executed\n" # puts $log # Store log $homePath/@errorLog auto 0 a puts [StoreLog {alert} {post (9)} "--$rep-- has not the repository syntax\nUpdateRepositoryProperties was not executed"] if ![file exists ../auxdoc/.copyOfRepositoryProperties.tcl] { file copy -force ../auxdoc/.repositoryProperties.tcl ../auxdoc/.copyOfRepositoryProperties.tcl ;# used to manually check corrupted .repositoryListForPost.tcl file } continue } UpdateRepositoryProperties $rep } # StoreArray repositoryProperties ../auxdoc/.repositoryProperties.tcl SaveRepositoryProperties 1 } # loBiMiMetadataRep # this code must be here because of FindMetadataRep if {!$installInitialCollection && ![info exists environmentArray(localBibliographicMirrorMetadataRepository)]} { # migration - 2016-05-23 - environmentArray of Archive installed before 2016-05-18 doesn't have the entry localBibliographicMirrorMetadataRepository set loBiMiMetadataRep [FindMetadataRep $loBiMiRep] # puts --$loBiMiMetadataRep-- set environmentArray(localBibliographicMirrorMetadataRepository) $loBiMiMetadataRep ;# used just in LoadGlobalVariables StoreArrayWithBackup environmentArray ../auxdoc/.environmentArray.tcl w list } if [file exists $homePath/newVersion] { if [file exist ../auxdoc/.urlibServiceVersion.tcl] { source ../auxdoc/.urlibServiceVersion.tcl ;# set urlibServiceVersion } else { set urlibServiceVersion 0 } source $homePath/newVersion ;# set updateLevel # puts [expr [string compare $updateLevel(3) $urlibServiceVersion] > 0] if {[string compare $updateLevel(3) $urlibServiceVersion] > 0} { # old version - make the cgi scripts puts {updating cgi scripts...} MakeAllCgiScripts 0 puts {cgi scripts updated} } } if !$installInitialCollection { # Updating the cgi scripts after a home path change if 0 { # commented by GJFB in 2012-12-30 - $homePath/@homePath may be correct and the homePath in the cgi script incorrect Load $homePath/@homePath fileContent if ![string equal $homePath $fileContent] { # the cgi scripts must be updated puts {updating cgi scripts...} MakeAllCgiScripts 1 Store homePath $homePath/@homePath ;# used in post only puts {cgi scripts updated} } } else { if [regexp -- {-[cC]} $argv] {file delete ../auxdoc/cgi/get} Load ../auxdoc/cgi/get fileContent set rep $URLibServiceRepository set cgiScript [MakeCgiScript $rep $rep get get.tcl Get cgi 0] ;# to force updating remove cgi/get if ![string equal $cgiScript $fileContent] { # the cgi scripts must be updated puts {updating cgi scripts...} MakeAllCgiScripts 1 puts {cgi scripts updated} } } # Updating the cgi scripts after a home path change - end # Solve the accent problem after migration from a utf-8 local collection to a non utf-8 one, and vice versa # if [file exists $homePath/col/$URLibServiceRepository/auxdoc/@cgiCallFlagForPost] # # post has been called from a cgi script (see Administrator page) # if ![regexp -- {-[xX]} $argv] # # file delete $homePath/col/$URLibServiceRepository/auxdoc/@cgiCallFlagForPost # # # else # set encodingSystem [encoding system] Load $homePath/@encodingSystem encodingSystem2 if [string equal {utf-8} $encodingSystem] { # encoding system is utf-8 if ![string equal {utf-8} $encodingSystem2] { # @encodingSystem didn't exist (was not utf-8) # the service/encodingSystem files must be updated or created puts {updating service/encodingSystem files for metadata repositories...} CreateRepositoryList ;# set repositoryList foreach rep $repositoryList { if [TestContentType $rep Metadata] { # $rep contains a metadata Store encodingSystem $homePath/col/$rep/service/encodingSystem } } Store encodingSystem $homePath/@encodingSystem ;# used in post only puts {service/encodingSystem files updated for metadata repositories} } } else { # encoding system is not utf-8 if [string equal {utf-8} $encodingSystem2] { # @encodingSystem was utf-8 puts {removing service/encodingSystem files for metadata repositories...} CreateRepositoryList ;# set repositoryList foreach rep $repositoryList { if [TestContentType $rep Metadata] { # $rep contains a metadata Load $homePath/col/$rep/doc/@metadata.refer fileContent set fileContent [encoding convertfrom $encodingSystem2 $fileContent] ;# solves the accent problem when migrating from a collection using utf-8 encoding set mtime [file mtime $homePath/col/$rep/doc/@metadata.refer] Store fileContent $homePath/col/$rep/doc/@metadata.refer file mtime $homePath/col/$rep/doc/@metadata.refer $mtime ;# restore mtime file delete $homePath/col/$rep/service/encodingSystem } } file delete $homePath/@encodingSystem ;# used in post only puts {service/encodingSystem files removed for metadata repositories} } } # # Solve the accent problem after migration from a utf-8 local collection to a non utf-8 one, and vice versa - end } # MakeAllCgiScripts # set urlibServiceSiteWithIP 150.163.2.14:1905 ;# site having a copy of the URLibService last version # set urlibServiceSiteWithIP 150.163.2.175:1905 ;# site having a copy of the URLibService last version # set urlibServiceSiteWithIP 150.163.2.176 ;# plutao - site having a copy of the URLibService last version # urlibServiceSiteWithIP - site having a copy of the URLibService last version # set urlibServiceSiteWithIP [Execute urlib.net GetURLibServiceSiteWithIP] # urlibServiceSiteWithIP is needed in StartService if [file exists $homePath/@URLibServiceSiteWithIP.txt] { # the current site is urlib.net (no other sites should have this file) Load $homePath/@URLibServiceSiteWithIP.txt urlibServiceSiteWithIP } else { if [catch {Execute urlib.net GetURLibServiceSiteWithIP} urlibServiceSiteWithIP] { # puts [StoreLog {alert} {post (10)} "urlib.net site not found: $urlibServiceSiteWithIP"] puts [StoreLog {alert} {post (10)} "urlib.net site not found: computer probably in standalone mode"] set urlibServiceSiteWithIP {} } } # Unpost if [regexp -- {-[xX]} $argv] { # unpost if 0 { file mkdir $serverRoot/conf/VirtualHost2 cd $serverRoot/conf/VirtualHost2 set virtualHostConfList [glob -nocomplain *] cd $pwd if {[llength $virtualHostConfList] > 1} { set message [list {cannot unpost - more than one local collection are posted}] lappend message "the following ports are in use: $virtualHostConfList" puts [join $message \n] set log [join [concat {post:} $message] \n] Store log $homePath/@errorLog auto 0 a exit } } # Capture new URLibService version if [regexp -- {-[uU]} $argv] { puts {looking for new URLibService version...} set localLastVersion [GetURLibServiceLastVersion] if ![string equal {} $urlibServiceSiteWithIP] { set query {list GetURLibServiceLastVersion} # MULTIPLE SUBMIT set lastVersion {} # MultipleSubmit {} $query lastVersion 0 [list $urlibServiceSiteWithIP] MultipleSubmit {} $query lastVersion 1 [list $urlibServiceSiteWithIP] if ![string equal {} $lastVersion] { if ![string equal [lindex $localLastVersion 0] $lastVersion] { # Get the new version puts {capturing a new URLibService version...} if [file exists $homePath/doc.zip] { file rename -force $homePath/doc.zip $homePath/previousDoc.zip } set fileId [open $homePath/doc.zip w] proc Progress {token total current} { global iProgress if ![info exists iProgress] {set iProgress 0} incr iProgress if {[expr $iProgress % 20] == 0} { puts "[expr int(($current / $total.) * 100)]% done" } # puts -nonewline "." ;# nonewline doesn't work properly with windows 95 } set convertedURL [ConvertURLToHexadecimal http://$urlibServiceSiteWithIP/col/$URLibServiceRepository/download/doc.zip] ;# doc.zip is updated at post of urlibServiceSiteWithIP (see # Update URLibService in StartService) if [catch {http::geturl $convertedURL -progress Progress -channel $fileId} token] { close $fileId # puts "post: new URLibService version capture failed: $token" puts [StoreLog {alert} {post (11)} "new URLibService version capture failed: $token"] } else { # new URLibService version captured close $fileId http::cleanup $token set updateURLibServiceMessageForScript {the last URLibService version was captured} puts $updateURLibServiceMessageForScript Store updateURLibServiceMessageForScript $homePath/col/$URLibServiceRepository/auxdoc/@updateURLibServiceMessageForScript ;# used in Script (Administrator page) if 0 { # Extract a new version of URLibService source ExtractURLibService.tcl ExtractURLibService # Extract a new version of URLibService - end } } # Get the new version - end } else { set updateURLibServiceMessageForScript {there is no new URLibService version to capture} puts $updateURLibServiceMessageForScript Store updateURLibServiceMessageForScript $homePath/col/$URLibServiceRepository/auxdoc/@updateURLibServiceMessageForScript ;# used in Script (Administrator page) } } } } # Capture new URLibService version - end # Update the index # must be before Run-exit if [file exists ../auxdoc/.repositoryListForPost.tcl] { set mtime [file mtime ../auxdoc/.repositoryListForPost.tcl] Load ../auxdoc/previousRepositoryListForPostMtime previousRepositoryListForPostMtime if ![string equal $previousRepositoryListForPostMtime $mtime] { # the collection has been updated - the index must be updated too # UPDATE INDEX if [catch {http::geturl http://$localSite/createindex.cgi} message] { # catch error like: couln't open socket: host is unreachable - otherwise post ends set log "$message\n while executing\n\"http::geturl http://$localSite/createindex.cgi\"" puts [StoreLog {alert} {post (12)} $log] } else { http::cleanup $message } } file delete ../auxdoc/previousRepositoryListForPostMtime } # Update the index - end if 1 { if [catch {StopApacheServer} message] { puts [StoreLog {alert} {post (13)} $message] # exit } # httpd.pid file deleted } Load ../auxdoc/pid pid ;# pid of the URLib server # if [catch {Eval Run-exit $pid} message] # if [catch {Execute $serverAddressWithIP [list Run-exit $pid]} message] { puts [StoreLog {alert} {post (14)} $message] exit } puts {URLib local collection unposted} # to update three virtual hosts A, B and C # do (in any order) unpost A, unpost B, unpost C, post/unpost/post A, post/unpost/post B and post C (see auxdoc/serverDir/logs/virtualHostRunning in ExtractURLibService) # Extract a new version of URLibService source ExtractURLibService.tcl ExtractURLibService ;# placed here by GJFB in 2010-08-17 # Extract a new version of URLibService - end exit ;# end end end } # Unpost - end set installInitialCollection [expr ![info exists environmentArray(localCollectionIndexRepository)]] # Start the Service if !$installInitialCollection {StartService} # Start the Service - end # Start the URLib local collection server if [info exists environmentArray] { puts "starting the servers..." } if [StartLocalURLibServer] { # URLiService is probably running Load ../auxdoc/messageForStart message puts --$message-- # => if {$tcl_platform(platform) == "windows"} {vwait forever} if {$tcl_platform(platform) == "unix"} {exit} } # Start the URLib local collection server - end # puts >>>$environmentArray(ipAddress) # puts >>>$serverAddressWithIP set message [CheckURLibServerAccess] ;# CheckURLibServerAccess is in SPDialog.tcl # puts $message if !$installInitialCollection { ;# added by GJFB in 2016-04-28 - at installation serverAddressWithIP is empty foreach {serverName urlibPort} [ReturnCommunicationAddress $serverAddress] {break} foreach {ip urlibPort} [ReturnCommunicationAddress $serverAddressWithIP] {break} if [regexp {access not completed} $message] { Store message ../auxdoc/messageForStart # similar code in start set message [list $message {The communication with the URLib local collection server cannot be made.}] # lappend message "$serverName was used as server name." lappend message "$ip was used as IP." lappend message "$urlibPort was used as URLib port." lappend message {The URLib local collection has not been posted.} puts [StoreLog {alert} {post (15)} [join $message \n]] set x3 0; after 60000 {set x3 1}; vwait x3 ;# wait 60 seconds # puts [StoreLog {alert} {post (15)} [join $message \n]] # close $localURLibServer(socketId) ;# added by GJFB in 2016-06-27 - free the URLib port (ex: 19050) # source $homePath/col/$URLibServiceRepository/doc/post ;# added by GJFB in 2016-06-27 - run post again exit } } if 1 { StopApacheServer ;# it might be running } # if {$tcl_platform(platform) == "windows"} # ;# commented by GJFB in 2016-04-28 - ManageLogFile needs loCoInRep which has not been created yet at installation if {$tcl_platform(platform) == "windows" && !$installInitialCollection} { # Windows doesn't allow to change .log file name while Apache is running # managing log file must occur while Apache is stopped ManageLogFile $homePath/@errorLog ManageLogFile $homePath/col/$loCoInRep/auxdoc/@errorLog ;# added by GJFB in 2017-11-18 ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/access.log ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/error.log } set staticIPFlag [InformURLibSystem] ;# added by GJFB in 2017-10-15 - environmentArray(staticIPFlag) set in InformURLibSystem is required at installation # Start the Service at installation if $installInitialCollection { set staticIPFlag 0 ;# added by GJFB in 2016-04-28 - force dynamic IP is order to be able to use any type of IP at installation StartService } # Start the Service at installation - end if !$installInitialCollection { ;# added by GJFB in 2016-04-28 - serverAddress and serverAddressWithIP needed in CreateEnvironmentArray (called by startApacheServer) are unknown at installation because environmentArray is incomplete - one must wait for the execution of InformURLibSystem # now here to allow using http protocol # Start Apache server set startApacheServer 1 StartApacheServer # after 1000 {set waitForApache 1}; vwait waitForApache ;# wait 1 s - needed to allow the use of Apache by CreatePermissionList - added by GJFB in 2013-01-13 after 2000 {set waitForApache 1}; vwait waitForApache ;# wait 2 s - needed to allow the use of Apache by InformURLibSystem - added by GJFB in 2014-08-16 # Start Apache server - end } # Inform the URLib system # InformURLibSystem ;# commented by GJFB in 2010-08-23 - previously in StartService # set staticIPFlag [InformURLibSystem] ;# added by GJFB in 2010-08-23 - commented by GJFB in 2017-10-15 - now above # puts --$staticIPFlag-- set environmentArray(registrationFlag) 1 ;# value is 0 or 1; 1 means that the site has been registered at urlib.net; is 0 when communication with urlib.net failed (urlib.net is down) or the site has not been registered at urlib.net or the collection is being unposted # environmentArray(registrationFlag) is used to enable/disable the DD button and the "Submit a ..." menu in the tool bar # environmentArray(registrationFlag) is 0 if staticIPFlag is empty (communication with urlib.net failed (urlib.net is down) or the site has not been registered at urlib.net or the collection is beeing unposted) # environmentArray(registrationFlag) is 1 if staticIPFlag is 0 or 1 (registered collection) if [string equal {0} $staticIPFlag] { # the current collection is probably using dynamic IP if ![string equal {} $environmentArray(domainName)] { # the domain name must be fixed # site example: c010013416.fmvz.local:80 set hostName $environmentArray(hostName) ;# c010013416 - gjfb set domainName $environmentArray(domainName) ;# fmvz.local - Home set environmentArray(hostName) [string tolower $hostName.$domainName] ;# c010013416.fmvz.local - gjfb.home set environmentArray(domainName) {} # Update DOMAIN_NAME entre within .envArray.tcl # added by GJFB in 2016-05-22 array set env2 [array get env] unset env source ../auxdoc/.envArray.tcl ;# set env set env(DOMAIN_NAME) {empty} StoreArray env ../auxdoc/.envArray.tcl w list array 1 array set env [array get env2] # Update DOMAIN_NAME entre within .envArray.tcl - end } # elseif {[string equal {} $staticIPFlag]} # ;# commented by GJFB in 2017-04-28 } elseif {[string equal {} $environmentArray(staticIPFlag)]} { ;# added by GJFB in 2017-04-28 # communication with urlib.net failed (urlib.net is down) or the site has not been registered at urlib.net or the collection is being unposted set environmentArray(registrationFlag) 0 } # if $installInitialCollection { ;# added by GJFB in 2016-04-28 - now environmentArray allow to compute serverAddress and serverAddressWithIP # set serverAddress [GetServerAddress] ;# banon-pc2.dpi.inpe.br 800 # set serverAddressWithIP [GetServerAddress 1] # } # Inform the URLib system - end # Create environmentArray(permissionList) # Create environmentArray(languagePreference) ;# any changes in displayControl.tcl may require two unpost/post # Create environmentArray(displayReviewButton) CreatePermissionList $environmentArray(mirrorRepList) ;# CreatePermissionList needs Apache running when sourcing some displayControl.tcl files that use http::geturl # Create environmentArray(displayReviewButton) - end # Create environmentArray(languagePreference) - end # Create environmentArray(permissionList) - end StoreArrayWithBackup environmentArray ../auxdoc/.environmentArray.tcl w list ;# added by GJFB in 2012-05-28 - used by start if $installInitialCollection { ;# added by GJFB in 2016-04-28 - at installation oldServerAddress is empty set message "URLib local collection posted" ;# message used in start Store message ../auxdoc/messageForStart ;# used in PostLocalCollection to exit from PostLocalCollection and continue within start } else { # Update metadataArray and repArray with the correct site name # the domain name may have changed since the last start set oldServerAddress [lindex [GetMetadata $URLibServiceMetadataRepository-0,site] end] # puts "--$serverAddress-- --$oldServerAddress--" # if [string equal {} $oldServerAddress] # ;# commented by GJFB in 2016-04-28 if {[string equal {} $oldServerAddress] && $serverRoot2ExistenceFlag} { # oldServerAddress empty and not the first execution of post after an installation # .metadataArray.tcl is corrupted - added by GJFB in 2013-07-04 # set log "\n\[alert\] post (16): the file:\ncol/$URLibServiceRepository/auxdoc/.metadataArray.tcl\nis corrupted and must be deleted before posting again" # puts $log puts [StoreLog {alert} {post (16)} "the file:\ncol/$URLibServiceRepository/auxdoc/.metadataArray.tcl\nis corrupted and must be deleted before posting again"] exit } if ![string equal $serverAddress $oldServerAddress] { puts "changing site name $oldServerAddress to $serverAddress into metadataArray and repArray..." set metadata2List [GetMetadata *-0,site] puts "change expected time: [expr int(0.04 * [llength $metadata2List])] seconds" ;# ~40 milliseconds per record RemoveMetadata $metadata2List array set localMetadataArray $metadata2List foreach i [array names localMetadataArray] { set localMetadataArray($i) $serverAddress } AddMetadata [array get localMetadataArray] puts "site name changed to: $serverAddress into metadataArray and repArray" } # Update metadataArray and repArray with the correct site name - end } # Update $homePath/index.html StoreIndex # Update $homePath/index.html - end if {[info exists loCoInRep] && $loCoInRep != "$devLoCoInRep"} { file delete $homePath/newVersion } if [file exists $homePath/readOnlySite] {Link {} $serverAddress} if [file exists $homePath/readOnlySite] { puts {read only site} } if {$tcl_platform(platform) == "unix"} { # cd $homePath # exec chmod -R g+w col ;# unzip might not preserve write permission for group - time consuming # cd $pwd # create kill set httpdPid {} while {[string equal {} $httpdPid]} { set xw 0; after 100 {set xw 1}; vwait xw # Load $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/httpd.pid httpdPid Load $serverRoot2/logs/httpd.pid httpdPid } set kill {} if [file exists $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/httpd.pid] { append kill "kill -TERM $httpdPid\n" append kill "rm -f \"$homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/httpd.pid\"\n" } Load $homePath/col/$URLibServiceRepository/auxdoc/pid pid append kill "kill -9 $pid" file delete $homePath/kill ;# otherwise chmod may not work because of a different owner Store kill $homePath/kill exec chmod 755 $homePath/kill if !$installInitialCollection { ;# added by GJFB in 2016-04-28 - at installation serverName doesn't exist puts "servers at >>> $serverAddress \[$serverName\] started" } Load ../auxdoc/apacheVersion apacheVersion puts $apacheVersion set message "URLib local collection posted at $localSite" ;# message used in start puts $message # puts {(to unpost, execute the command: post -- -x)} puts {(to unpost, execute the command: ./post -x)} } set localSite [ReturnHTTPHost] # if {$tcl_platform(platform) == "windows"} # if {$tcl_platform(platform) == "windows" && !$installInitialCollection} { ;# added by GJFB in 2016-04-28 - at installation serverName doesn't exist puts "servers at >>> $serverAddress \[$serverName\] started" Load ../auxdoc/apacheVersion apacheVersion puts $apacheVersion set message "URLib local collection posted at $localSite" ;# message used in start puts $message regsub -all {/} $tclPath {\\} path1 regsub -all {/} "$homePath/col/$URLibServiceRepository/doc" {\\} path2 puts "(to unpost, execute the command: $path1 post -x starting in: $path2)" # Open the bibliographic mirror within the navigator after 1000 {set wait 1}; vwait wait ;# wait 1 s - needed when opening Firefox (otherwise Fiferox open in offline mode) - added by GJFB in 2010-11-25 set language $environmentArray(spLanguageEntry) Link {} $localSite/col/$loBiMiRep/doc/mirror.cgi?languagebutton=$webLanguageTable($language) # Open the bibliographic mirror within the navigator - end } Store message ../auxdoc/messageForStart ;# used in PostLocalCollection to exit from PostLocalCollection and continue within start if {$tcl_platform(os) == "Linux"} { exec which nslookup > $homePath/col/$URLibServiceRepository/auxdoc/whichMessage Load $homePath/col/$URLibServiceRepository/auxdoc/whichMessage message if [regexp ^no $message] {puts [StoreLog {alert} {post (17)} $message]} } #set body [info body StartService] #set body2 [info body StartService] #if {[string compare $body $body2] == 0} { # puts {uncorrupted code} #} else { # puts {corrupted code} #} # vwait forever set previousRepositoryListForPostMtime {} set startingTime 02:00:00 ;# for managing log files and testing local collection integrity set testingFlag 0 ;# 1 is for testing log file managment and testing local collection integrity if $testingFlag { set timePeriod [expr 30] ;# 1/2 minute - for testing log file managment and testing local collection integrity } else { set timePeriod [expr 24*60*60] ;# 1 day - for managing log files and testing local collection integrity } set startingSecond [clock scan $startingTime -base 109306800] ;# for managing log files and testing local collection integrity if $testingFlag {set numberOfIterations 5} else {set numberOfIterations 1800} file delete $homePath/col/$URLibServiceRepository/auxdoc/@updateURLibServiceMessageForPost while 1 { if 0 { # set forever 0; after 3600000 {set forever 1}; vwait forever ;# wait for 1 hour - works as well if [info exists forever] {unset forever} if $testingFlag { after 10000 {set forever 1}; vwait forever ;# wait for 10 seconds - for testing log file managment and testing local collection integrity } else { after 3600000 {set forever 1}; vwait forever ;# wait for 1 hour } } else { set i 0 while {$i < $numberOfIterations} { if [info exists forever] {unset forever} after 2000 {set forever 1}; vwait forever ;# wait for 2 seconds incr i if [file exists $homePath/col/$URLibServiceRepository/auxdoc/@updateURLibServiceMessageForPost] { ;# created in Script (Administrator page) exec $homePath/updateURLibService & file delete $homePath/col/$URLibServiceRepository/auxdoc/@updateURLibServiceMessageForPost } } } set seconds [clock seconds] # set xxx [clock seconds] # Store xxx C:/tmp/bbb auto 0 a # Create/update Index if [file exists $homePath/col/$loCoInRep/doc/index1.html] { if [file exists ../auxdoc/.repositoryListForPost.tcl] { set mtime [file mtime ../auxdoc/.repositoryListForPost.tcl] if ![string equal $previousRepositoryListForPostMtime $mtime] { # the collection has been updated - the index must be updated too # UPDATE INDEX if [catch {http::geturl http://$localSite/createindex.cgi} message] { # catch error like: couln't open socket: host is unreachable - otherwise post ends set log "$message\n while executing\n\"http::geturl http://$localSite/createindex.cgi\"" puts [StoreLog {alert} {post (18)} $log] } else { http::cleanup $message set previousRepositoryListForPostMtime $mtime Store previousRepositoryListForPostMtime ../auxdoc/previousRepositoryListForPostMtime ;# useful when unposting URLibService } } } } else { # CREATE INDEX if [catch {http::geturl http://$localSite/createindex.cgi} message] { # catch error like: couln't open socket: host is unreachable - otherwise post ends set log "$message\n while executing\n\"http::geturl http://$localSite/createindex.cgi\"" puts [StoreLog {alert} {post (19)} $log] } else { http::cleanup $message } } # Create/update Index - end # Manage log files and test local collection integrity if [file exists ../auxdoc/@manageLogFile] { set mtime [file mtime ../auxdoc/@manageLogFile] } else { set mtime $startingSecond ;# force manage log files and test local collection integrity } # puts "[expr ($seconds - $startingSecond)/$timePeriod] != [expr ($mtime - $startingSecond)/$timePeriod]" if {[expr ($seconds - $startingSecond)/$timePeriod] != [expr ($mtime - $startingSecond)/$timePeriod]} { # let the transition time set = {starting second + n * time period: n = 0, 1, ...} # since the last update (mtime) at least one transition time occured if {$tcl_platform(platform) != "windows"} { # Windows doesn't allow to change .log file name while Apache is running # Manage log files ManageLogFile $homePath/@errorLog ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/access.log ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/error.log # Manage log files } # Test local collection integrity puts {testing local collection integrity...} Load $homePath/col/$loCoInRep/auxdoc/xxx data binary set data [UnShift $data] set administratorCodedPassword [lindex $data end] set repositoryList1 [Select2 repository {repository, *} $administratorCodedPassword] set repositoryList2 [Select2 metadatarepository {repository, *} $administratorCodedPassword] set repositoryList3 [list $loCoInRep $loBiMiRep] ;# permanent repositories - should not be removed set repositoryList4 [FindMetadataRepList $loCoInRep] ;# permanent metadata repositories - should not be removed set repositoryList5 [FindMetadataRepList $loBiMiRep] ;# permanent metadata repositories - should not be removed # set xxx $repositoryList1 # Store xxx C:/tmp/bbb.txt auto 0 a set repositoryList [lsort -unique [concat $repositoryList1 $repositoryList2 $repositoryList3 $repositoryList4 $repositoryList5]] set dirList1 {} set dirList2 {} set dirList3 {} foreach repository $repositoryList { set splitedRep [file split $repository] lappend dirList1 [lindex $splitedRep 0] lappend dirList2 [eval file join [lrange $splitedRep 0 1]] lappend dirList3 [eval file join [lrange $splitedRep 0 2]] } # puts [lsort -unique $dirList1] set missingDirectoryList {} ;# no directory foreach dir [lsort -unique $dirList1] { if ![file isdirectory $homePath/col/$dir] {lappend missingDirectoryList $dir} ;# ex: dir1A } foreach dir [lsort -unique $dirList2] { set continueFlag 0 foreach missingDir $missingDirectoryList { if [regexp ^$missingDir/ $dir] {set continueFlag 1; break} } if $continueFlag {continue} ;# dir is part of missingDir - ex: dir1A/dir2A if ![file isdirectory $homePath/col/$dir] {lappend missingDirectoryList $dir} ;# ex: dir1A and dir1B/dir2A } foreach dir [lsort -unique $dirList3] { set continueFlag 0 foreach missingDir $missingDirectoryList { if [regexp ^$missingDir/ $dir] {set continueFlag 1; break} } if $continueFlag {continue} ;# dir is part of missingDir - ex: dir1A/dir2A/dir3A or dir1B/dir2A/dir3A if ![file isdirectory $homePath/col/$dir] {lappend missingDirectoryList $dir} ;# ex: dir1A and dir1B/dir2A and dir1B/dir2B/dir3A } foreach repository $repositoryList { set continueFlag 0 foreach missingDir $missingDirectoryList { if [regexp ^$missingDir/ $repository] {set continueFlag 1; break} } if $continueFlag {continue} ;# repository is part of missingDir - ex: dir1A/dir2A/dir3A/dir4A or dir1B/dir2A/dir3A/dir4A and dir1B/dir2B/dir3A/dir4A if ![file isdirectory $homePath/col/$repository] {lappend missingDirectoryList $repository} ;# ex: dir1A and dir1B/dir2A and dir1B/dir2B/dir3A and dir1B/dir2B/dir3B/dir4A } if [string equal {} $missingDirectoryList] { file delete $homePath/@missingDirectoryList } else { set list [join $missingDirectoryList \n] set message "missing directories:\n$list" puts [StoreLog {alert} {post (20)} $message] Store list $homePath/@missingDirectoryList } # Test local collection integrity - end set fileContent {could be anything} Store fileContent ../auxdoc/@manageLogFile } # Manage log files and test local collection integrity - end } ;# end of while } m] { # set log "post (21): $errorInfo" # Store log $homePath/@errorLog auto 0 a # puts $log ;# useful with unix puts [StoreLog {error} {post (21)} $errorInfo] set x4 0; after 40000 {set x4 1}; vwait x4 ;# wait 40 seconds }