Skip to content

Commit

Permalink
Merge pull request #3197 from kc284/master
Browse files Browse the repository at this point in the history
Merge feature/cdn-updates to master + CA-381216
  • Loading branch information
kc284 authored Aug 11, 2023
2 parents 4d0d232 + de18d64 commit bee2388
Show file tree
Hide file tree
Showing 145 changed files with 15,313 additions and 2,628 deletions.
Binary file modified Branding/Images/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* SUCH DAMAGE.
*/

def XENADMIN_BRANDING_TAG = 'v4.17'
def XENADMIN_BRANDING_TAG = 'v5.0'

@Library(['PacmanSharedLibrary', "[email protected]"])
import com.citrix.pipeline.xencenter.*
Expand Down
117 changes: 117 additions & 0 deletions XenAdmin/Actions/GUIActions/ConfigYumRepoAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* Copyright (c) Cloud Software Group, Inc.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

using System.Collections.Generic;
using System.Linq;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAPI;

namespace XenAdmin.Actions.GUIActions
{
internal class ConfigYumRepoAction : AsyncAction
{
private readonly RepoDescriptor _repoToEnable;
private readonly Repository _introducedRepo;
private readonly List<Repository> _oldEnabledRepos;
private readonly Pool _pool;

public ConfigYumRepoAction(IXenConnection connection, RepoDescriptor repoDescriptor)
: base(connection, string.Empty)
{
Title = Description = string.Format(Messages.YUM_REPO_ACTION_CONFIG_TITLE, connection.Name, repoDescriptor.FriendlyName);

_repoToEnable = repoDescriptor;

_introducedRepo = connection.Cache.Repositories.FirstOrDefault(r => _repoToEnable.MatchesRepository(r));

_pool = Helpers.GetPoolOfOne(Connection);

_oldEnabledRepos = (from XenRef<Repository> repoRef in _pool.repositories
let repo = Connection.Resolve(repoRef)
where !_repoToEnable.MatchesRepository(repo)
select repo).ToList();

#region RBAC

if (_oldEnabledRepos.Count > 0)
ApiMethodsToRoleCheck.Add("Pool.remove_repository");

if (_introducedRepo == null)
ApiMethodsToRoleCheck.Add("Repository.introduce");

ApiMethodsToRoleCheck.Add("Pool.add_repository");

#endregion
}

protected override void Run()
{
foreach (var repo in _oldEnabledRepos)
{
var repoName = RepoDescriptor.AllRepos.FirstOrDefault(r => r.MatchesRepository(repo))?.FriendlyName ?? string.Empty;
Description = string.Format(Messages.YUM_REPO_ACTION_CONFIG_DESCRIPTION_DISABLE, repoName);
Pool.remove_repository(Session, _pool.opaque_ref, repo.opaque_ref);
}

XenRef<Repository> repoRef;

if (_introducedRepo == null)
{
var baseRepo = RepoDescriptor.BaseRepo;

if (!Connection.Cache.Repositories.Any(r => baseRepo.MatchesRepository(r)))
{
Description = string.Format(Messages.YUM_REPO_ACTION_CONFIG_DESCRIPTION_INTRODUCE, baseRepo.FriendlyName);

Repository.introduce(Session, baseRepo.Key, baseRepo.FriendlyName, baseRepo.BinUrl, baseRepo.SourceUrl, false, "");
}

Description = string.Format(Messages.YUM_REPO_ACTION_CONFIG_DESCRIPTION_INTRODUCE, _repoToEnable.FriendlyName);

repoRef = Repository.introduce(Session, _repoToEnable.Key, _repoToEnable.FriendlyName,
_repoToEnable.BinUrl, _repoToEnable.SourceUrl, true, "");
}
else
{
repoRef = new XenRef<Repository>(_introducedRepo.opaque_ref);
}

Description = string.Format(Messages.YUM_REPO_ACTION_CONFIG_DESCRIPTION_ENABLE, _repoToEnable.FriendlyName);

Pool.add_repository(Session, _pool.opaque_ref, repoRef);

//wait until the cache has been updated so that the config panel can show
//the new value if the action was triggered by hitting the Apply button

Connection.WaitFor(() => _pool.repositories.Contains(repoRef), null);
}
}
}
9 changes: 6 additions & 3 deletions XenAdmin/Actions/GUIActions/DismissAlertsAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ protected override void Run()
if (_alerts.Count > 0)
midPoint = 100 * msgAlerts.Count / _alerts.Count;

RelatedTask = Message.async_destroy_many(Session, msgRefs);
PollToCompletion(0, midPoint);
Alert.RemoveAlert(a => msgAlerts.Contains(a));
if (msgAlerts.Count > 0)
{
RelatedTask = Message.async_destroy_many(Session, msgRefs);
PollToCompletion(0, midPoint);
Alert.RemoveAlert(a => msgAlerts.Contains(a));
}

for (var i = 0; i < otherAlerts.Count; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions XenAdmin/Actions/GUIActions/ExternalPluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ private void CheckPermission(IXenConnection xenConnection)
List<Role> rolesAbleToCompleteAction;
bool ableToCompleteAction = Role.CanPerform(methodsToCheck, xenConnection, out rolesAbleToCompleteAction);

log.DebugFormat("Roles able to complete action: {0}", Role.FriendlyCSVRoleList(rolesAbleToCompleteAction));
log.DebugFormat("Subject {0} has roles: {1}", xenConnection.Session.UserLogName(), Role.FriendlyCSVRoleList(xenConnection.Session.Roles));
log.DebugFormat("Roles able to complete action: {0}", Role.FriendlyCsvRoleList(rolesAbleToCompleteAction));
log.DebugFormat("Subject {0} has roles: {1}", xenConnection.Session.UserLogName(), Role.FriendlyCsvRoleList(xenConnection.Session.Roles));

if (ableToCompleteAction)
{
Expand All @@ -206,7 +206,7 @@ private void CheckPermission(IXenConnection xenConnection)
// Can't run on this connection, bail out
string desc = string.Format(FriendlyErrorNames.RBAC_PERMISSION_DENIED_FRIENDLY_CONNECTION,
xenConnection.Session.FriendlyRoleDescription(),
Role.FriendlyCSVRoleList(rolesAbleToCompleteAction),
Role.FriendlyCsvRoleList(rolesAbleToCompleteAction),
xenConnection.Name);
throw new Exception(desc);
}
Expand Down
14 changes: 14 additions & 0 deletions XenAdmin/Alerts/AlertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,19 @@ public static string GetUpdateDetailsCSVQuotes(this Alert a)
date.EscapeQuotes(),
a.WebPageLabel.EscapeQuotes());
}

public static string GetGuiDate(DateTime? dateTime)
{
string date = string.Empty;

Program.Invoke(Program.MainWindow,
() =>
{
if (dateTime.HasValue)
date = HelpersGUI.DateTimeToString(dateTime.Value.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
});

return date;
}
}
}
11 changes: 3 additions & 8 deletions XenAdmin/Alerts/NewVersionPriorityAlertComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@ public int Compare(Alert alert1, Alert alert2)
if (alert1 == null || alert2 == null)
return 0;

int sortResult = 0;

if (IsVersionOrVersionUpdateAlert(alert1) && !IsVersionOrVersionUpdateAlert(alert2))
sortResult = 1;
return -1;

if (!IsVersionOrVersionUpdateAlert(alert1) && IsVersionOrVersionUpdateAlert(alert2))
sortResult = -1;

if (sortResult == 0)
sortResult = Alert.CompareOnDate(alert1, alert2);
return 1;

return -sortResult;
return -Alert.CompareOnDate(alert1, alert2); //descending date
}

private bool IsVersionOrVersionUpdateAlert(Alert alert)
Expand Down
29 changes: 9 additions & 20 deletions XenAdmin/Alerts/Types/CertificateAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,35 @@ public override string Description
{
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRED:
var pool1 = Helpers.GetPoolOfOne(Connection);
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRED_DESCIRPTION, objectName, pool1.Name(), GetExpiryDate());
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRED_DESCIRPTION, objectName, pool1.Name(),
AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_07:
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_14:
case Message.MessageType.POOL_CA_CERTIFICATE_EXPIRING_30:
var pool2 = Helpers.GetPoolOfOne(Connection);
return string.Format(Messages.CERTIFICATE_CA_ALERT_EXPIRING_DESCRIPTION,
objectName, pool2.Name(), GetExpiryDate());
objectName, pool2.Name(), AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRED:
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRED_DESCIRPTION, objectName, GetExpiryDate());
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRED_DESCIRPTION,
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_07:
case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_14:
case Message.MessageType.HOST_INTERNAL_CERTIFICATE_EXPIRING_30:
return string.Format(Messages.CERTIFICATE_HOST_INTERNAL_ALERT_EXPIRING_DESCRIPTION,
objectName, GetExpiryDate());
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRED:
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRED_DESCIRPTION, objectName, GetExpiryDate());
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRED_DESCIRPTION, objectName,
AlertExtensions.GetGuiDate(_certificateExpiryDate));

case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_07:
case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_14:
case Message.MessageType.HOST_SERVER_CERTIFICATE_EXPIRING_30:
return string.Format(Messages.CERTIFICATE_HOST_ALERT_EXPIRING_DESCRIPTION,
objectName, GetExpiryDate());
objectName, AlertExtensions.GetGuiDate(_certificateExpiryDate));

default:
return base.Title;
Expand Down Expand Up @@ -237,19 +240,5 @@ public override string FixLinkText
public override string HelpID => "CertificateAlert";

public override string HelpLinkText => Messages.ALERT_GENERIC_HELP;

private string GetExpiryDate()
{
string date = string.Empty;

Program.Invoke(Program.MainWindow,
() =>
{
if (_certificateExpiryDate.HasValue)
date = HelpersGUI.DateTimeToString(_certificateExpiryDate.Value.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
});

return date;
}
}
}
108 changes: 108 additions & 0 deletions XenAdmin/Alerts/Types/CssExpiryAlert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* Copyright (c) Cloud Software Group, Inc.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

using System;
using System.Diagnostics;
using System.Xml;
using XenAPI;


namespace XenAdmin.Alerts
{
public class CssExpiryAlert : MessageAlert
{
private readonly DateTime? _cssExpiryDate;
private readonly string _title;
private readonly string _description;

public CssExpiryAlert(Message m)
: base(m)
{
try
{
var doc = new XmlDocument();
doc.LoadXml(m.body);
var nodes = doc.GetElementsByTagName("date");

if (nodes.Count > 0 && Util.TryParseIso8601DateTime(nodes[0].InnerText, out var result))
_cssExpiryDate = result;
}
catch
{
//ignore
}

switch (Message.Type)
{
case Message.MessageType.UPDATES_FEATURE_EXPIRED:
_title = Messages.ALERT_CSS_EXPIRED_TITLE;
_description = string.Format(Messages.ALERT_CSS_EXPIRED_DESCIRPTION, AlertExtensions.GetGuiDate(_cssExpiryDate));
break;

case Message.MessageType.UPDATES_FEATURE_EXPIRING_CRITICAL:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_MAJOR:
case Message.MessageType.UPDATES_FEATURE_EXPIRING_WARNING:

if (_cssExpiryDate.HasValue && _cssExpiryDate.Value > Timestamp)
{
var eta = _cssExpiryDate.Value - Timestamp;

if (eta.TotalDays >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_DAYS, Math.Round(eta.TotalDays, MidpointRounding.AwayFromZero));

else if (eta.TotalHours >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_HOURS, Math.Round(eta.TotalHours, MidpointRounding.AwayFromZero));

else if (eta.TotalMinutes >= 1)
_title = string.Format(Messages.ALERT_CSS_EXPIRING_TITLE_MINUTES, Math.Round(eta.TotalMinutes, MidpointRounding.AwayFromZero));
}
else
{
_title = Messages.ALERT_CSS_EXPIRED_TITLE;
}

_description = string.Format(Messages.ALERT_CSS_EXPIRING_DESCRIPTION, AlertExtensions.GetGuiDate(_cssExpiryDate));
break;
}
}

public override string Title => string.IsNullOrEmpty(_title) ? base.Title : _title;

public override string Description => string.IsNullOrEmpty(_description) ? base.Title : _description;

public override Action FixLinkAction => () => Process.Start(InvisibleMessages.CSS_URL);

public override string FixLinkText => Messages.ALERT_CSS_EXPIRED_LINK_TEXT;

public override string HelpID => "CssExpiryAlert";

public override string HelpLinkText => Messages.ALERT_GENERIC_HELP;
}
}
Loading

0 comments on commit bee2388

Please sign in to comment.