Rev 119 | Blame | Last modification | View Log | RSS feed
Option Explicit'=====================================================' Name: pkg_archive' Description: This library contains methods required' for dpkg_archive and deploy_archive' manipulation.'=====================================================Class PkgArchive'================ Properties Declaration =============Private pRemote_HostPrivate pArchive_Path'==================== Properties =====================Public Property Let Remote_Host( SSrhost )pRemote_Host = SSrhostEnd PropertyPublic Property Let Archive_Path( SSarch_path )pArchive_Path = UnixPath(SSarch_path)End Property'====================== Methods ======================'-----------------------------------------------------------------------------------------------------------------Private Sub Get_Archive_Telnet_Login_Details ( outUser, outPassword )outUser = "root"outPassword = "shoo7gaC"End Sub'-----------------------------------------------------------------------------------------------------------------Private Sub Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )outUser = "erggroup\svukovic"outPassword = "4digimoveerg"End Sub'-----------------------------------------------------------------------------------------------------------------Function UnixPath( SSpath )If SSpath <> "" Then UnixPath = Replace( SSpath, "\", "/" )End Function'-----------------------------------------------------------------------------------------------------------------Sub Ensure_Read_Write ( SSpkg_name, SSpkg_version )Dim outMachine, outUser, outPasswordDim login_details, command, sysShell, oExec, outStrOut, outStrErrCall Get_Archive_Telnet_Login_Details ( outUser, outPassword )' Set all folders to +RWX and all files to +RW' --- Commands to run ---command = _"cd "& pArchive_Path &" && "&_"chmod a+rwx "& SSpkg_name &"; "&_"cd "& SSpkg_name &" && "&_"find '"& SSpkg_version &"' -type d -exec chmod a+rwx {} \; ; "&_"chmod -R a+rw "& SSpkg_version &"; "WScript.Echo command' --- SSH client with login details ---login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPasswordSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( login_details &" "& command )outStrOut = oExec.StdOut.ReadAlloutStrErr = oExec.StdErr.ReadAllIf outStrErr <> "" ThenCall Raise_Event ( enumEVENT_ERROR, "[sub:Ensure_Read_Write]", _"user: "& outUser & VBNewLine &_"command: "& command , _outStrErr, enum_RELEASE_NOTES_FAILED )End IfSet oExec = NothingSet sysShell = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub All_Read_Only ( SSpkg_name, SSpkg_version )Dim outMachine, outUser, outPasswordDim login_details, command, sysShell, oExec, outStrOut, outStrErrCall Get_Archive_Telnet_Login_Details ( outUser, outPassword )' Set all folders from version folder, to -W and all files to -W' --- Commands to run ---command = _"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_"find '"& SSpkg_version &"' -type d -exec chmod a-w {} \; ; "&_"chmod -R a-w "& SSpkg_version &"; "WScript.Echo command' --- SSH client with login details ---login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPasswordSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( login_details &" "& command )outStrOut = oExec.StdOut.ReadAlloutStrErr = oExec.StdErr.ReadAllIf outStrErr <> "" ThenCall Raise_Event ( enumEVENT_ERROR, "[sub:All_Read_Only]", _"user: "& outUser & VBNewLine &_"command: "& command , _outStrErr, enum_RELEASE_NOTES_FAILED )End IfSet oExec = NothingSet sysShell = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Create_Doc_Folder ( SSpkg_name, SSpkg_version, docFolder )Dim outMachine, outDpkg_root, outUser, outPasswordDim login_details, command, sysShell, oExec, outStrOut, outStrErrCall Get_Archive_Telnet_Login_Details ( outUser, outPassword )' --- Commands to run ---' Creates doc folder if required with rwx permissions for allcommand = _"cd "& pArchive_Path &"/"& SSpkg_name &"/"& SSpkg_version &" && "&_"mkdir -p -m a+rwx "& docFolder &"; "WScript.Echo command' --- SSH client with login details ---login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPasswordSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( login_details &" "& command )outStrOut = oExec.StdOut.ReadAlloutStrErr = oExec.StdErr.ReadAllIf outStrErr <> "" ThenCall Raise_Event ( enumEVENT_ERROR, "[sub:Create_Doc_Folder]", _"user: "& outUser & VBNewLine &_"command: "& command , _outStrErr, enum_RELEASE_NOTES_FAILED )End IfSet oExec = NothingSet sysShell = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Create_Pkg_Folder ( SSpkg_name, SSpkg_version )Dim outMachine, outDpkg_root, outUser, outPasswordDim login_details, command, sysShell, oExec, outStrOut, outStrErrCall Get_Archive_Telnet_Login_Details ( outUser, outPassword )' --- Commands to run ---' Creates pkg_name and pkg_version folder if required with rwx permissions for allcommand = _"cd "& pArchive_Path &" && "&_"mkdir -p -m a+rwx "& SSpkg_name &"; "&_"cd "& pArchive_Path &"/"& SSpkg_name &" && "&_"mkdir -p -m a+rwx "& SSpkg_version &"; "WScript.Echo command' --- SSH client with login details ---login_details = AppPath & SSH_EXE &" -ssh -batch "& outUser &"@"& pRemote_Host &" -pw "& outPasswordSet sysShell = WScript.CreateObject("WScript.Shell")Set oExec = sysShell.Exec( login_details &" "& command )outStrOut = oExec.StdOut.ReadAlloutStrErr = oExec.StdErr.ReadAllIf outStrErr <> "" ThenCall Raise_Event ( enumEVENT_ERROR, "[sub:Create_Pkg_Folder]", _"user: "& outUser & VBNewLine &_"command: "& command , _outStrErr, enum_RELEASE_NOTES_FAILED )End IfSet oExec = NothingSet sysShell = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Sub Map_Network_Drive ( SSunc, outMappedDrive )Dim outUser, outPasswordDim ValidDrivesARR, validDrive, UsedDrivesDim i, WshNetwork, oDrives, oFilesys, drvWScript.Echo "Mapping drive..."Call Get_Archive_Map_Drive_Login_Details ( outUser, outPassword )ValidDrivesARR = Array("B:","E:","F:","G:","H:","I:","J:","K:","L:","M:","N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:")Set WshNetwork = WScript.CreateObject("WScript.Network")Set oDrives = WshNetwork.EnumNetworkDrives' Check for existing mapoutMappedDrive = ""For i = 0 to oDrives.Count - 1 Step 2If UCase(oDrives.Item(i+1)) = UCase(SSunc) ThenoutMappedDrive = oDrives.Item(i)Exit ForEnd IfNextIf outMappedDrive = "" Then' Drive need to be mapped, hence map one.' Get all drive used drive letters.' NOTE: It will not display a drive if mapped but not connected.Set oFilesys = CreateObject("Scripting.FileSystemObject")Set oDrives = oFilesys.DrivesFor Each drv in oDrivesUsedDrives = UsedDrives &"|"& drv.DriveLetter &":|"NextFor Each validDrive In ValidDrivesARRIf NOT InStr( UCase(UsedDrives), "|"& UCase(validDrive) &"|") > 0 Then' used this unused driveOn Error Resume NextWshNetwork.MapNetworkDrive validDrive, SSunc, FALSE, outUser, outPasswordCall ErrorCheck ( "[sub:Map_Network_Drive]", _"used drives: "& UsedDrives & VBNewLine &_"valid letters to pick from: "& Join( ValidDrivesARR, ",") & VBNewLine &_"attempting to map: "& validDrive & VBNewLine &_"UNC: "& SSunc )outMappedDrive = validDriveExit ForEnd IfNextEnd IfIf outMappedDrive = "" ThenCall Raise_Event ( enumEVENT_ERROR, "[sub:Map_Network_Drive]", _"used drives: "& UsedDrives & VBNewLine &_"valid drives to pick from: "& Join( ValidDrivesARR, ",") , _"Network drive is not mapped!", enum_RELEASE_NOTES_FAILED )End IfWScript.Echo "Using network drive: "& outMappedDriveSet oDrives = NothingSet WshNetwork = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------End Class