Get the App
SLTechnology News&Howtos  ›  Servers  › 

Flush authorization automatic update script

Shulou Source: shulou.com Published: 2022-06-02 14:12:57 09月21日 Update

I believe that if you have a lot of temporary authorization for flush, manual update is very troublesome, and there is too much repetitive work, you can use the following powershell script downkey.ps1 to achieve automatic update, mainly to determine that the certificate in pauth.ini is within a week, and the implementation will automatically update the authorization. If the script is placed in the planned task and defined to update at 8pm, the authorization can be updated automatically (provided that flush has been re-authorized).

The specific script is as follows:

# flush updates the certificate of the entrusted master station. Note that key has special characters such as +-to escape, and authcodes-authcode1 without escape.

$AuthCodes='E22-LHjT-4Itu-A7sg-Hnyi-H0U+'

$AuthCodes1='E22-LHjT-4Itu-A7sg-Hnyi-H0U%2B'

$AuthPath='d:\ thssj\ wtserver\'

$NetFile=' http://services.myhexin.com/produser/downloadcert?libver=20030506&authcode='+$AuthCodes1+'&Submit=%CF%C2%D4%D8%D6%A4%CA%E9'

$SaveFile=$AuthPath+$AuthCodes.Substring (0dat 3) + '.dat'

# load winapi

$ini = Add-Type-memberDefinition @ "

[DllImport ("Kernel32")]

Public static extern int GetPrivateProfileString (

String section

String key

String def

StringBuilder retVal

Int size

String filePath)

"@-passthru-name MyPrivateProfileString-UsingNamespace System.Text

# define configuration

$section=$AuthCodes

$filePath=$AuthPath+ "pauth.ini"

$key= "Certificate due date"

$retVal=New-Object System.Text.StringBuilder (200)

# View the key value of configuration file

$null=$ini::GetPrivateProfileString ($section,$key, "", $retVal,200,$filePath)

$dateStr = $retVal.tostring ()

# format string to date

$dateVal = get-date $dateStr

# find the date seven days in advance

$dateLast = $dateVal.AddDays (- 7)

# get the current date

$dateNow = get-date

# key value compared with the current date, lt is less than, ge is greater than

If ($dateLast-le $dateNow) {

# start downloading license file

$client = new-object System.Net.WebClient

$client.DownloadFile ($NetFile,$SaveFile)

# restart the delegated master station

Taskkill / im hxwt.exe / f

Start-Sleep-s 3

Cd $AuthPath

Start hxwt.exe

}

#

# flush updates the delegated gateway certificate. Note that key has special characters such as +-to escape, and authcodes-authcode1 without escape.

$AuthCodes='E19-LHjT-4Itu-A7sg-Hnyi-H0U+'

$AuthCodes1='E19-LHjT-4Itu-A7sg-Hnyi-H0U%2B'

$AuthPath='d:\ thssj\ WTGateWay\'

$NetFile=' http://services.myhexin.com/produser/downloadcert?libver=20030506&authcode='+$AuthCodes1+'&Submit=%CF%C2%D4%D8%D6%A4%CA%E9'

$SaveFile=$AuthPath+$AuthCodes.Substring (0dat 3) + '.dat'

# load winapi

$ini = Add-Type-memberDefinition @ "

[DllImport ("Kernel32")]

Public static extern int GetPrivateProfileString (

String section

String key

String def

StringBuilder retVal

Int size

String filePath)

"@-passthru-name MyPrivateProfileString-UsingNamespace System.Text

# define configuration

$section=$AuthCodes

$filePath=$AuthPath+ "pauth.ini"

$key= "Certificate due date"

$retVal=New-Object System.Text.StringBuilder (200)

# View the key value of configuration file

$null=$ini::GetPrivateProfileString ($section,$key, "", $retVal,200,$filePath)

$dateStr = $retVal.tostring ()

# format string to date

$dateVal = get-date $dateStr

# find the date seven days in advance

$dateLast = $dateVal.AddDays (- 7)

# get the current date

$dateNow = get-date

# key value compared with the current date, lt is less than, ge is greater than

If ($dateLast-le $dateNow) {

# start downloading license file

$client = new-object System.Net.WebClient

$client.DownloadFile ($NetFile,$SaveFile)

# restart the delegate gateway

Taskkill / im WTMonitor.exe / f

Start-Sleep-s 3

Cd $AuthPath

Start WTMonitor.exe

}

Tags: Date update certificate flush character file escape delegate configuration script special string case time format gateway deadline task premise manual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia Microsoft Linux Shulou Technology