Added crypto key into scheduler service config

This commit is contained in:
vfedosevich 2013-05-17 11:42:49 +03:00
parent 38c8ac1199
commit 9a10d75492
3 changed files with 31 additions and 4 deletions

View file

@ -33,7 +33,8 @@ namespace WebsitePanel.SchedulerServiceInstaller
[CustomAction]
public static ActionResult FinalizeInstall(Session session)
{
ChangeConnectionString(session["CONNECTIONSTRING"], session["INSTALLFOLDER"]);
ChangeConfigString("installer.connectionstring", session["CONNECTIONSTRING"], session["INSTALLFOLDER"]);
ChangeCryptoKey(session["INSTALLFOLDER"]);
InstallService(session["INSTALLFOLDER"]);
return ActionResult.Success;
@ -55,7 +56,26 @@ namespace WebsitePanel.SchedulerServiceInstaller
}
}
private static void ChangeConnectionString(string connectionString, string installFolder)
private static void ChangeCryptoKey(string installFolder)
{
string path = Path.Combine(installFolder.Replace("SchedulerService", "Enterprise Server"), "web.config");
string cryptoKey = "0123456789";
if (File.Exists(path))
{
using (var reader = new StreamReader(path))
{
string content = reader.ReadToEnd();
var pattern = new Regex(@"(?<=<add key=""WebsitePanel.CryptoKey"" .*?value\s*=\s*"")[^""]+(?="".*?>)");
Match match = pattern.Match(content);
cryptoKey = match.Value;
}
}
ChangeConfigString("installer.cryptokey", cryptoKey, installFolder);
}
private static void ChangeConfigString(string searchString, string replaceValue, string installFolder)
{
string content;
string path = Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe.config");
@ -65,8 +85,8 @@ namespace WebsitePanel.SchedulerServiceInstaller
content = reader.ReadToEnd();
}
var re = new Regex("\\$\\{" + "installer.connectionstring" + "\\}+", RegexOptions.IgnoreCase);
content = re.Replace(content, connectionString);
var re = new Regex("\\$\\{" + searchString + "\\}+", RegexOptions.IgnoreCase);
content = re.Replace(content, replaceValue);
using (var writer = new StreamWriter(path))
{

View file

@ -6,4 +6,10 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<appSettings>
<!-- Encryption util settings -->
<add key="WebsitePanel.CryptoKey" value="0123456789"/>
<!-- A1D4KDHUE83NKHddF -->
<add key="WebsitePanel.EncryptionEnabled" value="true" />
</appSettings>
</configuration>

View file

@ -327,6 +327,7 @@
</MSBuild>
<XmlUpdate XmlFileName="$(RootFolder)\WebsitePanel\Sources\WebsitePanel.SchedulerService\Bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/connectionStrings/add/@connectionString" Value="${installer.connectionstring}" />
<XmlUpdate XmlFileName="$(RootFolder)\WebsitePanel\Sources\WebsitePanel.SchedulerService\Bin\WebsitePanel.SchedulerService.exe.config" Xpath="//configuration/appSettings/add[@key=%22WebsitePanel.CryptoKey%22]/@value" Value="${installer.cryptokey}" />
<MSBuild Projects="$(RootFolder)\WebsitePanel.Installer\Sources\Setup.SchedulerService\Setup.SchedulerService.wixproj" Properties="Configuration=$(BuildConfiguration);DefineSolutionProperties=false">
<Output