Merge
This commit is contained in:
commit
b15d7966da
122 changed files with 5707 additions and 1069 deletions
|
@ -4543,6 +4543,69 @@ namespace WebsitePanel.EnterpriseServer
|
|||
);
|
||||
}
|
||||
|
||||
public static void DeleteAllEnterpriseFolderOwaUsers(int itemId, int folderId)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"DeleteAllEnterpriseFolderOwaUsers",
|
||||
new SqlParameter("@ItemID", itemId),
|
||||
new SqlParameter("@FolderID", folderId)
|
||||
);
|
||||
}
|
||||
|
||||
public static int AddEnterpriseFolderOwaUser(int itemId, int folderId, int accountId)
|
||||
{
|
||||
SqlParameter id = new SqlParameter("@ESOwsaUserId", SqlDbType.Int);
|
||||
id.Direction = ParameterDirection.Output;
|
||||
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"AddEnterpriseFolderOwaUser",
|
||||
id,
|
||||
new SqlParameter("@ItemID", itemId),
|
||||
new SqlParameter("@FolderID", folderId),
|
||||
new SqlParameter("@AccountId", accountId)
|
||||
);
|
||||
|
||||
// read identity
|
||||
return Convert.ToInt32(id.Value);
|
||||
}
|
||||
|
||||
public static IDataReader GetEnterpriseFolderOwaUsers(int itemId, int folderId)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetEnterpriseFolderOwaUsers",
|
||||
new SqlParameter("@ItemID", itemId),
|
||||
new SqlParameter("@FolderID", folderId)
|
||||
);
|
||||
}
|
||||
|
||||
public static IDataReader GetEnterpriseFolderId(int itemId, string folderName)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetEnterpriseFolderId",
|
||||
new SqlParameter("@ItemID", itemId),
|
||||
new SqlParameter("@FolderName", folderName)
|
||||
);
|
||||
}
|
||||
|
||||
public static IDataReader GetUserEnterpriseFolderWithOwaEditPermission(int itemId, int accountId)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetUserEnterpriseFolderWithOwaEditPermission",
|
||||
new SqlParameter("@ItemID", itemId),
|
||||
new SqlParameter("@AccountID", accountId)
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Support Service Levels
|
||||
|
@ -4613,6 +4676,37 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
#region RDS
|
||||
|
||||
public static int AddRdsCertificate(int serviceId, string content, byte[] hash, string fileName, DateTime? validFrom, DateTime? expiryDate)
|
||||
{
|
||||
SqlParameter rdsCertificateId = new SqlParameter("@RDSCertificateID", SqlDbType.Int);
|
||||
rdsCertificateId.Direction = ParameterDirection.Output;
|
||||
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"AddRDSCertificate",
|
||||
rdsCertificateId,
|
||||
new SqlParameter("@ServiceId", serviceId),
|
||||
new SqlParameter("@Content", content),
|
||||
new SqlParameter("@Hash", Convert.ToBase64String(hash)),
|
||||
new SqlParameter("@FileName", fileName),
|
||||
new SqlParameter("@ValidFrom", validFrom),
|
||||
new SqlParameter("@ExpiryDate", expiryDate)
|
||||
);
|
||||
|
||||
return Convert.ToInt32(rdsCertificateId.Value);
|
||||
}
|
||||
|
||||
public static IDataReader GetRdsCertificateByServiceId(int serviceId)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
ConnectionString,
|
||||
CommandType.StoredProcedure,
|
||||
"GetRDSCertificateByServiceId",
|
||||
new SqlParameter("@ServiceId", serviceId)
|
||||
);
|
||||
}
|
||||
|
||||
public static IDataReader GetRdsCollectionSettingsByCollectionId(int collectionId)
|
||||
{
|
||||
return SqlHelper.ExecuteReader(
|
||||
|
|
|
@ -32,6 +32,7 @@ using System.Collections.Specialized;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using WebsitePanel.Providers;
|
||||
using WebsitePanel.Providers.DNS;
|
||||
|
@ -385,7 +386,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var idn = new IdnMapping();
|
||||
|
||||
if (itemType == typeof(DnsZone))
|
||||
items.AddRange(dns.GetZones().Select(z => idn.GetUnicode(z)));
|
||||
items.AddRange(dns.GetZones().Select(z =>
|
||||
Encoding.UTF8.GetByteCount(z) == z.Length ? // IsASCII
|
||||
idn.GetUnicode(z) : z ));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
|
|
@ -152,6 +152,16 @@ namespace WebsitePanel.EnterpriseServer
|
|||
StartESBackgroundTaskInternal("SET_ENTERPRISE_FOLDER_SETTINGS", itemId, folder, permissions, directoyBrowsingEnabled, quota, quotaType);
|
||||
}
|
||||
|
||||
public static void SetESGeneralSettings(int itemId, SystemFile folder, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
|
||||
{
|
||||
SetESGeneralSettingsInternal("SET_ENTERPRISE_FOLDER_GENERAL_SETTINGS", itemId, folder, directoyBrowsingEnabled, quota, quotaType);
|
||||
}
|
||||
|
||||
public static void SetESFolderPermissionSettings(int itemId, SystemFile folder, ESPermission[] permissions)
|
||||
{
|
||||
SetESFolderPermissionSettingsInternal("SET_ENTERPRISE_FOLDER_GENERAL_SETTINGS", itemId, folder, permissions);
|
||||
}
|
||||
|
||||
public static int AddWebDavAccessToken(WebDavAccessToken accessToken)
|
||||
{
|
||||
return DataProvider.AddWebDavAccessToken(accessToken);
|
||||
|
@ -257,6 +267,69 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return rootFolders;
|
||||
}
|
||||
|
||||
protected static void SetESGeneralSettingsInternal(string taskName, int itemId, SystemFile folder, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
|
||||
{
|
||||
// load organization
|
||||
var org = OrganizationController.GetOrganization(itemId);
|
||||
|
||||
try
|
||||
{
|
||||
TaskManager.StartTask("ENTERPRISE_STORAGE", taskName, org.PackageId);
|
||||
|
||||
EnterpriseStorageController.SetFRSMQuotaOnFolder(itemId, folder.Name, quota, quotaType);
|
||||
EnterpriseStorageController.SetDirectoryBrowseEnabled(itemId, folder.Url, directoyBrowsingEnabled);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// log error
|
||||
TaskManager.WriteError(ex, "Error executing enterprise storage background task");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// complete task
|
||||
try
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void SetESFolderPermissionSettingsInternal(string taskName, int itemId, SystemFile folder, ESPermission[] permissions)
|
||||
{
|
||||
// load organization
|
||||
var org = OrganizationController.GetOrganization(itemId);
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.StartTask("ENTERPRISE_STORAGE", taskName, org.PackageId);
|
||||
|
||||
EnterpriseStorageController.SetFolderPermission(itemId, folder.Name, permissions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// log error
|
||||
TaskManager.WriteError(ex, "Error executing enterprise storage background task");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// complete task
|
||||
try
|
||||
{
|
||||
TaskManager.CompleteTask();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}).Start();
|
||||
}
|
||||
|
||||
protected static void StartESBackgroundTaskInternal(string taskName, int itemId, SystemFile folder, ESPermission[] permissions, bool directoyBrowsingEnabled, int quota, QuotaType quotaType)
|
||||
{
|
||||
// load organization
|
||||
|
@ -1265,6 +1338,87 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return null;
|
||||
}
|
||||
|
||||
public static OrganizationUser[] GetFolderOwaAccounts(int itemId, string folderName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var folderId = GetFolderId(itemId, folderName);
|
||||
|
||||
var users = ObjectUtils.CreateListFromDataReader<OrganizationUser>(DataProvider.GetEnterpriseFolderOwaUsers(itemId, folderId));
|
||||
|
||||
return users.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetFolderOwaAccounts(int itemId, string folderName, OrganizationUser[] users)
|
||||
{
|
||||
try
|
||||
{
|
||||
var folderId = GetFolderId(itemId, folderName);
|
||||
|
||||
DataProvider.DeleteAllEnterpriseFolderOwaUsers(itemId, folderId);
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
DataProvider.AddEnterpriseFolderOwaUser(itemId, folderId, user.AccountId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int GetFolderId(int itemId, string folderName)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetFolder(itemId, folderName);
|
||||
|
||||
var dataReader = DataProvider.GetEnterpriseFolderId(itemId, folderName);
|
||||
|
||||
while (dataReader.Read())
|
||||
{
|
||||
return (int)dataReader[0];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetUserEnterpriseFolderWithOwaEditPermission(int itemId, List<int> accountIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new List<string>();
|
||||
|
||||
|
||||
foreach (var accountId in accountIds)
|
||||
{
|
||||
var reader = DataProvider.GetUserEnterpriseFolderWithOwaEditPermission(itemId, accountId);
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(Convert.ToString(reader["FolderName"]));
|
||||
}
|
||||
}
|
||||
|
||||
return result.Distinct().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
#region WebDav portal
|
||||
|
||||
public static string GetWebDavPortalUserSettingsByAccountId(int accountId)
|
||||
|
|
|
@ -248,22 +248,22 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return GetRdsCollectionSessionHostsInternal(collectionId);
|
||||
}
|
||||
|
||||
public static RdsServerInfo GetRdsServerInfo(int itemId, string fqdnName)
|
||||
public static RdsServerInfo GetRdsServerInfo(int? itemId, string fqdnName)
|
||||
{
|
||||
return GetRdsServerInfoInternal(itemId, fqdnName);
|
||||
}
|
||||
|
||||
public static string GetRdsServerStatus(int itemId, string fqdnName)
|
||||
public static string GetRdsServerStatus(int? itemId, string fqdnName)
|
||||
{
|
||||
return GetRdsServerStatusInternal(itemId, fqdnName);
|
||||
}
|
||||
|
||||
public static ResultObject ShutDownRdsServer(int itemId, string fqdnName)
|
||||
public static ResultObject ShutDownRdsServer(int? itemId, string fqdnName)
|
||||
{
|
||||
return ShutDownRdsServerInternal(itemId, fqdnName);
|
||||
}
|
||||
|
||||
public static ResultObject RestartRdsServer(int itemId, string fqdnName)
|
||||
public static ResultObject RestartRdsServer(int? itemId, string fqdnName)
|
||||
{
|
||||
return RestartRdsServerInternal(itemId, fqdnName);
|
||||
}
|
||||
|
@ -278,31 +278,53 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return SaveRdsCollectionLocalAdminsInternal(users, collectionId);
|
||||
}
|
||||
|
||||
public static ResultObject InstallSessionHostsCertificate(int collectionId, byte[] certificate, string password)
|
||||
public static ResultObject InstallSessionHostsCertificate(RdsServer rdsServer)
|
||||
{
|
||||
return InstallSessionHostsCertificateInternal(collectionId, certificate, password);
|
||||
return InstallSessionHostsCertificateInternal(rdsServer);
|
||||
}
|
||||
|
||||
private static ResultObject InstallSessionHostsCertificateInternal(int collectionId, byte[] certificate, string password)
|
||||
public static RdsCertificate GetRdsCertificateByServiceId(int serviceId)
|
||||
{
|
||||
return GetRdsCertificateByServiceIdInternal(serviceId);
|
||||
}
|
||||
|
||||
public static RdsCertificate GetRdsCertificateByItemId(int? itemId)
|
||||
{
|
||||
return GetRdsCertificateByItemIdInternal(itemId);
|
||||
}
|
||||
|
||||
public static ResultObject AddRdsCertificate(RdsCertificate certificate)
|
||||
{
|
||||
return AddRdsCertificateInternal(certificate);
|
||||
}
|
||||
|
||||
public static List<ServiceInfo> GetRdsServices()
|
||||
{
|
||||
return GetRdsServicesInternal();
|
||||
}
|
||||
|
||||
private static List<ServiceInfo> GetRdsServicesInternal()
|
||||
{
|
||||
return ObjectUtils.CreateListFromDataSet<ServiceInfo>(DataProvider.GetServicesByGroupName(SecurityContext.User.UserId, ResourceGroups.RDS));
|
||||
}
|
||||
|
||||
private static ResultObject InstallSessionHostsCertificateInternal(RdsServer rdsServer)
|
||||
{
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "INSTALL_CERTIFICATE");
|
||||
|
||||
try
|
||||
{
|
||||
var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
|
||||
Organization org = OrganizationController.GetOrganization(collection.ItemId);
|
||||
{
|
||||
int serviceId = GetRdsServiceId(rdsServer.ItemId);
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
var certificate = GetRdsCertificateByServiceIdInternal(serviceId);
|
||||
|
||||
var array = Convert.FromBase64String(certificate.Hash);
|
||||
char[] chars = new char[array.Length / sizeof(char)];
|
||||
System.Buffer.BlockCopy(array, 0, chars, 0, array.Length);
|
||||
string password = new string(chars);
|
||||
byte[] content = Convert.FromBase64String(certificate.Content);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
result.IsSuccess = false;
|
||||
result.AddError("", new NullReferenceException("Organization not found"));
|
||||
return result;
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
var servers = ObjectUtils.CreateListFromDataReader<RdsServer>(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
|
||||
|
||||
rds.InstallCertificate(certificate, password, servers.Select(s => s.FqdName).ToArray());
|
||||
rds.InstallCertificate(content, password, new string[] {rdsServer.FqdName});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -323,6 +345,57 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
private static RdsCertificate GetRdsCertificateByServiceIdInternal(int serviceId)
|
||||
{
|
||||
var result = ObjectUtils.FillObjectFromDataReader<RdsCertificate>(DataProvider.GetRdsCertificateByServiceId(serviceId));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static RdsCertificate GetRdsCertificateByItemIdInternal(int? itemId)
|
||||
{
|
||||
int serviceId = GetRdsServiceId(itemId);
|
||||
var result = ObjectUtils.FillObjectFromDataReader<RdsCertificate>(DataProvider.GetRdsCertificateByServiceId(serviceId));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ResultObject AddRdsCertificateInternal(RdsCertificate certificate)
|
||||
{
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "ADD_RDS_SERVER");
|
||||
|
||||
try
|
||||
{
|
||||
byte[] hash = new byte[certificate.Hash.Length * sizeof(char)];
|
||||
System.Buffer.BlockCopy(certificate.Hash.ToCharArray(), 0, hash, 0, hash.Length);
|
||||
certificate.Id = DataProvider.AddRdsCertificate(certificate.ServiceId, certificate.Content, hash, certificate.FileName, certificate.ValidFrom, certificate.ExpiryDate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
result.AddError("Unable to add RDS Certificate", ex.InnerException);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AddError("Unable to add RDS Certificate", ex);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
TaskManager.CompleteResultTask(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskManager.CompleteResultTask();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static RdsCollection GetRdsCollectionInternal(int collectionId)
|
||||
{
|
||||
var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
|
||||
|
@ -370,9 +443,9 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
|
||||
var organizationUsers = OrganizationController.GetOrganizationUsersPaged(collection.ItemId, null, null, null, 0, Int32.MaxValue).PageUsers;
|
||||
var organizationAdmins = rds.GetRdsCollectionLocalAdmins(servers.First().FqdName);
|
||||
var organizationAdmins = rds.GetRdsCollectionLocalAdmins(org.OrganizationId, collection.Name);
|
||||
|
||||
return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.DomainUserName.ToLower())).ToList();
|
||||
return organizationUsers.Where(o => organizationAdmins.Select(a => a.ToLower()).Contains(o.SamAccountName.ToLower())).ToList();
|
||||
}
|
||||
|
||||
private static ResultObject SaveRdsCollectionLocalAdminsInternal(OrganizationUser[] users, int collectionId)
|
||||
|
@ -394,7 +467,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
var servers = ObjectUtils.CreateListFromDataReader<RdsServer>(DataProvider.GetRDSServersByCollectionId(collection.Id)).ToList();
|
||||
|
||||
rds.SaveRdsCollectionLocalAdmins(users, servers.Select(s => s.FqdName).ToArray());
|
||||
rds.SaveRdsCollectionLocalAdmins(users.Select(u => u.AccountName).ToArray(), servers.Select(s => s.FqdName).ToArray(), org.OrganizationId, collection.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -420,19 +493,22 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var collection = ObjectUtils.FillObjectFromDataReader<RdsCollection>(DataProvider.GetRDSCollectionById(collectionId));
|
||||
var settings = ObjectUtils.FillObjectFromDataReader<RdsCollectionSettings>(DataProvider.GetRdsCollectionSettingsByCollectionId(collectionId));
|
||||
|
||||
if (settings.SecurityLayer == null)
|
||||
if (settings != null)
|
||||
{
|
||||
settings.SecurityLayer = SecurityLayerValues.Negotiate.ToString();
|
||||
}
|
||||
if (settings.SecurityLayer == null)
|
||||
{
|
||||
settings.SecurityLayer = SecurityLayerValues.Negotiate.ToString();
|
||||
}
|
||||
|
||||
if (settings.EncryptionLevel == null)
|
||||
{
|
||||
settings.EncryptionLevel = EncryptionLevel.ClientCompatible.ToString();
|
||||
}
|
||||
if (settings.EncryptionLevel == null)
|
||||
{
|
||||
settings.EncryptionLevel = EncryptionLevel.ClientCompatible.ToString();
|
||||
}
|
||||
|
||||
if (settings.AuthenticateUsingNLA == null)
|
||||
{
|
||||
settings.AuthenticateUsingNLA = true;
|
||||
if (settings.AuthenticateUsingNLA == null)
|
||||
{
|
||||
settings.AuthenticateUsingNLA = true;
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
|
@ -453,17 +529,31 @@ namespace WebsitePanel.EnterpriseServer
|
|||
private static int AddRdsCollectionInternal(int itemId, RdsCollection collection)
|
||||
{
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "ADD_RDS_COLLECTION");
|
||||
var domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
|
||||
|
||||
try
|
||||
{
|
||||
// load organization
|
||||
Organization org = OrganizationController.GetOrganization(itemId);
|
||||
if (org == null)
|
||||
{
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
|
||||
foreach(var server in collection.Servers)
|
||||
{
|
||||
if (!server.FqdName.EndsWith(domainName, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
throw TaskManager.WriteError(new Exception("Fully Qualified Domain Name not valid."));
|
||||
}
|
||||
|
||||
if (!rds.CheckRDSServerAvaliable(server.FqdName))
|
||||
{
|
||||
throw TaskManager.WriteError(new Exception(string.Format("Unable to connect to {0} server.", server.FqdName)));
|
||||
}
|
||||
}
|
||||
|
||||
collection.Name = GetFormattedCollectionName(collection.DisplayName, org.OrganizationId);
|
||||
|
||||
collection.Settings = new RdsCollectionSettings
|
||||
|
@ -743,7 +833,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
FillRdsServerData(tmpServer);
|
||||
}
|
||||
|
||||
result.Servers = tmpServers.ToArray();
|
||||
result.Servers = tmpServers.ToArray();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -935,27 +1025,29 @@ namespace WebsitePanel.EnterpriseServer
|
|||
|
||||
try
|
||||
{
|
||||
if (CheckRDSServerAvaliable(rdsServer.FqdName))
|
||||
int serviceId = GetRdsMainServiceId();
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
|
||||
if (rds.CheckRDSServerAvaliable(rdsServer.FqdName))
|
||||
{
|
||||
rdsServer.Id = DataProvider.AddRDSServer(rdsServer.Name, rdsServer.FqdName, rdsServer.Description);
|
||||
var domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
|
||||
|
||||
if (rdsServer.FqdName.EndsWith(domainName, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
rds.AddSessionHostFeatureToServer(rdsServer.FqdName);
|
||||
rds.MoveSessionHostToRdsOU(rdsServer.Name);
|
||||
rdsServer.Id = DataProvider.AddRDSServer(rdsServer.Name, rdsServer.FqdName, rdsServer.Description);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw TaskManager.WriteError(new Exception("Fully Qualified Domain Name not valid."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AddError("REMOTE_DESKTOP_SERVICES_ADD_RDS_SERVER", new Exception("The server that you are adding, is not available"));
|
||||
return result;
|
||||
throw TaskManager.WriteError(new Exception(string.Format("Unable to connect to {0} server. Please double check Server Full Name setting and retry.", rdsServer.FqdName)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
result.AddError("Unable to add RDS Server", ex.InnerException);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AddError("Unable to add RDS Server", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!result.IsSuccess)
|
||||
|
@ -1101,12 +1193,6 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
|
||||
RdsServer rdsServer = GetRdsServer(serverId);
|
||||
|
||||
//if (!rds.CheckSessionHostFeatureInstallation(rdsServer.FqdName))
|
||||
{
|
||||
rds.AddSessionHostFeatureToServer(rdsServer.FqdName);
|
||||
}
|
||||
|
||||
rds.MoveRdsServerToTenantOU(rdsServer.FqdName, org.OrganizationId);
|
||||
DataProvider.AddRDSServerToOrganization(itemId, serverId);
|
||||
}
|
||||
|
@ -1415,36 +1501,32 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
private static RdsServerInfo GetRdsServerInfoInternal(int itemId, string fqdnName)
|
||||
private static RdsServerInfo GetRdsServerInfoInternal(int? itemId, string fqdnName)
|
||||
{
|
||||
Organization org = OrganizationController.GetOrganization(itemId);
|
||||
int serviceId = GetRdsServiceId(itemId);
|
||||
var result = new RdsServerInfo();
|
||||
|
||||
if (org == null)
|
||||
if (serviceId != -1)
|
||||
{
|
||||
return new RdsServerInfo();
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
result = rds.GetRdsServerInfo(fqdnName);
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
var result = rds.GetRdsServerInfo(fqdnName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetRdsServerStatusInternal(int itemId, string fqdnName)
|
||||
{
|
||||
Organization org = OrganizationController.GetOrganization(itemId);
|
||||
private static string GetRdsServerStatusInternal(int? itemId, string fqdnName)
|
||||
{
|
||||
var result = "Unavailable";
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
var serviceId = GetRdsServiceId(itemId);
|
||||
|
||||
try
|
||||
{
|
||||
result = rds.GetRdsServerStatus(fqdnName);
|
||||
if (serviceId != -1)
|
||||
{
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
result = rds.GetRdsServerStatus(fqdnName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -1453,23 +1535,19 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
private static ResultObject ShutDownRdsServerInternal(int itemId, string fqdnName)
|
||||
private static ResultObject ShutDownRdsServerInternal(int? itemId, string fqdnName)
|
||||
{
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "SHUTDOWN_RDS_SERVER");
|
||||
|
||||
try
|
||||
{
|
||||
Organization org = OrganizationController.GetOrganization(itemId);
|
||||
{
|
||||
int serviceId = GetRdsServiceId(itemId);
|
||||
|
||||
if (org == null)
|
||||
if (serviceId != -1)
|
||||
{
|
||||
result.IsSuccess = false;
|
||||
result.AddError("", new NullReferenceException("Organization not found"));
|
||||
return result;
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
rds.ShutDownRdsServer(fqdnName);
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
rds.ShutDownRdsServer(fqdnName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1490,23 +1568,19 @@ namespace WebsitePanel.EnterpriseServer
|
|||
return result;
|
||||
}
|
||||
|
||||
private static ResultObject RestartRdsServerInternal(int itemId, string fqdnName)
|
||||
private static ResultObject RestartRdsServerInternal(int? itemId, string fqdnName)
|
||||
{
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "RESTART_RDS_SERVER");
|
||||
var result = TaskManager.StartResultTask<ResultObject>("REMOTE_DESKTOP_SERVICES", "RESTART_RDS_SERVER");
|
||||
|
||||
try
|
||||
{
|
||||
Organization org = OrganizationController.GetOrganization(itemId);
|
||||
int serviceId = GetRdsServiceId(itemId);
|
||||
|
||||
if (org == null)
|
||||
if (serviceId != -1)
|
||||
{
|
||||
result.IsSuccess = false;
|
||||
result.AddError("", new NullReferenceException("Organization not found"));
|
||||
return result;
|
||||
var rds = GetRemoteDesktopServices(serviceId);
|
||||
rds.RestartRdsServer(fqdnName);
|
||||
}
|
||||
|
||||
var rds = GetRemoteDesktopServices(GetRemoteDesktopServiceID(org.PackageId));
|
||||
rds.RestartRdsServer(fqdnName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1668,22 +1742,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
var address = Dns.GetHostAddresses(hostname);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
private static bool CheckRDSServerAvaliable(string hostname)
|
||||
{
|
||||
bool result = false;
|
||||
var ping = new Ping();
|
||||
var reply = ping.Send(hostname, 1000);
|
||||
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ResultObject DeleteRemoteDesktopServiceInternal(int itemId)
|
||||
{
|
||||
|
@ -1727,16 +1786,58 @@ namespace WebsitePanel.EnterpriseServer
|
|||
private static int GetRemoteDesktopServiceID(int packageId)
|
||||
{
|
||||
return PackageController.GetPackageServiceId(packageId, ResourceGroups.RDS);
|
||||
}
|
||||
|
||||
private static int GetRdsServiceId(int? itemId)
|
||||
{
|
||||
int serviceId = -1;
|
||||
|
||||
if (itemId.HasValue)
|
||||
{
|
||||
Organization org = OrganizationController.GetOrganization(itemId.Value);
|
||||
|
||||
if (org == null)
|
||||
{
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
serviceId = GetRemoteDesktopServiceID(org.PackageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceId = GetRdsMainServiceId();
|
||||
}
|
||||
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
private static RemoteDesktopServices GetRemoteDesktopServices(int serviceId)
|
||||
{
|
||||
var rds = new RemoteDesktopServices();
|
||||
ServiceProviderProxy.Init(rds, serviceId);
|
||||
ServiceProviderProxy.Init(rds, serviceId);
|
||||
|
||||
return rds;
|
||||
}
|
||||
|
||||
private static int GetRdsMainServiceId()
|
||||
{
|
||||
var settings = SystemController.GetSystemSettings(WebsitePanel.EnterpriseServer.SystemSettings.RDS_SETTINGS);
|
||||
|
||||
if (!string.IsNullOrEmpty(settings["RdsMainController"]))
|
||||
{
|
||||
return Convert.ToInt32(settings["RdsMainController"]);
|
||||
}
|
||||
|
||||
var rdsServices = GetRdsServicesInternal();
|
||||
|
||||
if (rdsServices.Any())
|
||||
{
|
||||
return rdsServices.First().ServiceId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static string GetFormattedCollectionName(string displayName, string organizationId)
|
||||
{
|
||||
return string.Format("{0}-{1}", organizationId, displayName.Replace(" ", "_"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue