From d906a767944f02209c010d539163a9c10af7bee2 Mon Sep 17 00:00:00 2001 From: vaalacat Date: Mon, 18 Mar 2024 17:21:38 +0000 Subject: [PATCH] feat: windows service install script --- install.ps1 | 65 ++++++++++++++++++++++++++++++++++ www/components/client_item.tsx | 10 +++--- www/components/server_item.tsx | 8 ++--- www/lib/consts.ts | 12 ++++--- 4 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 install.ps1 diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..c1015b7 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,65 @@ +# Download latest release from github +if($PSVersionTable.PSVersion.Major -lt 5){ + Write-Host "Require PS >= 5,your PSVersion:"$PSVersionTable.PSVersion.Major -BackgroundColor DarkGreen -ForegroundColor White + exit +} +$clientrepo = "VaalaCat/frp-panel" +$nssmrepo = "nezhahq/nssm-backup" +# x86 or x64 +if ([System.Environment]::Is64BitOperatingSystem) { + $file = "frp-panel-amd64.exe" +} +else { + Write-Host "Your system is 32-bit, please use 64-bit operating system" -BackgroundColor DarkGreen -ForegroundColor White + exit +} +$clientreleases = "https://api.github.com/repos/$clientrepo/releases" +$nssmreleases = "https://api.github.com/repos/$nssmrepo/releases" +#重复运行自动更新 +if (Test-Path "C:\frpp") { + Write-Host "frp panel client already exists, delete and reinstall" -BackgroundColor DarkGreen -ForegroundColor White + C:/frpp/nssm.exe stop frpp + C:/frpp/nssm.exe remove frpp + Remove-Item "C:\frpp" -Recurse +} + +#TLS/SSL +Write-Host "Determining latest frp panel client release" -BackgroundColor DarkGreen -ForegroundColor White +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$agenttag = (Invoke-WebRequest -Uri $clientreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name +$nssmtag = (Invoke-WebRequest -Uri $nssmreleases -UseBasicParsing | ConvertFrom-Json)[0].tag_name +#Region判断 +$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1" +$region=$ipapi.cc +echo $ipapi +if($region -ne "CN"){ +$download = "https://github.com/$clientrepo/releases/download/$agenttag/$file" +$nssmdownload="https://github.com/$nssmrepo/releases/download/$nssmtag/nssm.zip" +Write-Host "Location:$region,connect directly!" -BackgroundColor DarkRed -ForegroundColor Green +}else{ +$download = "https://dn-dao-github-mirror.daocloud.io/$clientrepo/releases/download/$agenttag/$file" +$nssmdownload="https://dn-dao-github-mirror.daocloud.io/$nssmrepo/releases/download/$nssmtag/nssm.zip" +Write-Host "Location:CN,use mirror address" -BackgroundColor DarkRed -ForegroundColor Green +} +echo $download +echo $nssmdownload +Invoke-WebRequest $nssmdownload -OutFile "C:\nssm.zip" +Invoke-WebRequest $download -OutFile "C:\frpp.exe" +#使用nssm安装服务 + +#解压 +Expand-Archive "C:\nssm.zip" -DestinationPath "C:\temp" -Force +if (!(Test-Path "C:\frpp")) { New-Item -Path "C:\frpp" -type directory } + +#整理文件 +Move-Item -Path "C:\frpp.exe" -Destination "C:\frpp\frpp.exe" +Move-Item -Path "C:\temp\nssm-2.24\win64\nssm.exe" -Destination "C:\frpp\nssm.exe" + +#清理垃圾 +Remove-Item "C:\nssm.zip" +Remove-Item "C:\temp" -Recurse +#安装部分 +C:\frpp\nssm.exe install frpp C:\frpp\frpp.exe $args +C:\frpp\nssm.exe start frpp +#enjoy +Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red \ No newline at end of file diff --git a/www/components/client_item.tsx b/www/components/client_item.tsx index ec1450a..fa3808f 100644 --- a/www/components/client_item.tsx +++ b/www/components/client_item.tsx @@ -100,15 +100,15 @@ export const ClientID = ({ client }: { client: ClientTableSchema }) => {
{client.id}
- +
Linux安装到systemd
{platformInfo === undefined ? '获取平台信息失败' : LinuxInstallCommand('client', client, platformInfo)}
- {/*
Windows
-
- {platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("client", client, platformInfo)} -
*/} +
Windows安装到系统服务
+
+ {platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("client", client, platformInfo)} +
) diff --git a/www/components/server_item.tsx b/www/components/server_item.tsx index aada089..b034edd 100644 --- a/www/components/server_item.tsx +++ b/www/components/server_item.tsx @@ -113,10 +113,10 @@ export const ServerID = ({ server }: { server: ServerTableSchema }) => {
{platformInfo === undefined ? '获取平台信息失败' : LinuxInstallCommand('server', server, platformInfo)}
- {/*
Windows
-
- {platformInfo === undefined ? "获取平台信息失败" : WindowsInstallCommand("server", server, platformInfo)} -
*/} +
Windows安装到系统服务
+
+ {platformInfo === undefined ? '获取平台信息失败' : WindowsInstallCommand('server', server, platformInfo)} +
) diff --git a/www/lib/consts.ts b/www/lib/consts.ts index 6c98123..cdaa133 100644 --- a/www/lib/consts.ts +++ b/www/lib/consts.ts @@ -32,11 +32,13 @@ export const WindowsInstallCommand = ( item: T, info: GetPlatformInfoResponse, ) => { - return `Invoke-WebRequest -Uri 'https://github.com/your_repository/frp-panel/releases/latest/download/frp-panel-amd64.exe' -OutFile 'frp-panel.exe' - Move-Item .\\frp-panel.exe C:\\Tools\\frp-panel.exe - $command = "C:\\Tools\\${ExecCommandStr(type, item, info, 'frp-panel.exe')}" - Set-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Services\\FRPPanel' -Name 'ImagePath' -Value "\`"$command\`"" - New-Service -Name 'FRPPanel' -BinaryPathName 'C:\\Tools\\frp-panel.exe' -StartupType Automatic | Start-Service` + return `[Net.ServicePointManager]::SecurityProtocol = `+ + `[Net.SecurityProtocolType]::Ssl3 -bor `+ + `[Net.SecurityProtocolType]::Tls -bor ` + + `[Net.SecurityProtocolType]::Tls11 -bor ` + + `[Net.SecurityProtocolType]::Tls12;set-ExecutionPolicy RemoteSigned;`+ + `Invoke-WebRequest https://raw.githubusercontent.com/VaalaCat/frp-panel/main/install.ps1 `+ + `-OutFile C:\install.ps1;powershell.exe C:\install.ps1 ${ExecCommandStr(type, item, info, ' ')}` } export const LinuxInstallCommand = (