Skip to content

Commit

Permalink
quick stab at configuring the url for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dovholuknf committed Oct 25, 2023
1 parent c3a958f commit b7aead4
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 45 deletions.
5 changes: 5 additions & 0 deletions DesktopEdge/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ async private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
monitorClient = new MonitorClient("ui");
monitorClient.OnClientConnected += MonitorClient_OnClientConnected;
monitorClient.OnNotificationEvent += MonitorClient_OnInstallationNotificationEvent;
monitorClient.OnUrlUpdateEvent += MonitorClient_OnUrlUpdateEvent;
monitorClient.OnServiceStatusEvent += MonitorClient_OnServiceStatusEvent;
monitorClient.OnShutdownEvent += MonitorClient_OnShutdownEvent;
monitorClient.OnCommunicationError += MonitorClient_OnCommunicationError;
Expand Down Expand Up @@ -651,6 +652,10 @@ async private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
Placement();
}

private void MonitorClient_OnUrlUpdateEvent(object sender, UrlUpdateEvent e) {
throw new NotImplementedException();
}

private void MonitorClient_OnCommunicationError(object sender, Exception e) {
string msg = "Communication Error with monitor?";
ShowError(msg, e.Message);
Expand Down
38 changes: 19 additions & 19 deletions DesktopEdge/Models/ViewState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@
using System.Threading.Tasks;
using System.Windows;

namespace Ziti.Desktop.Edge.Models
{
public class ZDEWViewState
{
namespace Ziti.Desktop.Edge.Models {
public class ZDEWViewState {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private bool automaticUpdatesDisabled = false;
public bool AutomaticUpdatesDisabled
{
get
{
private string updateUrl = "";
public bool AutomaticUpdatesDisabled {
get {
return automaticUpdatesDisabled;
}
set
{
set {
automaticUpdatesDisabled = value;
}
}
public string UpdateUrl {
get {
return updateUrl;
}
set {
updateUrl = value;
}
}

public UpdateInfo PendingUpdate { get; set; } = new UpdateInfo();

internal void AutomaticUpdatesEnabledFromString(string automaticUpgradeDisabled)
{
internal void AutomaticUpdatesEnabledFromString(string automaticUpgradeDisabled) {
bool disabled = bool.TrueString.ToLower() == automaticUpgradeDisabled?.ToLower().Trim();
this.AutomaticUpdatesDisabled = disabled;
}
}
public class UpdateInfo
{
public class UpdateInfo {
public DateTime InstallTime { get; set; } = DateTime.MinValue;
public string Version { get; set; } = "0.0.0.0";

public double TimeLeft
{
get
{
public double TimeLeft {
get {
double timeLeft = (InstallTime - DateTime.Now).TotalSeconds;
return timeLeft;
}
}
}
}
}
13 changes: 13 additions & 0 deletions DesktopEdge/Views/Screens/MainMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,22 @@
</StackPanel>
</StackPanel>
<StackPanel Name="AutomaticUpgradesItems" Visibility="Collapsed" Orientation="Vertical" HorizontalAlignment="Stretch">
<Label>Automatic upgrades are:</Label>
<local:SubOptionItem x:Name="AutomaticUpgradesItemOn" HorizontalAlignment="Stretch" Width="Auto" Label="Enabled" MouseUp="SetAutomaticUpgradesMenuAction"></local:SubOptionItem>
<local:SubOptionItem x:Name="AutomaticUpgradesItemOff" HorizontalAlignment="Stretch" Width="Auto" Label="Disabled" MouseUp="SetAutomaticUpgradesMenuAction"></local:SubOptionItem>

<Rectangle Height="20" />
<Rectangle Height="2" Fill="Black" />
<Rectangle Height="20" />
<Label>URL used to discover new upgrades</Label>
<Label>Do not change unless you understand</Label>
<TextBox x:Name="UpdateUrl" Padding="10" Margin="10,10,10,10" Height="40" BorderThickness="1" TextAlignment="Left" FontSize="14" Foreground="Black" FontFamily="pack://application:,,,/Assets/Fonts/#Open Sans"></TextBox>
<Button x:Name="SetUpdateUrlButton" Content="Set Update URL" MouseUp="SetUpdateURL" FocusableChanged="SetUpdateUrlButton_FocusableChanged"/>
</StackPanel>

<StackPanel Name="AutomaticUpgradeUrl" Visibility="Visible" Orientation="Vertical" HorizontalAlignment="Stretch">
</StackPanel>

<StackPanel Name="ConfigItems" Visibility="Collapsed" Orientation="Vertical" HorizontalAlignment="Stretch">
<local:MenuEditItem x:Name="ConfigIp" HorizontalAlignment="Stretch" Width="Auto" Label="IPv4 Address:"></local:MenuEditItem>
<local:MenuEditItem x:Name="ConfigSubnet" HorizontalAlignment="Stretch" Width="Auto" Label="Subnet Mask:"></local:MenuEditItem>
Expand Down
4 changes: 4 additions & 0 deletions DesktopEdge/Views/Screens/MainMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,5 +746,9 @@ private void CheckRange() {
if (value < 10 || value > 500) value = defaultVal;
ConfigePageSizeNew.Text = value.ToString();
}

private void SetUpdateUrlButton_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e) {
Console.WriteLine("here we go");
}
}
}
7 changes: 5 additions & 2 deletions ZitiDesktopEdge.Client/DataStructures/DataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,15 @@ public class StatusCheck : MonitorServiceStatusEvent {
public bool UpdateAvailable { get; set; }
}

public class InstallationNotificationEvent : MonitorServiceStatusEvent
{
public class InstallationNotificationEvent : MonitorServiceStatusEvent {
public string ZDEVersion { get; set; }
public DateTime InstallTime { get; set; }
}

public class UrlUpdateEvent : MonitorServiceStatusEvent {
public string URL { get; set; }
}

public class MfaEvent : ActionEvent {
public string Identifier { get; set; }
public bool Successful { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions ZitiDesktopEdge.Client/ServiceClient/MonitorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MonitorClient : AbstractClient {

public event EventHandler<MonitorServiceStatusEvent> OnServiceStatusEvent;
public event EventHandler<InstallationNotificationEvent> OnNotificationEvent;
public event EventHandler<UrlUpdateEvent> OnUrlUpdateEvent;

protected virtual void ServiceStatusEvent(MonitorServiceStatusEvent e) {
OnServiceStatusEvent?.Invoke(this, e);
Expand All @@ -41,7 +42,7 @@ protected virtual void InstallationNotificationEvent(InstallationNotificationEve
}

public MonitorClient(string id) : base(id) {

}

async protected override Task ConnectPipesAsync() {
Expand All @@ -62,8 +63,7 @@ async protected override Task ConnectPipesAsync() {
protected override void ProcessLine(string line) {
var evt = serializer.Deserialize<MonitorServiceStatusEvent>(new JsonTextReader(new StringReader(line)));

switch(evt.Type)
{
switch (evt.Type) {
case "Notification":
var instEvt = serializer.Deserialize<InstallationNotificationEvent>(new JsonTextReader(new StringReader(line)));
InstallationNotificationEvent(instEvt);
Expand Down Expand Up @@ -182,7 +182,7 @@ async public Task<SvcResponse> TriggerUpdate() {
return null;
}
async public Task<SvcResponse> SetAutomaticUpgradeDisabledAsync(bool disabled) {
ActionEvent action = new ActionEvent() { Op = "SetAutomaticUpgradeDisabled", Action = (disabled ? "true" : "false")};
ActionEvent action = new ActionEvent() { Op = "SetAutomaticUpgradeDisabled", Action = (disabled ? "true" : "false") };
try {
await sendAsync(action);
return await readAsync<SvcResponse>(ipcReader);
Expand Down
2 changes: 0 additions & 2 deletions ZitiDesktopEdge.Client/Utility/GithubAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public static class GithubAPI {

public const string ProdUrl = "https://api.github.com/repos/openziti/desktop-edge-win/releases/latest";
public const string BetaUrl = "https://api.github.com/repos/openziti/desktop-edge-win-beta/releases/latest";
public const string ProdReleasesUrl = "https://api.github.com/repos/openziti/desktop-edge-win/releases";
public const string BetaReleasesUrl = "https://api.github.com/repos/openziti/desktop-edge-win-beta/releases";

public static JObject GetJson(string url) {
HttpWebRequest httpWebRequest = WebRequest.CreateHttp(url);
Expand Down
4 changes: 4 additions & 0 deletions ZitiUpdateService/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
1000x the default UpdateTimer (1008 to be precise).
-->
<add key="InstallationCritical" value="7:0:0:0" />
<!--
The url to use when checking for updates.
-->
<add key="UpdateCheckURL" value="http://localhostasdf:18000/github.override.json" />
<add key="Version" value="release" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="UseBetaReleases" value="false" />
Expand Down
13 changes: 13 additions & 0 deletions ZitiUpdateService/UpdateJsonExample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "2.1.19 Override",
"tag_name": "2.1.19",
"created_at": "2020-12-02T16:48:11Z",
"published_at": "2022-11-10T20:03:12Z",
"assets": [
{
"name": "Ziti.Desktop.Edge.Client-2.1.19.exe",
"created_at": "2022-11-10T20:09:25Z",
"browser_download_url": "https://github.com/openziti/desktop-edge-win-beta/releases/download/2.1.19/Ziti.Desktop.Edge.Client-2.1.19.exe"
}
]
}
23 changes: 14 additions & 9 deletions ZitiUpdateService/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using DnsClient.Protocol;
using ZitiUpdateService.Utils;
using ZitiUpdateService.Checkers;
using System.Security.Policy;

#if !SKIPUPDATE
using ZitiUpdateService.Checkers.PeFile;
Expand Down Expand Up @@ -677,22 +678,26 @@ private void cleanOldLogs(string whereToScan) {
#if MOCKUPDATE
static DateTime mockDate = DateTime.Now;
#endif
private UpdateCheck getCheck(Version v)
{
private UpdateCheck getCheck(Version v) {
#if MOCKUPDATE
//run with MOCKUPDATE to enable debugging/mocking the update check
var check = new FilesystemCheck(v, -1, mockDate, "FilesysteCheck.download.mock.txt", new Version("2.1.4"));
#else
string updateUrl = null;
string releasesUrl = null;
if (!IsBeta) {
updateUrl = "https://api.github.com/repos/openziti/desktop-edge-win/releases/latest"; //hardcoded on purpose
releasesUrl = GithubAPI.ProdReleasesUrl;

var updateCheckUrl = ConfigurationManager.AppSettings.Get("UpdateCheckURL");
if (updateCheckUrl != null) {
updateUrl = updateCheckUrl;
} else {
updateUrl = "https://api.github.com/repos/openziti/desktop-edge-win-beta/releases/latest";
releasesUrl = GithubAPI.BetaReleasesUrl;
if (!IsBeta) {
updateUrl = GithubAPI.ProdUrl;
} else {
updateUrl = GithubAPI.BetaUrl;
}
}
var check = new GithubCheck(v, updateUrl, releasesUrl);


var check = new GithubCheck(v, updateUrl);
#endif
return check;
}
Expand Down
1 change: 1 addition & 0 deletions ZitiUpdateService/ZitiUpdateService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Resource Include="ziti.ico" />
<None Include="UpdateJsonExample.json" />
<None Include="ZitiUpdateService-log.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
16 changes: 7 additions & 9 deletions ZitiUpdateService/checkers/GithubCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@

using ZitiDesktopEdge.Utility;
using ZitiUpdateService.Checkers.PeFile;
using System.Configuration;

namespace ZitiUpdateService.Checkers {

internal class GithubCheck : UpdateCheck {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
string url;
string releasesUrl;
string updateCheckUrl;
string downloadUrl = null;
Version nextVersion = null;


public GithubCheck(Version compareTo, string url, string releasesUrl) : base(compareTo) {
this.url = url;
this.releasesUrl = releasesUrl;
public GithubCheck(Version compareTo, string url) : base(compareTo) {
this.updateCheckUrl = url;
Avail = CheckUpdate(compareTo);
}

Expand All @@ -41,9 +40,9 @@ override public void CopyUpdatePackage(string destinationFolder, string destinat

private int CheckUpdate(Version currentVersion) {
Logger.Debug("checking for update begins. current version detected as {0}", currentVersion);
Logger.Debug("issuing http get to url: {0}", url);
JObject json = GithubAPI.GetJson(url);
Logger.Debug("issuing http get to url: {0}", updateCheckUrl);

JObject json = GithubAPI.GetJson(updateCheckUrl);
JArray assets = JArray.Parse(json.Property("assets").Value.ToString());
foreach (JObject asset in assets.Children<JObject>()) {
string assetName = asset.Property("name").Value.ToString();
Expand All @@ -57,7 +56,7 @@ private int CheckUpdate(Version currentVersion) {
}

if (downloadUrl == null) {
Logger.Error("DOWNLOAD URL not found at: {0}", url);
Logger.Error("DOWNLOAD URL not found at: {0}", updateCheckUrl);
return 0;
}
Logger.Debug("download url detected: {0}", downloadUrl);
Expand All @@ -70,7 +69,6 @@ private int CheckUpdate(Version currentVersion) {
string isoPublishedDate = json.Property("published_at").Value.ToString();
PublishDate = DateTime.Parse(isoPublishedDate, null, System.Globalization.DateTimeStyles.RoundtripKind);


int compare = currentVersion.CompareTo(nextVersion);
if (compare < 0) {
Logger.Info("upgrade {} is available. Published version: {} is newer than the current version: {}", releaseName, nextVersion, currentVersion);
Expand Down

0 comments on commit b7aead4

Please sign in to comment.