1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 13:16:09 +03:00

fix config.json issue

This commit is contained in:
nuxt-autumn 2021-03-08 23:15:18 +08:00
parent 77cf7737f7
commit 177c09896c
6 changed files with 23 additions and 19 deletions

View File

@ -233,9 +233,6 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<None Include="Data\Record.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
@ -362,6 +359,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Data\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets" Condition="Exists('..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets')" /> <Import Project="..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets" Condition="Exists('..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@ -1,3 +1,3 @@
{ {
"api": null "api": {}
} }

View File

@ -1,3 +1,3 @@
{ {
"stats": null "stats": {}
} }

View File

@ -48,7 +48,7 @@ namespace ProxySU_Core.ViewModels.Developers
return new return new
{ {
log = logObj["log"], log = logObj["log"],
api = apiObj["api"], //api = apiObj["api"], api不能为空
dns = dnsObj["dns"], dns = dnsObj["dns"],
routing = routingObj["routing"], routing = routingObj["routing"],
policy = policyObj["policy"], policy = policyObj["policy"],
@ -63,14 +63,14 @@ namespace ProxySU_Core.ViewModels.Developers
public static string BuildCaddyConfig(XraySettings parameters) public static string BuildCaddyConfig(XraySettings parameters)
{ {
var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile"));
caddyStr.Replace("##domain##", parameters.Domain); caddyStr = caddyStr.Replace("##domain##", parameters.Domain);
if (!string.IsNullOrEmpty(parameters.MaskDomain)) if (!string.IsNullOrEmpty(parameters.MaskDomain))
{ {
caddyStr.Replace("##server_proxy##", $"reverse_proxy http://{parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}"); caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy http://{parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}");
} }
else else
{ {
caddyStr.Replace("##server_proxy##", ""); caddyStr = caddyStr.Replace("##reverse_proxy##", "");
} }
return caddyStr; return caddyStr;

View File

@ -106,6 +106,7 @@ namespace ProxySU_Core.ViewModels.Developers
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("rm -rf /usr/local/etc/xray/config.json"); RunCmd("rm -rf /usr/local/etc/xray/config.json");
UploadFile(stream, "/usr/local/etc/xray/config.json"); UploadFile(stream, "/usr/local/etc/xray/config.json");
RunCmd("systemctl restart xray");
} }
private void InstallCertToXray() private void InstallCertToXray()
@ -114,7 +115,7 @@ namespace ProxySU_Core.ViewModels.Developers
RunCmd(GetInstallCmd("socat")); RunCmd(GetInstallCmd("socat"));
// 解决搬瓦工CentOS缺少问题 // 解决搬瓦工CentOS缺少问题
RunCmd(GetInstallCmd("automake autoconf libtool")); RunCmd("y | " + GetInstallCmd("automake autoconf libtool"));
// 安装Acme // 安装Acme
var result = RunCmd($"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m {GetRandomEmail()}"); var result = RunCmd($"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m {GetRandomEmail()}");
@ -153,7 +154,7 @@ namespace ProxySU_Core.ViewModels.Developers
// 安装证书到xray // 安装证书到xray
RunCmd("mkdir -p /usr/local/etc/xray/ssl"); RunCmd("mkdir -p /usr/local/etc/xray/ssl");
RunCmd($"/root/.acme.sh/acme.sh --installcert -d {Parameters.Domain} --certpath /usr/local/etc/xray/ssl/xray_ssl.crt --keypath /usr/local/etc/xray/ssl/xray_ssl.key --capath /usr/local/etc/xray/ssl/xray_ssl.crt --reloadcmd \"systemctl restart xray\""); RunCmd($"/root/.acme.sh/acme.sh --installcert -d {Parameters.Domain} --certpath /usr/local/etc/xray/ssl/xray_ssl.crt --keypath /usr/local/etc/xray/ssl/xray_ssl.key --capath /usr/local/etc/xray/ssl/xray_ssl.crt");
result = RunCmd(@"if [ ! -f ""/usr/local/etc/xray/ssl/xray_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"); result = RunCmd(@"if [ ! -f ""/usr/local/etc/xray/ssl/xray_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1");
if (result.Contains("1")) if (result.Contains("1"))
{ {
@ -164,8 +165,7 @@ namespace ProxySU_Core.ViewModels.Developers
throw new Exception("安装证书失败,请联系开发者!"); throw new Exception("安装证书失败,请联系开发者!");
} }
RunCmd(@"chmod 755 /usr/local/etc/xray/ssl");
RunCmd(@"chmod 644 /usr/local/etc/xray/ssl/xray_ssl.key");
} }
private string GetRandomEmail() private string GetRandomEmail()

View File

@ -46,11 +46,14 @@ namespace ProxySU_Core
if (File.Exists(RecordPath)) if (File.Exists(RecordPath))
{ {
var recordsJson = File.ReadAllText(RecordPath, Encoding.UTF8); var recordsJson = File.ReadAllText(RecordPath, Encoding.UTF8);
var records = JsonConvert.DeserializeObject<List<Record>>(recordsJson); if (!string.IsNullOrEmpty(recordsJson))
records.ForEach(item =>
{ {
Records.Add(new RecordViewModel(item)); var records = JsonConvert.DeserializeObject<List<Record>>(recordsJson);
}); records.ForEach(item =>
{
Records.Add(new RecordViewModel(item));
});
}
} }
@ -66,10 +69,11 @@ namespace ProxySU_Core
{ {
ContractResolver = new CamelCasePropertyNamesContractResolver() ContractResolver = new CamelCasePropertyNamesContractResolver()
}); });
if (File.Exists("Data\\Record.json")) if (!Directory.Exists("Data"))
{ {
File.WriteAllText("Data\\Record.json", json, Encoding.UTF8); Directory.CreateDirectory("Data");
} }
File.WriteAllText("Data\\Record.json", json, Encoding.UTF8);
} }
private void LaunchGitHubSite(object sender, RoutedEventArgs e) private void LaunchGitHubSite(object sender, RoutedEventArgs e)