1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-21 20:56:08 +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>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Data\Record.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -362,6 +359,9 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Folder Include="Data\" />
</ItemGroup>
<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')" />
<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
{
log = logObj["log"],
api = apiObj["api"],
//api = apiObj["api"], api不能为空
dns = dnsObj["dns"],
routing = routingObj["routing"],
policy = policyObj["policy"],
@ -63,14 +63,14 @@ namespace ProxySU_Core.ViewModels.Developers
public static string BuildCaddyConfig(XraySettings parameters)
{
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))
{
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
{
caddyStr.Replace("##server_proxy##", "");
caddyStr = caddyStr.Replace("##reverse_proxy##", "");
}
return caddyStr;

View File

@ -106,6 +106,7 @@ namespace ProxySU_Core.ViewModels.Developers
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("rm -rf /usr/local/etc/xray/config.json");
UploadFile(stream, "/usr/local/etc/xray/config.json");
RunCmd("systemctl restart xray");
}
private void InstallCertToXray()
@ -114,7 +115,7 @@ namespace ProxySU_Core.ViewModels.Developers
RunCmd(GetInstallCmd("socat"));
// 解决搬瓦工CentOS缺少问题
RunCmd(GetInstallCmd("automake autoconf libtool"));
RunCmd("y | " + GetInstallCmd("automake autoconf libtool"));
// 安装Acme
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
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");
if (result.Contains("1"))
{
@ -164,8 +165,7 @@ namespace ProxySU_Core.ViewModels.Developers
throw new Exception("安装证书失败,请联系开发者!");
}
RunCmd(@"chmod 644 /usr/local/etc/xray/ssl/xray_ssl.key");
RunCmd(@"chmod 755 /usr/local/etc/xray/ssl");
}
private string GetRandomEmail()

View File

@ -46,11 +46,14 @@ namespace ProxySU_Core
if (File.Exists(RecordPath))
{
var recordsJson = File.ReadAllText(RecordPath, Encoding.UTF8);
var records = JsonConvert.DeserializeObject<List<Record>>(recordsJson);
records.ForEach(item =>
if (!string.IsNullOrEmpty(recordsJson))
{
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()
});
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)