#!/bin/sh # Copyright for URLibService (c) 1995 - 2013, # 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 \ #exec ../../../../../\ #dpi.inpe.br/banon/1997/10.21.17.24\ #/doc/tcl8.0/unix/tclsh "$0" ${1+"$@"} # post \ exec /usr/local/bin/tclsh "$0" ${1+"$@"} 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 set newibiurlcodeFlag 0 # global variables needed for post # 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 # environmentArray # homePath # htpasswdPath # inverseTable ## letterPattern ;# used by SetNoMatch (Search.tcl) # 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 # diskSpeed ;# set and use only in GetSiteInformation # 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 # 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 { # Load global variables # installInitialCollection doesn't exist LoadGlobalVariables 0 ;# sources environmentArray # Load global variables - end # puts --$zipPath-- if ![regexp -- {-[xX]} $argv] { ## set log "post (1):\nstarting URLibService \[[clock format [clock seconds] -format %Y:%m.%d.%H.%M.%S]\]\n" # set log "\[[clock format [clock seconds] -format %Y:%m.%d.%H.%M.%S]\] \[notice\] post (1):\nstarting URLibService\n" ## puts $log # Store log $homePath/@errorLog auto 0 a 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 } } FindInternetAddress ;# updates environmentArray ;# added by GJFB in 2010-09-25 - the domain name might be wrong and is fixed at unpost (using InformURLibSystem return) } # pid # used by Set, Unset, Lappend, Array, Get and ServeLocalCollection set pid [pid] Store pid ../auxdoc/pid if 0 { # Load global variables # installInitialCollection doesn't exist LoadGlobalVariables 0 ;# sources environmentArray # Load global variables - end } # FindInternetAddress ;# updates environmentArray ;# commented by GJFB in 2010-09-25 - the domain name might be wrong and is not fixed at unpost 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 serverAddress [GetServerAddress] ;# banon-pc2.dpi.inpe.br 800 set serverAddressWithIP [GetServerAddress 1] set localSite [ReturnHTTPHost] ;# banon-pc2.dpi.inpe.br or www.urlib.net set localSiteWithIP [ReturnHTTPHost $serverAddressWithIP] # Create @serverRoot2 and @serverAddressWithIP # set convertedURL [ConvertURLToHexadecimal http://$ipPort/@serverRoot2] set convertedURL [ConvertURLToHexadecimal http://$localSiteWithIP/@serverRoot2] if [catch {http::geturl $convertedURL} token] { # apache is not running set serverRoot2 $serverRoot Store serverAddressWithIP $homePath/@serverAddressWithIP ;# used to restart apache } else { # apache is running set serverRoot2 [string trim [http::data $token] \n] set convertedURL [ConvertURLToHexadecimal http://$localSiteWithIP/@serverAddressWithIP] set token [http::geturl $convertedURL] set remoteServerAddressWithIP [string trim [http::data $token] \n] 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) # set letterPattern a-zA-ZáàãâäçéèêëíìîïóòõôöúùûüýÿÁÀÃÂÄÇÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÝŸ # Load variables - end SourceLanguage environmentArray if [regexp -- {-[xX]} $argv] { 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 exit } } puts {} 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 {} puts {posting the URLib local collection...} if [catch {exec $apachePath -v > ../auxdoc/apacheVersion &} message] { set log "post (3): $message" puts $log Store log $homePath/@errorLog auto 0 a 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 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 } # Clean the clipboards - 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 necessary after a "disk quota exceeded") 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 } 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 for ever) lappend repositoryList3 $rep set transferableFlag 1 StoreService transferableFlag $rep transferableFlag 1 1 ;# (B) } elseif {![GetDocumentState $rep]} { # the document is not the original # 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 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]] # set message [Execute $remoteServerAddressWithIP [list UpdateHostCollectionFieldValue $rep $registrationPassword {} $transferableFlag] 0] ;# not async # 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" } else { set log "post: 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 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 } # 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] { CreateRepositoryList foreach rep $repositoryList { UpdateReferenceTable $rep 0 } } else { foreach rep $repositoryListForPost { UpdateReferenceTable $rep } } # UpdateReferenceFileForLoCoInRep # StoreArray referenceTable ../auxdoc/.referenceTable.tcl SaveReferenceTable 1 } # repositoryProperties if [file exists ../auxdoc/.repositoryProperties.tcl] { catch {source ../auxdoc/.repositoryProperties.tcl} ;# .repositoryProperties.tcl may 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] { CreateRepositoryList set repositoryList2 $repositoryList } else { set repositoryList2 $repositoryListForPost } 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 (4):\n--$rep-- has not the repository syntax\nUpdateRepositoryProperties was not executed\n" puts $log Store log $homePath/@errorLog auto 0 a 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 } 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} } } # Updating the cgi scripts after a home path change if !$installInitialCollection { 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 { Load ../auxdoc/cgi/get fileContent set rep $URLibServiceRepository set cgiScript [MakeCgiScript $rep $rep get get.tcl Get cgi 0] if ![string equal $cgiScript $fileContent] { # the cgi scripts must be updated puts {updating cgi scripts...} MakeAllCgiScripts 1 puts {cgi scripts updated} } } set encodingSystem [encoding system] Load $homePath/@encodingSystem encodingSystem2 if [string equal {utf-8} $encodingSystem] { # is utf-8 if ![string equal $encodingSystem $encodingSystem2] { # @encodingSystem was not utf-8 or didn't exist # 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 { # is not utf-8 if [string equal {utf-8} $encodingSystem2] { # 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} } } } # Updating the cgi scripts after a home path change - 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.34.239 ;# plutao - site having a copy of the URLibService last version # 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] 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 $localLastVersion $lastVersion] { # Get the new version puts {capturing 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" } else { # new URLibService version captured close $fileId puts {new URLibService version captured} if 0 { # Extract a new version of URLibService source ExtractURLibService.tcl ExtractURLibService # Extract a new version of URLibService - end } } # Get the new version - end } } } # 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 "post (5): $message" puts $log Store log $homePath/@errorLog auto 0 a } } file delete ../auxdoc/previousRepositoryListForPostMtime } # Update the index - end if [catch {StopApacheServer} message] { puts $message set log [concat {post:} $message] Store log $homePath/@errorLog auto 0 a # exit } # httpd.pid file deleted Load ../auxdoc/pid pid # if [catch {Eval Run-exit $pid} message] # if [catch {Execute $serverAddressWithIP [list Run-exit $pid]} message] { puts $message set log [concat {post:} $message] Store log $homePath/@errorLog auto 0 a 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 set message [CheckURLibServerAccess] ;# CheckURLibServerAccess is in SPDialog.tcl # puts $message foreach {serverName 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 "$urlibPort was used as URLib port." lappend message {The URLib local collection has not been posted.} puts [join $message \n] set log [join [concat {post:} $message] \n] Store log $homePath/@errorLog auto 0 a set x3 0; after 5000 {set x3 1}; vwait x3 ;# wait 5 seconds exit } if 1 { StopApacheServer ;# it might be running } if {$tcl_platform(platform) == "windows"} { # Windows doesn't allow to change .log file name while apache is running # managing log file must occur while apache is stopped ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/access.log ManageLogFile $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/error.log } # Start the Service if $installInitialCollection {StartService} # Start the Service - 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 # puts --$staticIPFlag-- set environmentArray(registrationFlag) 1 ;# value is 0 or 1; 1 means that the site has been registered at urlib.net 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 set domainName $environmentArray(domainName) ;# fmvz.local set environmentArray(hostName) [string tolower $hostName.$domainName] ;# c010013416.fmvz.local set environmentArray(domainName) {} # StoreArrayWithBackup environmentArray ../auxdoc/.environmentArray.tcl ;# added by GJFB in 2010-08-05 } } elseif {[string equal {} $staticIPFlag]} { # the site has not been registered at urlib.net set environmentArray(registrationFlag) 0 } if 0 { # now below StoreArrayWithBackup environmentArray ../auxdoc/.environmentArray.tcl ;# added by GJFB in 2012-05-28 - used by start } # Inform the URLib system - end # Start Apache server set startApacheServer 1 StartApacheServer # Start Apache server - end 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 if 1 { # was in StartService # 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 ;# added by GJFB in 2012-05-28 - used by start } # 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] { # .metadataArray.tcl is corrupted - added by GJFB in 2013-07-04 set log "\n\[alert\] post (6): the file:\ncol/$URLibServiceRepository/auxdoc/.metadataArray.tcl\nis corrupted and must be deleted before posting again" puts $log 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] ## Update $homePath/index.html # StoreIndex ## Update $homePath/index.html - end puts "site name changed to: $serverAddress into metadataArray and repArray" } # Update metadataArray and repArray with the correct site name - end # if ![file exists $homePath/index.html] # # Update $homePath/index.html StoreIndex # Update $homePath/index.html - end # # Robot protocol if ![file exists $homePath/robots.txt] { set fileContent \ "User-agent: * Disallow: " Store fileContent $homePath/robots.txt } # Robot protocol - end ## Migration 30/12/02 #if [file exists $homePath/newVersion] { # if {[string compare $updateLevel(10) $urlibServiceVersion] > 0} { ## old version - new index.html file # StoreIndex # } #} ## Migration 30/12/02 - 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 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)} } set localSite [ReturnHTTPHost] if {$tcl_platform(platform) == "windows"} { # puts {(to unpost, click the x button of this window, #then click the Yes button of the warning window)} regsub -all {/} $tclPath {\\} path1 regsub -all {/} "$homePath/col/$URLibServiceRepository/doc" {\\} path2 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: $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 #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 set timePeriod [expr 24*60*60] ;# 1 day # set timePeriod [expr 60] ;# 1 minute - for testing log file managment set startingSecond [clock scan $startingTime -base 109306800] while 1 { # set forever 0; after 3600000 {set forever 1}; vwait forever ;# wait for 1 hour - works as well if [info exists forever] {unset forever} after 3600000 {set forever 1}; vwait forever ;# wait for 1 hour # after 10000 {set forever 1}; vwait forever ;# wait for 10 seconds - for testing log file managment set seconds [clock seconds] # set xxx [clock seconds] # Store xxx C:/tmp/bbb auto 0 a if [file exists $homePath/col/$loCoInRep/doc/index1.html] { if [file exists ../auxdoc/.repositoryListForPost.tcl] { set mtime [file mtime ../auxdoc/.repositoryListForPost.tcl] # if {[expr ($seconds - $startingSecond)/$timePeriod] == [expr ($mtime - $startingSecond)/$timePeriod]} # 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 "post (7): $message" puts $log Store log $homePath/@errorLog auto 0 a } else { 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 "post (8): $message" puts $log Store log $homePath/@errorLog auto 0 a } } if {$tcl_platform(platform) != "windows"} { # Windows doesn't allow to change .log file name while apache is running if [file exists ../auxdoc/@manageLogFile] { set mtime [file mtime ../auxdoc/@manageLogFile] 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 leat one transition time occured # MANAGE LOG FILE foreach absolutePath [ \ list \ $homePath/@errorLog \ $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/access.log \ $homePath/col/$URLibServiceRepository/auxdoc/serverDir/logs/error.log \ ] { ManageLogFile $absolutePath } set fileContent {could be anything} Store fileContent ../auxdoc/@manageLogFile } } else { set fileContent {could be anything} Store fileContent ../auxdoc/@manageLogFile } } } } m] { set log "post (9): $errorInfo" Store log $homePath/@errorLog auto 0 a puts $log ;# useful with unix set x4 0; after 40000 {set x4 1}; vwait x4 ;# wait 40 seconds }