mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
moved update check url to app level allowing each app to have correct update check download link.
This commit is contained in:
@@ -31,7 +31,7 @@ namespace DnsServerApp
|
|||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
configFolder = args[0];
|
configFolder = args[0];
|
||||||
|
|
||||||
DnsWebService service = new DnsWebService(configFolder);
|
DnsWebService service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updateca.bin"));
|
||||||
|
|
||||||
service.Start();
|
service.Start();
|
||||||
Console.WriteLine("Technitium DNS Server was started successfully.");
|
Console.WriteLine("Technitium DNS Server was started successfully.");
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace DnsServerApp
|
|||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
configFolder = args[0];
|
configFolder = args[0];
|
||||||
|
|
||||||
DnsWebService service = new DnsWebService(configFolder);
|
DnsWebService service = new DnsWebService(configFolder, new Uri("https://technitium.com/download/dns/updatewa.bin"));
|
||||||
|
|
||||||
service.Start();
|
service.Start();
|
||||||
Console.WriteLine("Technitium DNS Server was started successfully.");
|
Console.WriteLine("Technitium DNS Server was started successfully.");
|
||||||
|
|||||||
@@ -48,14 +48,10 @@ namespace DnsServerCore
|
|||||||
|
|
||||||
#region variables
|
#region variables
|
||||||
|
|
||||||
readonly static Uri UPDATE_URI_WINDOWS_SERVICE = new Uri("https://technitium.com/download/dns/updatews.bin");
|
|
||||||
readonly static Uri UPDATE_URI_WINDOWS_APP = new Uri("https://technitium.com/download/dns/updatewa.bin");
|
|
||||||
readonly static Uri UPDATE_URI_MONO_APP = new Uri("https://technitium.com/download/dns/updatema.bin");
|
|
||||||
|
|
||||||
bool _isWindowsService;
|
|
||||||
readonly string _currentVersion;
|
readonly string _currentVersion;
|
||||||
readonly string _appFolder;
|
readonly string _appFolder;
|
||||||
readonly string _configFolder;
|
readonly string _configFolder;
|
||||||
|
readonly Uri _updateCheckUri;
|
||||||
|
|
||||||
readonly LogManager _log;
|
readonly LogManager _log;
|
||||||
|
|
||||||
@@ -76,12 +72,11 @@ namespace DnsServerCore
|
|||||||
|
|
||||||
#region constructor
|
#region constructor
|
||||||
|
|
||||||
public DnsWebService(string configFolder = null)
|
public DnsWebService(string configFolder = null, Uri updateCheckUri = null)
|
||||||
{
|
{
|
||||||
Assembly assembly = Assembly.GetEntryAssembly();
|
Assembly assembly = Assembly.GetEntryAssembly();
|
||||||
AssemblyName assemblyName = assembly.GetName();
|
AssemblyName assemblyName = assembly.GetName();
|
||||||
|
|
||||||
_isWindowsService = (assemblyName.Name == "DnsService");
|
|
||||||
_currentVersion = assemblyName.Version.ToString();
|
_currentVersion = assemblyName.Version.ToString();
|
||||||
_appFolder = Path.GetDirectoryName(assembly.Location);
|
_appFolder = Path.GetDirectoryName(assembly.Location);
|
||||||
|
|
||||||
@@ -90,6 +85,8 @@ namespace DnsServerCore
|
|||||||
else
|
else
|
||||||
_configFolder = configFolder;
|
_configFolder = configFolder;
|
||||||
|
|
||||||
|
_updateCheckUri = updateCheckUri;
|
||||||
|
|
||||||
if (!Directory.Exists(_configFolder))
|
if (!Directory.Exists(_configFolder))
|
||||||
Directory.CreateDirectory(_configFolder);
|
Directory.CreateDirectory(_configFolder);
|
||||||
|
|
||||||
@@ -553,71 +550,60 @@ namespace DnsServerCore
|
|||||||
|
|
||||||
bool updateAvailable = false;
|
bool updateAvailable = false;
|
||||||
|
|
||||||
try
|
if (_updateCheckUri != null)
|
||||||
{
|
{
|
||||||
using (WebClient wc = new WebClient())
|
try
|
||||||
{
|
{
|
||||||
Uri updateUri;
|
using (WebClient wc = new WebClient())
|
||||||
|
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
||||||
{
|
{
|
||||||
if (_isWindowsService)
|
byte[] response = wc.DownloadData(_updateCheckUri);
|
||||||
updateUri = UPDATE_URI_WINDOWS_SERVICE;
|
|
||||||
else
|
|
||||||
updateUri = UPDATE_URI_WINDOWS_APP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
updateUri = UPDATE_URI_MONO_APP;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] response = wc.DownloadData(updateUri);
|
using (MemoryStream mS = new MemoryStream(response, false))
|
||||||
|
|
||||||
using (MemoryStream mS = new MemoryStream(response, false))
|
|
||||||
{
|
|
||||||
BincodingDecoder decoder = new BincodingDecoder(mS, "DU");
|
|
||||||
|
|
||||||
switch (decoder.Version)
|
|
||||||
{
|
{
|
||||||
case 1:
|
BincodingDecoder decoder = new BincodingDecoder(mS, "DU");
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Bincoding entry = decoder.DecodeNext();
|
|
||||||
if (entry == null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
KeyValuePair<string, Bincoding> value = entry.GetKeyValuePair();
|
switch (decoder.Version)
|
||||||
|
{
|
||||||
switch (value.Key)
|
case 1:
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
case "version":
|
Bincoding entry = decoder.DecodeNext();
|
||||||
updateVersion = value.Value.GetStringValue();
|
if (entry == null)
|
||||||
|
|
||||||
updateAvailable = IsUpdateAvailable(_currentVersion, updateVersion);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "displayText":
|
KeyValuePair<string, Bincoding> value = entry.GetKeyValuePair();
|
||||||
displayText = value.Value.GetStringValue();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "downloadLink":
|
switch (value.Key)
|
||||||
downloadLink = value.Value.GetStringValue();
|
{
|
||||||
break;
|
case "version":
|
||||||
|
updateVersion = value.Value.GetStringValue();
|
||||||
|
|
||||||
|
updateAvailable = IsUpdateAvailable(_currentVersion, updateVersion);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "displayText":
|
||||||
|
displayText = value.Value.GetStringValue();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "downloadLink":
|
||||||
|
downloadLink = value.Value.GetStringValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IOException("File version not supported: " + decoder.Version);
|
throw new IOException("File version not supported: " + decoder.Version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_log.Write(GetRequestRemoteEndPoint(request), "Check for update was done {updateAvailable: " + updateAvailable + "; updateVersion: " + updateVersion + "; displayText: " + displayText + "; downloadLink: " + downloadLink + ";}");
|
_log.Write(GetRequestRemoteEndPoint(request), "Check for update was done {updateAvailable: " + updateAvailable + "; updateVersion: " + updateVersion + "; displayText: " + displayText + "; downloadLink: " + downloadLink + ";}");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
_log.Write(GetRequestRemoteEndPoint(request), "Check for update was done {updateAvailable: False;}");
|
_log.Write(GetRequestRemoteEndPoint(request), "Check for update was done {updateAvailable: False;}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonWriter.WritePropertyName("updateAvailable");
|
jsonWriter.WritePropertyName("updateAvailable");
|
||||||
@@ -668,7 +654,7 @@ namespace DnsServerCore
|
|||||||
private void GetDnsSettings(JsonTextWriter jsonWriter)
|
private void GetDnsSettings(JsonTextWriter jsonWriter)
|
||||||
{
|
{
|
||||||
jsonWriter.WritePropertyName("version");
|
jsonWriter.WritePropertyName("version");
|
||||||
jsonWriter.WriteValue(_currentVersion.Replace(".0", ""));
|
jsonWriter.WriteValue(_currentVersion);
|
||||||
|
|
||||||
jsonWriter.WritePropertyName("serverDomain");
|
jsonWriter.WritePropertyName("serverDomain");
|
||||||
jsonWriter.WriteValue(_serverDomain);
|
jsonWriter.WriteValue(_serverDomain);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using DnsServerCore;
|
using DnsServerCore;
|
||||||
|
using System;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
|
|
||||||
namespace DnsService
|
namespace DnsService
|
||||||
@@ -33,7 +34,7 @@ namespace DnsService
|
|||||||
|
|
||||||
protected override void OnStart(string[] args)
|
protected override void OnStart(string[] args)
|
||||||
{
|
{
|
||||||
_service = new DnsWebService();
|
_service = new DnsWebService(null, new Uri("https://technitium.com/download/dns/updatews.bin"));
|
||||||
_service.Start();
|
_service.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user