添加SHA256检测,去除对XP的支持
This commit is contained in:
parent
14faab4894
commit
8a392690fa
@ -16,6 +16,6 @@ curl -O https://y-bi.top/setup.sh && sudo chmod +x setup.sh && sudo ./setup.sh
|
|||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
Download setup file: [https://y-bi.top/setup.exe](https://y-bi.top/setup.exe)
|
Windows 7+ download setup file: [https://y-bi.top/setup.exe](https://y-bi.top/setup.exe)
|
||||||
|
|
||||||
注意:默认版本兼容.NET2.0+,如果您的操作系统较新(例如 Windows Server 2019,默认没有安装.NET Framework 3.5),可以尝试安装此版本(基于.NET Framework 4构建):[https://y-bi.top/setup.net4.exe](https://y-bi.top/setup.net4.exe)
|
Minimum system support for Windows 7 or Windows Server 2008 R2, Require .NET Framework 4.0 and Transport Layer Security (TLS) 1.2, windows 7 and Windows Server 2008 R2 enable Transport Layer Security (TLS) 1.2 [https://github.com/TheLevelUp/pos-tls-patcher](https://github.com/TheLevelUp/pos-tls-patcher).
|
||||||
|
28
setup.sh
28
setup.sh
@ -66,7 +66,7 @@ download() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
getLatestVersion() {
|
Install() {
|
||||||
local platformValue=`platform`
|
local platformValue=`platform`
|
||||||
local archValue=`arch`
|
local archValue=`arch`
|
||||||
|
|
||||||
@ -83,25 +83,33 @@ getLatestVersion() {
|
|||||||
|
|
||||||
if [[ "${status}" == "1" ]]; then
|
if [[ "${status}" == "1" ]]; then
|
||||||
local downloadURL=$(echo "${res}" | grepCross '"downloadURL":".*?[^\\]",' | sed 's/"downloadURL":"//g' | sed 's/",//g')
|
local downloadURL=$(echo "${res}" | grepCross '"downloadURL":".*?[^\\]",' | sed 's/"downloadURL":"//g' | sed 's/",//g')
|
||||||
echo ${downloadURL}
|
local fileSha256=$(echo "${res}" | grepCross '"sha256":".*?[^\\]",' | sed 's/"sha256":"//g' | sed 's/",//g')
|
||||||
else
|
|
||||||
echo "no"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
Install() {
|
|
||||||
downloadURL=`getLatestVersion`
|
|
||||||
|
|
||||||
if [[ "${downloadURL}" != "no" ]]; then
|
|
||||||
mkdir -p /usr/local/dc-agent/bin
|
mkdir -p /usr/local/dc-agent/bin
|
||||||
mkdir -p /usr/local/dc-agent/log
|
mkdir -p /usr/local/dc-agent/log
|
||||||
|
|
||||||
download "${downloadURL}" -o "/usr/local/dc-agent/bin/dc-agent"
|
download "${downloadURL}" -o "/usr/local/dc-agent/bin/dc-agent"
|
||||||
|
|
||||||
|
if cmdhas "sha256sum"; then
|
||||||
|
checkSha256=$(sha256sum /usr/local/dc-agent/bin/dc-agent | awk '{ print $1 }' | tr '[A-Z]' '[a-z]')
|
||||||
|
if [[ "${checkSha256}" != "${fileSha256}" ]]; then
|
||||||
|
echo -e "${checkSha256}\n"
|
||||||
|
echo -e "${fileSha256}\n"
|
||||||
|
echo -e "\nError: File sha256 check failed.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "\nError: sha256sum command not found.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
|
|
||||||
sudo chmod 755 /usr/local/dc-agent/bin/dc-agent
|
sudo chmod 755 /usr/local/dc-agent/bin/dc-agent
|
||||||
sudo /usr/local/dc-agent/bin/dc-agent install
|
sudo /usr/local/dc-agent/bin/dc-agent install
|
||||||
sudo /usr/local/dc-agent/bin/dc-agent start
|
sudo /usr/local/dc-agent/bin/dc-agent start
|
||||||
|
|
||||||
|
echo -e "\nInstall success!\n"
|
||||||
else
|
else
|
||||||
echo -e "\nServer connection failed, please check your network connection.\n"
|
echo -e "\nServer connection failed, please check your network connection.\n"
|
||||||
fi
|
fi
|
||||||
|
@ -3,9 +3,11 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
internal static class Win32API
|
internal static class Win32API
|
||||||
{
|
{
|
||||||
@ -18,6 +20,7 @@ namespace setup
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
static double systemVersion = Convert.ToDouble(Environment.OSVersion.Version.Major + "." + Environment.OSVersion.Version.Minor);
|
||||||
public static bool IsAdministrator()
|
public static bool IsAdministrator()
|
||||||
{
|
{
|
||||||
WindowsIdentity current = WindowsIdentity.GetCurrent();
|
WindowsIdentity current = WindowsIdentity.GetCurrent();
|
||||||
@ -48,7 +51,7 @@ namespace setup
|
|||||||
bool is64 = IsWin64(cur);
|
bool is64 = IsWin64(cur);
|
||||||
string result = "";
|
string result = "";
|
||||||
string arch = is64 ? "amd64" : "386";
|
string arch = is64 ? "amd64" : "386";
|
||||||
string url = "https://server-0.sercretcore.cn/api/download?arch=" + arch + "&platform=windows";
|
string url = "http://server-0.sercretcore.cn/api/download?arch=" + arch + "&platform=windows";
|
||||||
Stream stream;
|
Stream stream;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -166,6 +169,7 @@ namespace setup
|
|||||||
{
|
{
|
||||||
FileStream fstream = new FileStream(filePath, FileMode.Create, FileAccess.Write);
|
FileStream fstream = new FileStream(filePath, FileMode.Create, FileAccess.Write);
|
||||||
WebRequest wRequest = WebRequest.Create(url);
|
WebRequest wRequest = WebRequest.Create(url);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebResponse wResponse = wRequest.GetResponse();
|
WebResponse wResponse = wRequest.GetResponse();
|
||||||
@ -263,55 +267,27 @@ namespace setup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetChecksum(string file)
|
||||||
|
{
|
||||||
|
using (FileStream stream = File.OpenRead(file))
|
||||||
|
{
|
||||||
|
var sha = new SHA256Managed();
|
||||||
|
byte[] checksum = sha.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(checksum).Replace("-", string.Empty).ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
if (systemVersion < 6.1)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Minimum system support for Windows 7 or Windows Server 2008 R2.");
|
||||||
|
Console.ReadLine();
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (IsAdministrator())
|
if (IsAdministrator())
|
||||||
{
|
{
|
||||||
int systemVersion = Environment.OSVersion.Version.Major;
|
|
||||||
if (systemVersion < 6)
|
|
||||||
{
|
|
||||||
// ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
|
||||||
// ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
|
|
||||||
// print initial status
|
|
||||||
Console.WriteLine("Runtime: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(int).Assembly.Location).ProductVersion);
|
|
||||||
Console.WriteLine("Enabled protocols: " + ServicePointManager.SecurityProtocol);
|
|
||||||
Console.WriteLine("Available protocols: ");
|
|
||||||
Boolean platformSupportsTls12 = false;
|
|
||||||
foreach (SecurityProtocolType protocol in Enum.GetValues(typeof(SecurityProtocolType)))
|
|
||||||
{
|
|
||||||
Console.WriteLine(protocol.GetHashCode());
|
|
||||||
if (protocol.GetHashCode() == 3072)
|
|
||||||
{
|
|
||||||
platformSupportsTls12 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("Is Tls12 enabled: " + ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072));
|
|
||||||
|
|
||||||
|
|
||||||
// enable Tls12, if possible
|
|
||||||
if (!ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072))
|
|
||||||
{
|
|
||||||
if (platformSupportsTls12)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Platform supports Tls12, but it is not enabled. Enabling it now.");
|
|
||||||
ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Platform does not supports Tls12.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable ssl3
|
|
||||||
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Ssl3))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Ssl3SSL3 is enabled. Disabling it now.");
|
|
||||||
// disable SSL3. Has no negative impact if SSL3 is already disabled. The enclosing "if" if just for illustration.
|
|
||||||
System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
|
|
||||||
}
|
|
||||||
Console.WriteLine("Enabled protocols: " + ServicePointManager.SecurityProtocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.Write(@"
|
Console.Write(@"
|
||||||
DC-Agent
|
DC-Agent
|
||||||
|
|
||||||
@ -375,6 +351,7 @@ SOFTWARE.");
|
|||||||
|
|
||||||
string patternStatus = "\"status\":.";
|
string patternStatus = "\"status\":.";
|
||||||
string patternDownloadURL = "\"downloadURL\":\".*?[^\\\\]\",";
|
string patternDownloadURL = "\"downloadURL\":\".*?[^\\\\]\",";
|
||||||
|
string patternSha256 = "\"sha256\":\".*?[^\\\\]\",";
|
||||||
string status = Regex.Matches(res, patternStatus)[0].Value.Replace("\"status\":", "");
|
string status = Regex.Matches(res, patternStatus)[0].Value.Replace("\"status\":", "");
|
||||||
|
|
||||||
if (status != "1")
|
if (status != "1")
|
||||||
@ -386,13 +363,26 @@ SOFTWARE.");
|
|||||||
}
|
}
|
||||||
|
|
||||||
string downloadURL = Regex.Matches(res, patternDownloadURL)[0].Value.Replace("\"downloadURL\":\"", "").Replace("\",", "");
|
string downloadURL = Regex.Matches(res, patternDownloadURL)[0].Value.Replace("\"downloadURL\":\"", "").Replace("\",", "");
|
||||||
|
string fileSha256 = Regex.Matches(res, patternSha256)[0].Value.Replace("\"sha256\":\"", "").Replace("\",", "");
|
||||||
|
|
||||||
Mkdir("C:\\WINDOWS\\dc-agent");
|
Mkdir("C:\\WINDOWS\\dc-agent");
|
||||||
Mkdir("C:\\WINDOWS\\dc-agent\\log");
|
Mkdir("C:\\WINDOWS\\dc-agent\\log");
|
||||||
Mkdir("C:\\WINDOWS\\dc-agent\\bin");
|
Mkdir("C:\\WINDOWS\\dc-agent\\bin");
|
||||||
|
|
||||||
DownLoadOneFile(downloadURL, "C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe");
|
DownLoadOneFile(downloadURL, "C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe");
|
||||||
|
|
||||||
|
string checkSha256 = GetChecksum("C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe");
|
||||||
|
|
||||||
|
if (checkSha256 != fileSha256)
|
||||||
|
{
|
||||||
|
Console.WriteLine(checkSha256);
|
||||||
|
Console.WriteLine(fileSha256);
|
||||||
|
Console.WriteLine("Error: File sha256 check failed.");
|
||||||
|
Console.ReadLine();
|
||||||
|
Environment.Exit(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine(ExecuteOutCmd("C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe", "install"));
|
Console.WriteLine(ExecuteOutCmd("C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe", "install"));
|
||||||
Console.WriteLine(ExecuteOutCmd("C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe", "start"));
|
Console.WriteLine(ExecuteOutCmd("C:\\WINDOWS\\dc-agent\\bin\\dc-agent.exe", "start"));
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@ -48,6 +49,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetZone>LocalIntranet</TargetZone>
|
<TargetZone>LocalIntranet</TargetZone>
|
||||||
|
Loading…
Reference in New Issue
Block a user