diff --git a/Disco.BI/BI/Interop/Community/UpdateCheck.cs b/Disco.BI/BI/Interop/Community/UpdateCheck.cs deleted file mode 100644 index 85579910..00000000 --- a/Disco.BI/BI/Interop/Community/UpdateCheck.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Disco.Data.Repository; -using Disco.Models.BI.Interop.Community; -using Disco.Models.Repository; -using Disco.Services.Tasks; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Xml.Linq; -using System.Xml.Serialization; - -namespace Disco.BI.Interop.Community -{ - public static class UpdateCheck - { - private static string UpdateUrl() - { - return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoUpdate/V1"); - } - - public static Version CurrentDiscoVersion() - { - return typeof(UpdateCheck).Assembly.GetName().Version; - } - public static string CurrentDiscoVersionFormatted() - { - var v = CurrentDiscoVersion(); - return string.Format("{0}.{1}.{2:0000}.{3:0000}", v.Major, v.Minor, v.Build, v.Revision); - } - - public static UpdateResponse Check(DiscoDataContext Database, bool UseProxy, IScheduledTaskStatus status) - { - status.UpdateStatus(10, "Building Update Request"); - - var request = BuildRequest(Database); - - status.UpdateStatus(40, "Sending Request"); - - var DiscoBIVersion = CurrentDiscoVersionFormatted(); - - HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(UpdateUrl()); - - // Added: 2013-02-08 G# - // Fix for Proxy Servers which dont support KeepAlive - webRequest.KeepAlive = false; - // End Added: 2013-02-08 G# - - if (!UseProxy) - webRequest.Proxy = new WebProxy(); - - webRequest.ContentType = "application/json"; - webRequest.Method = WebRequestMethods.Http.Post; - webRequest.UserAgent = string.Format("Disco/{0} (Update)", DiscoBIVersion); - - using (var wrStream = webRequest.GetRequestStream()) - { - XmlSerializer xml = new XmlSerializer(typeof(UpdateRequestV1)); - xml.Serialize(wrStream, request); - } - status.UpdateStatus(50, "Waiting for Response"); - using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) - { - if (webResponse.StatusCode == HttpStatusCode.OK) - { - status.UpdateStatus(90, "Reading Response"); - UpdateResponse result; - using (var wResStream = webResponse.GetResponseStream()) - { - XmlSerializer xml = new XmlSerializer(typeof(UpdateResponse)); - result = (UpdateResponse)xml.Deserialize(wResStream); - } - Database.DiscoConfiguration.UpdateLastCheck = result; - Database.SaveChanges(); - - status.SetFinishedMessage(string.Format("The update server reported Version {0} is the latest.", result.Version)); - - return result; - } - else - { - status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription))); - return null; - } - } - } - - private static UpdateRequestV1 BuildRequest(DiscoDataContext Database) - { - var m = new UpdateRequestV1(); - - m.DeploymentId = Database.DiscoConfiguration.DeploymentId; - - m.CurrentDiscoVersion = CurrentDiscoVersionFormatted(); - - m.OrganisationName = Database.DiscoConfiguration.OrganisationName; - m.BroadbandDoeWanId = GetBroadbandDoeWanId(); - m.BetaDeployment = Database.DiscoConfiguration.UpdateBetaDeployment; - - m.Stat_JobCounts = Database.Jobs.GroupBy(j => j.JobTypeId).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key, Count = g.Count() }).ToList(); - m.Stat_OpenJobCounts = Database.Jobs.Where(j => j.ClosedDate == null).GroupBy(j => j.JobTypeId).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key, Count = g.Count() }).ToList(); - m.Stat_DeviceModelCounts = Database.DeviceModels.Select(dm => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = dm.Manufacturer + ";" + dm.Model, Count = dm.Devices.Count(d => d.DecommissionedDate == null) }).ToList(); - var activeThreshold = DateTime.Now.AddDays(-60); - m.Stat_ActiveDeviceModelCounts = Database.DeviceModels.Select(dm => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = dm.Manufacturer + ";" + dm.Model, Count = dm.Devices.Count(d => d.DecommissionedDate == null && (d.LastNetworkLogonDate == null || d.LastNetworkLogonDate > activeThreshold)) }).ToList(); - m.Stat_UserCounts = new List() { - new UpdateRequestV1.Stat(){ - Key = "All Users", - Count = Database.Users.Count() - } - }; - - m.Stat_JobWarrantyVendorCounts = Database.Jobs.Where(j => j.JobTypeId == JobType.JobTypeIds.HWar && j.JobMetaWarranty.ExternalLoggedDate.HasValue && j.JobMetaWarranty.ExternalName != null).GroupBy(j => j.JobMetaWarranty.ExternalName).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key ?? "", Count = g.Count() }).ToList(); - - m.InstalledPlugins = Disco.Services.Plugins.Plugins.GetPlugins().Select(manifest => new Disco.Models.BI.Interop.Community.UpdateRequestV1.PluginRef { Id = manifest.Id, Version = manifest.VersionFormatted }).ToList(); - - return m; - } - - #region DoE Query - public static string GetBroadbandDoeWanId() - { - // DnsQuery for broadband.doe.wan - IPHostEntry doeWanDnsEntry; - try - { - doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan"); - } - catch (Exception) - { return null; } // Fail on error - - // Try using IPSearch feature - XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(false); - if (doeWanIPSearchResult == null) - doeWanIPSearchResult = TryDownloadDoeIPSearch(true); - - if (doeWanIPSearchResult == null) - return null; - - try - { - return doeWanIPSearchResult.Element("resultset").Element("site").Element("number").Value.ToLower(); - } - catch (Exception) - { return null; } // Fail on error - } - private static XDocument TryDownloadDoeIPSearch(bool useProxy) - { - try - { - var DiscoBIVersion = CurrentDiscoVersionFormatted(); - - HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php"); - // Added: 2013-02-08 G# - // Fix for Proxy Servers which dont support KeepAlive - wReq.KeepAlive = false; - // End Added: 2013-02-08 G# - if (!useProxy) - wReq.Proxy = new WebProxy(); // Empty Proxy Config - wReq.Method = WebRequestMethods.Http.Post; - wReq.ContentType = "application/x-www-form-urlencoded"; - wReq.UserAgent = string.Format("Disco/{0}", DiscoBIVersion); - using (var wrStream = wReq.GetRequestStream()) - { - using (var wrStreamWriter = new StreamWriter(wrStream)) - { - wrStreamWriter.Write("mode=whoami"); - } - } - using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse()) - { - if (wRes.StatusCode == HttpStatusCode.OK) - { - using (var wResStream = wRes.GetResponseStream()) - { - return XDocument.Load(wResStream); - } - } - else - return null; - } - } - catch (Exception) - { return null; } // Fail on error - } - #endregion - - } -} diff --git a/Disco.BI/Disco.BI.csproj b/Disco.BI/Disco.BI.csproj index 5c5390b6..290f2bd2 100644 --- a/Disco.BI/Disco.BI.csproj +++ b/Disco.BI/Disco.BI.csproj @@ -146,8 +146,6 @@ - - @@ -207,7 +205,7 @@ - + diff --git a/Disco.Data/Configuration/CommunityHelpers.cs b/Disco.Data/Configuration/CommunityHelpers.cs deleted file mode 100644 index 9b20bf11..00000000 --- a/Disco.Data/Configuration/CommunityHelpers.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Linq; -using System.Net; - -namespace Disco.Data.Configuration -{ - public static class CommunityHelpers - { - public static string CommunityUrl() - { - // Special case for DiscoCommunity Hosting Network - try - { - var ip = (from addr in Dns.GetHostEntry(Dns.GetHostName()).AddressList - where addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork - && addr.ToString().StartsWith("10.131.200.") - select addr).FirstOrDefault(); - if (ip != null) - { - return "http://hades3:9393/base/"; - } - } - catch (Exception) - { } // Ignore Errors - - return "https://discoict.com.au/base/"; - } - } -} diff --git a/Disco.Data/Configuration/SystemConfiguration.cs b/Disco.Data/Configuration/SystemConfiguration.cs index 05ea67de..3311fd34 100644 --- a/Disco.Data/Configuration/SystemConfiguration.cs +++ b/Disco.Data/Configuration/SystemConfiguration.cs @@ -1,5 +1,5 @@ using Disco.Data.Repository; -using Disco.Models.BI.Interop.Community; +using Disco.Models.Services.Interop.DiscoServices; using System; using System.IO; @@ -269,11 +269,18 @@ namespace Disco.Data.Configuration return this.Get(null); } } - public UpdateResponse UpdateLastCheck + public string DeploymentSecret { get { - return this.Get(null); + return this.Get(null); + } + } + public UpdateResponseV2 UpdateLastCheckResponse + { + get + { + return this.Get(null); } set { diff --git a/Disco.Data/Disco.Data.csproj b/Disco.Data/Disco.Data.csproj index 4eee00c7..6f20200f 100644 --- a/Disco.Data/Disco.Data.csproj +++ b/Disco.Data/Disco.Data.csproj @@ -73,7 +73,6 @@ - @@ -220,7 +219,7 @@ - + diff --git a/Disco.Data/Migrations/201407100413342_DBv15.cs b/Disco.Data/Migrations/201407100413342_DBv15.cs index 6474c94d..0f2dcd01 100644 --- a/Disco.Data/Migrations/201407100413342_DBv15.cs +++ b/Disco.Data/Migrations/201407100413342_DBv15.cs @@ -8,6 +8,9 @@ namespace Disco.Data.Migrations public override void Up() { AddColumn("dbo.DeviceModels", "DefaultRepairProvider", c => c.String(maxLength: 40)); + + // Clear UpdateLastCheck due to Update Protocol v2 + Sql("DELETE [Configuration] WHERE [Scope]='System' AND [Key]='UpdateLastCheck'"); } public override void Down() diff --git a/Disco.Data/Repository/DiscoDataSeeder.cs b/Disco.Data/Repository/DiscoDataSeeder.cs index 8a954649..258942b3 100644 --- a/Disco.Data/Repository/DiscoDataSeeder.cs +++ b/Disco.Data/Repository/DiscoDataSeeder.cs @@ -34,6 +34,11 @@ namespace Disco.Data.Repository var deploymentId = Guid.NewGuid().ToString("D"); Database.ConfigurationItems.Add(new ConfigurationItem { Scope = "System", Key = "DeploymentId", Value = deploymentId }); } + if (Database.ConfigurationItems.Count(ci => ci.Scope == "System" && ci.Key == "DeploymentSecret") == 0) + { + var deploymentId = Guid.NewGuid().ToString("N"); + Database.ConfigurationItems.Add(new ConfigurationItem { Scope = "System", Key = "DeploymentSecret", Value = deploymentId }); + } } public static void SeedJobTypes(this DiscoDataContext Database) { diff --git a/Disco.Models/BI/Interop/Community/UpdateRequestBase.cs b/Disco.Models/BI/Interop/Community/UpdateRequestBase.cs deleted file mode 100644 index 70b22e7f..00000000 --- a/Disco.Models/BI/Interop/Community/UpdateRequestBase.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace Disco.Models.BI.Interop.Community -{ - public class UpdateRequestBase - { - public virtual int RequestVersion { get; set; } - } -} diff --git a/Disco.Models/BI/Interop/Community/UpdateRequestV1.cs b/Disco.Models/BI/Interop/Community/UpdateRequestV1.cs deleted file mode 100644 index 0db656f5..00000000 --- a/Disco.Models/BI/Interop/Community/UpdateRequestV1.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Disco.Models.BI.Interop.Community -{ - public class UpdateRequestV1 : UpdateRequestBase - { - public UpdateRequestV1() - { - this.RequestVersion = 1; - } - - public string DeploymentId { get; set; } - public string CurrentDiscoVersion { get; set; } - public bool BetaDeployment { get; set; } - - public string OrganisationName { get; set; } - public string BroadbandDoeWanId { get; set; } - - public List Stat_JobCounts { get; set; } - public List Stat_OpenJobCounts { get; set; } - public List Stat_ActiveDeviceModelCounts { get; set; } - public List Stat_DeviceModelCounts { get; set; } - public List Stat_UserCounts { get; set; } - - public List InstalledPlugins { get; set; } - - public List Stat_JobWarrantyVendorCounts { get; set; } - - public class Stat - { - public string Key { get; set; } - public int Count { get; set; } - } - - public class PluginRef - { - public string Id { get; set; } - public string Version { get; set; } - } - } -} diff --git a/Disco.Models/BI/Interop/Community/UpdateResponse.cs b/Disco.Models/BI/Interop/Community/UpdateResponse.cs deleted file mode 100644 index 1ebefc41..00000000 --- a/Disco.Models/BI/Interop/Community/UpdateResponse.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Disco.Models.BI.Interop.Community -{ - public class UpdateResponse - { - public string Version { get; set; } - public DateTime VersionReleasedTimestamp { get; set; } - public string Blurb { get; set; } - public string UrlLink { get; set; } - public DateTime ResponseTimestamp { get; set; } - public bool BetaRelease { get; set; } - - public bool IsUpdatable(Version TestVersion) - { - var updateVersion = System.Version.Parse(this.Version); - return (updateVersion > TestVersion); - } - } -} diff --git a/Disco.Models/Disco.Models.csproj b/Disco.Models/Disco.Models.csproj index 28bb1182..184c084d 100644 --- a/Disco.Models/Disco.Models.csproj +++ b/Disco.Models/Disco.Models.csproj @@ -63,9 +63,6 @@ - - - @@ -112,6 +109,8 @@ + + diff --git a/Disco.Models/Services/Interop/DiscoServices/UpdateRequestV2.cs b/Disco.Models/Services/Interop/DiscoServices/UpdateRequestV2.cs new file mode 100644 index 00000000..f7f31e7d --- /dev/null +++ b/Disco.Models/Services/Interop/DiscoServices/UpdateRequestV2.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; + +namespace Disco.Models.Services.Interop.DiscoServices +{ + public class UpdateRequestV2 + { + public Guid DeploymentId { get; set; } + public DateTime RequestDate { get; set; } + public string VersionCurrent { get; set; } + public bool IsBetaDeployment { get; set; } + + public string OrganisationName { get; set; } + public string BroadbandDoeWanId { get; set; } + + public List Stat_JobCounts { get; set; } + public List Stat_OpenJobCounts { get; set; } + public List Stat_ActiveDeviceModelCounts { get; set; } + public List Stat_DeviceModelCounts { get; set; } + public List Stat_UserCounts { get; set; } + + public List InstalledPlugins { get; set; } + + public List Stat_Jobs { get; set; } + + public class StatisticInt + { + public string K; + public int V; + } + + public class StatisticString + { + public string K; + public string V; + } + + public class StatisticJob + { + /// + /// Job Identifier + /// + public int I { get; set; } + + /// + /// Opened Date + /// + public DateTime OD { get; set; } + + /// + /// Closed Date + /// + public DateTime? CD { get; set; } + + /// + /// Job Type + /// + public string T { get; set; } + + /// + /// Job Sub Types (Semicolon Separated) + /// + public string ST { get; set; } + + /// + /// Deployment-Unique Device Serial Identifier (Device Serial Number anonymized via hashing salted with Deployment Secret) + /// + public string D { get; set; } + + /// + /// Deployment-Unique Job User Identifier (Job User Id anonymized via hashing salted with Deployment Secret) + /// + public string U { get; set; } + + /// + /// Deployment-Unique Job Technician Identifier (Job Technician Id anonymized via hashing salted with Deployment Secret) + /// + public string TI { get; set; } + + /// + /// Device Model + /// + public string DM { get; set; } + + /// + /// External Repairer + /// + public string R { get; set; } + + /// + /// External Repairer Logged + /// + public DateTime? RL { get; set; } + + /// + /// External Repairer Completed + /// + public DateTime? RC { get; set; } + } + } +} diff --git a/Disco.Models/Services/Interop/DiscoServices/UpdateResponseV2.cs b/Disco.Models/Services/Interop/DiscoServices/UpdateResponseV2.cs new file mode 100644 index 00000000..26af8ee7 --- /dev/null +++ b/Disco.Models/Services/Interop/DiscoServices/UpdateResponseV2.cs @@ -0,0 +1,16 @@ +using System; + +namespace Disco.Models.Services.Interop.DiscoServices +{ + public class UpdateResponseV2 + { + public string LatestVersion { get; set; } + + public DateTime ReleasedDate { get; set; } + public string Description { get; set; } + public bool IsBetaRelease { get; set; } + public string UrlLink { get; set; } + + public DateTime UpdateResponseDate { get; set; } + } +} diff --git a/Disco.Services/Disco.Services.csproj b/Disco.Services/Disco.Services.csproj index 1fec0c35..0ae316fe 100644 --- a/Disco.Services/Disco.Services.csproj +++ b/Disco.Services/Disco.Services.csproj @@ -236,6 +236,10 @@ + + + + @@ -364,7 +368,7 @@ - + diff --git a/Disco.Services/Interop/DiscoServices/DiscoServiceHelpers.cs b/Disco.Services/Interop/DiscoServices/DiscoServiceHelpers.cs new file mode 100644 index 00000000..bb5a3863 --- /dev/null +++ b/Disco.Services/Interop/DiscoServices/DiscoServiceHelpers.cs @@ -0,0 +1,21 @@ +using System; + +namespace Disco.Services.Interop.DiscoServices +{ + public static class DiscoServiceHelpers + { + [Obsolete] + public static string CommunityUrl() + { + return "https://discoict.com.au/base/"; + } + + public static string ServicesUrl + { + get + { + return "https://services.discoict.com.au/"; + } + } + } +} \ No newline at end of file diff --git a/Disco.Services/Interop/DiscoServices/UpdateQuery.cs b/Disco.Services/Interop/DiscoServices/UpdateQuery.cs new file mode 100644 index 00000000..bc46c3c8 --- /dev/null +++ b/Disco.Services/Interop/DiscoServices/UpdateQuery.cs @@ -0,0 +1,209 @@ +using Disco.Data.Repository; +using Disco.Models.Repository; +using Disco.Models.Services.Interop.DiscoServices; +using Disco.Services.Tasks; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Security.Cryptography; +using System.Text; + +namespace Disco.Services.Interop.DiscoServices +{ + using StatisticInt = UpdateRequestV2.StatisticInt; + using StatisticJob = UpdateRequestV2.StatisticJob; + using StatisticString = UpdateRequestV2.StatisticString; + + public static class UpdateQuery + { + private static string UpdateUrl() + { + return string.Concat(DiscoServiceHelpers.ServicesUrl, "API/Update/V2"); + } + + public static Version CurrentDiscoVersion() + { + return typeof(UpdateQuery).Assembly.GetName().Version; + } + + public static string CurrentDiscoVersionFormatted() + { + var v = CurrentDiscoVersion(); + return FormatVersion(v); + } + + public static string FormatVersion(Version Version) + { + return string.Format("{0}.{1}.{2:0000}.{3:0000}", Version.Major, Version.Minor, Version.Build, Version.Revision); + } + + public static string HashDeploymentData(DiscoDataContext Database, string Data) + { + if (Data == null) + return null; + + string clearText = Database.DiscoConfiguration.DeploymentSecret + Data; + byte[] clearTextBytes = Encoding.Unicode.GetBytes(clearText); + byte[] hashBytes; + + using (var hashAlgorithm = SHA1.Create()) + { + hashBytes = hashAlgorithm.ComputeHash(clearTextBytes); + } + + return Convert.ToBase64String(hashBytes); + } + + public static UpdateResponseV2 Check(DiscoDataContext Database, bool UseProxy, IScheduledTaskStatus Status) + { + Status.UpdateStatus(10, "Gathering statistics and building update request"); + + var updateRequest = BuildRequest(Database); + var updateRequestJson = JsonConvert.SerializeObject(updateRequest); + + Status.UpdateStatus(40, "Sending statistics and update request"); + + var discoVersion = CurrentDiscoVersionFormatted(); + + HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(UpdateUrl()); + + // Fix for Proxy Servers which don't support KeepAlive + request.KeepAlive = false; + + if (!UseProxy) + request.Proxy = new WebProxy(); + + request.ContentType = "application/json; charset=utf-8; encoding=gzip"; + request.Method = WebRequestMethods.Http.Post; + request.UserAgent = string.Format("Disco/{0} (Update)", discoVersion); + + using (var requestStream = request.GetRequestStream()) + { + using (var compressedStream = new GZipStream(requestStream, CompressionLevel.Optimal)) + { + using (var requestStreamWriter = new StreamWriter(compressedStream, Encoding.UTF8)) + { + requestStreamWriter.Write(updateRequestJson); + requestStreamWriter.Flush(); + } + } + } + + Status.UpdateStatus(50, "Waiting for update response"); + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + { + if (response.StatusCode == HttpStatusCode.OK) + { + Status.UpdateStatus(90, "Reading update response"); + string updateResultJson; + UpdateResponseV2 updateResult; + + using (var responseStream = response.GetResponseStream()) + { + using (var responseReader = new StreamReader(responseStream)) + { + updateResultJson = responseReader.ReadToEnd(); + } + } + + updateResult = JsonConvert.DeserializeObject(updateResultJson); + + Database.DiscoConfiguration.UpdateLastCheckResponse = updateResult; + Database.SaveChanges(); + + Status.SetFinishedMessage(string.Format("The update server reported Version {0} is the latest.", updateResult.LatestVersion)); + + return updateResult; + } + else + { + Status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", response.StatusCode, response.StatusDescription))); + return null; + } + } + } + + private static UpdateRequestV2 BuildRequest(DiscoDataContext Database) + { + var lastUpdate = Database.DiscoConfiguration.UpdateLastCheckResponse; + var m = new UpdateRequestV2(); + + m.DeploymentId = Guid.Parse(Database.DiscoConfiguration.DeploymentId); + m.RequestDate = DateTime.Now; + m.VersionCurrent = CurrentDiscoVersionFormatted(); + m.IsBetaDeployment = Database.DiscoConfiguration.UpdateBetaDeployment; + + m.OrganisationName = Database.DiscoConfiguration.OrganisationName; + + var whoAmIResponse = VicEduDept.VicSmart.WhoAmI(); + if (whoAmIResponse != null && !string.IsNullOrWhiteSpace(whoAmIResponse.Item1)) + m.BroadbandDoeWanId = whoAmIResponse.Item1; + + m.Stat_JobCounts = Database.Jobs.GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList(); + m.Stat_OpenJobCounts = Database.Jobs.Where(j => j.ClosedDate == null).GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList(); + m.Stat_DeviceModelCounts = Database.DeviceModels.Select(dm => new StatisticInt() { K = dm.Manufacturer + ";" + dm.Model, V = dm.Devices.Count(d => d.DecommissionedDate == null) }).ToList(); + var activeThreshold = DateTime.Now.AddDays(-60); + m.Stat_ActiveDeviceModelCounts = Database.DeviceModels.Select(dm => new StatisticInt() { K = dm.Manufacturer + ";" + dm.Model, V = dm.Devices.Count(d => d.DecommissionedDate == null && (d.LastNetworkLogonDate == null || d.LastNetworkLogonDate > activeThreshold)) }).ToList(); + m.Stat_UserCounts = new List() { + new StatisticInt() { K = "All", V = Database.Users.Count() }, + new StatisticInt() { K = "Assigned Current", V = Database.Users.Where(u => u.DeviceUserAssignments.Any(dua => !dua.UnassignedDate.HasValue)).Count() }, + new StatisticInt() { K = "Assigned Ever", V = Database.Users.Where(u => u.DeviceUserAssignments.Any()).Count() }, + new StatisticInt() { K = "Job Technicians", V = Database.Jobs.Select(j => j.OpenedTechUserId).Distinct().ToList().Concat(Database.Jobs.Select(j => j.ClosedTechUserId).Distinct().ToList()).Distinct().Count() }, + new StatisticInt() { K = "Job Users", V = Database.Jobs.Where(j => j.UserId != null).Select(j => j.UserId).Distinct().Count() } + }; + + IQueryable jobs; + if (lastUpdate == null) + jobs = Database.Jobs; + else + { + var lastUpdateDate = lastUpdate.UpdateResponseDate.Date; + jobs = Database.Jobs.Where(j => j.OpenedDate >= lastUpdateDate || (j.ClosedDate.HasValue && j.ClosedDate.Value >= lastUpdateDate)); + } + + var reportedJobs = jobs.Select(j => new + { + Id = j.Id, + OpenedDate = j.OpenedDate, + ClosedDate = j.ClosedDate, + JobType = j.JobTypeId, + JobSubTypes = j.JobSubTypes.Select(jst => jst.Id), + DeviceModelManufacturer = j.Device.DeviceModel.Manufacturer, + DeviceModelModel = j.Device.DeviceModel.Model, + DeviceSerialNumber = j.DeviceSerialNumber, + UserId = j.UserId, + JobTechnicianId = j.OpenedTechUserId, + WarrantyRepairer = j.JobMetaWarranty.ExternalName, + WarrantyRepairerLoggedDate = j.JobMetaWarranty.ExternalLoggedDate, + WarrantyRepairerCompletedDate = j.JobMetaWarranty.ExternalCompletedDate, + Repairer = j.JobMetaNonWarranty.RepairerName, + RepairerLoggedDate = j.JobMetaNonWarranty.RepairerLoggedDate, + RepairerCompletedDate = j.JobMetaNonWarranty.RepairerCompletedDate, + }).ToList(); + + m.Stat_Jobs = reportedJobs.Select(j => new StatisticJob() + { + I = j.Id, + OD = j.OpenedDate, + CD = j.ClosedDate, + T = j.JobType, + ST = j.JobSubTypes == null ? null : string.Join(";", j.JobSubTypes), + D = HashDeploymentData(Database, j.DeviceSerialNumber), + U = HashDeploymentData(Database, j.UserId), + TI = HashDeploymentData(Database, j.JobTechnicianId), + DM = string.Format("{0};{1}", j.DeviceModelManufacturer, j.DeviceModelModel), + R = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairer : j.Repairer, + RL = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairerLoggedDate : j.RepairerLoggedDate, + RC = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairerCompletedDate : j.RepairerCompletedDate + }).ToList(); + + m.InstalledPlugins = Disco.Services.Plugins.Plugins.GetPlugins().Select(manifest => new StatisticString() { K = manifest.Id, V = manifest.VersionFormatted }).ToList(); + + return m; + } + } +} diff --git a/Disco.BI/BI/Interop/Community/UpdateCheckTask.cs b/Disco.Services/Interop/DiscoServices/UpdateQueryTask.cs similarity index 65% rename from Disco.BI/BI/Interop/Community/UpdateCheckTask.cs rename to Disco.Services/Interop/DiscoServices/UpdateQueryTask.cs index c8b0ab95..43140cd8 100644 --- a/Disco.BI/BI/Interop/Community/UpdateCheckTask.cs +++ b/Disco.Services/Interop/DiscoServices/UpdateQueryTask.cs @@ -4,52 +4,15 @@ using Quartz; using System; using System.Linq; -namespace Disco.BI.Interop.Community +namespace Disco.Services.Interop.DiscoServices { - public class UpdateCheckTask : ScheduledTask + public class UpdateQueryTask : ScheduledTask { - public override string TaskName { get { return "Disco Community - Check for Update"; } } + public override string TaskName { get { return "Disco ICT - Check for Update"; } } public override bool SingleInstanceTask { get { return true; } } public override bool CancelInitiallySupported { get { return false; } } - public static ScheduledTaskStatus ScheduleNow() - { - - var runningTasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).Where(ts => ts.IsRunning).ToList(); - if (runningTasks.Count > 0) - return runningTasks.First(); - else - { - var t = new UpdateCheckTask(); - return t.ScheduleTask(); - } - } - public static ScheduledTaskStatus RunningStatus - { - get - { - return ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).Where(ts => ts.IsRunning).FirstOrDefault(); - } - } - public static DateTime? NextScheduled - { - get - { - var runningTasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).ToList(); - DateTime timestamp = DateTime.MaxValue; - foreach (var t in runningTasks) - { - if (t.NextScheduledTimestamp != null && t.NextScheduledTimestamp.Value < timestamp) - timestamp = t.NextScheduledTimestamp.Value; - } - if (timestamp == DateTime.MaxValue) - return null; - else - return timestamp; - } - } - - public override void InitalizeScheduledTask(Data.Repository.DiscoDataContext Database) + public override void InitalizeScheduledTask(DiscoDataContext Database) { // Random time between midday and midnight. var rnd = new Random(); @@ -69,15 +32,55 @@ namespace Disco.BI.Interop.Community { try { - UpdateCheck.Check(database, true, this.Status); + UpdateQuery.Check(database, true, this.Status); } catch (Exception ex) { ScheduledTasksLog.LogScheduledTaskException(this.Status.TaskName, this.Status.SessionId, this.Status.TaskType, ex); + // Could be proxy error - try again without proxy: - UpdateCheck.Check(database, false, this.Status); + UpdateQuery.Check(database, false, this.Status); } } } + + public static ScheduledTaskStatus ScheduleNow() + { + var taskStatus = RunningStatus; + if (taskStatus != null) + return taskStatus; + else + { + var task = new UpdateQueryTask(); + return task.ScheduleTask(); + } + } + + public static DateTime? NextScheduled + { + get + { + DateTime timestamp = DateTime.MaxValue; + var tasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateQueryTask)).ToList(); + + foreach (var t in tasks) + if (t.NextScheduledTimestamp != null && t.NextScheduledTimestamp.Value < timestamp) + timestamp = t.NextScheduledTimestamp.Value; + + if (timestamp != DateTime.MaxValue) + return timestamp; + else + return null; + } + } + + public static ScheduledTaskStatus RunningStatus + { + get + { + return ScheduledTasks.GetTaskStatuses(typeof(UpdateQueryTask)).Where(ts => ts.IsRunning).FirstOrDefault(); + } + } + } -} +} \ No newline at end of file diff --git a/Disco.Services/Interop/VicEduDept/VicSmart.cs b/Disco.Services/Interop/VicEduDept/VicSmart.cs new file mode 100644 index 00000000..761ca429 --- /dev/null +++ b/Disco.Services/Interop/VicEduDept/VicSmart.cs @@ -0,0 +1,88 @@ +using Disco.Services.Interop.DiscoServices; +using System; +using System.IO; +using System.Net; +using System.Xml.Linq; + +namespace Disco.Services.Interop.VicEduDept +{ + public class VicSmart + { + + /// + /// Queries DoE VicSmart Service to detect the current site. + /// + /// A Tuple where Item1 is the Site Number and Item2 is the Site Name + public static Tuple WhoAmI() + { + // DnsQuery for broadband.doe.wan + IPHostEntry doeWanDnsEntry; + try + { + doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan"); + } + catch (Exception) + { return null; } // Fail on error + + // Try using IPSearch feature + XDocument doeWanIPSearchResult = TryIPWhoAmISearch(false); + if (doeWanIPSearchResult == null) + doeWanIPSearchResult = TryIPWhoAmISearch(true); + + if (doeWanIPSearchResult == null) + return null; + + try + { + var site = doeWanIPSearchResult.Element("resultset").Element("site"); + var siteNumber = site.Element("number").Value.ToLower(); + var siteName = site.Element("name").Value.ToLower(); + + return Tuple.Create(siteNumber, siteName); + } + catch (Exception) + { return null; } // Fail on error + } + + private static XDocument TryIPWhoAmISearch(bool useProxy) + { + try + { + var DiscoBIVersion = UpdateQuery.CurrentDiscoVersionFormatted(); + + HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php"); + + // Fix for Proxy Servers which don't support KeepAlive + wReq.KeepAlive = false; + + if (!useProxy) + wReq.Proxy = new WebProxy(); // Empty Proxy Config + wReq.Method = WebRequestMethods.Http.Post; + wReq.ContentType = "application/x-www-form-urlencoded"; + wReq.UserAgent = string.Format("Disco/{0}", DiscoBIVersion); + using (var wrStream = wReq.GetRequestStream()) + { + using (var wrStreamWriter = new StreamWriter(wrStream)) + { + wrStreamWriter.Write("mode=whoami"); + } + } + using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse()) + { + if (wRes.StatusCode == HttpStatusCode.OK) + { + using (var wResStream = wRes.GetResponseStream()) + { + return XDocument.Load(wResStream); + } + } + else + return null; + } + } + catch (Exception) + { return null; } // Fail on error + } + + } +} \ No newline at end of file diff --git a/Disco.Services/Plugins/CommunityInterop/PluginLibraryUpdateTask.cs b/Disco.Services/Plugins/CommunityInterop/PluginLibraryUpdateTask.cs index 756b69a9..a86d0558 100644 --- a/Disco.Services/Plugins/CommunityInterop/PluginLibraryUpdateTask.cs +++ b/Disco.Services/Plugins/CommunityInterop/PluginLibraryUpdateTask.cs @@ -13,6 +13,7 @@ using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Quartz; +using Disco.Services.Interop.DiscoServices; namespace Disco.Services.Plugins.CommunityInterop { @@ -173,11 +174,11 @@ namespace Disco.Services.Plugins.CommunityInterop private static string PluginLibraryUpdateUrl() { - return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/V1"); + return string.Concat(DiscoServiceHelpers.CommunityUrl(), "DiscoPluginLibrary/V1"); } private static string PluginLibraryCompatibilityUrl() { - return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/CompatibilityV1"); + return string.Concat(DiscoServiceHelpers.CommunityUrl(), "DiscoPluginLibrary/CompatibilityV1"); } public static ScheduledTaskStatus ScheduleNow() diff --git a/Disco.Services/Tasks/ScheduledTasks.cs b/Disco.Services/Tasks/ScheduledTasks.cs index 3c39f157..076ecf1b 100644 --- a/Disco.Services/Tasks/ScheduledTasks.cs +++ b/Disco.Services/Tasks/ScheduledTasks.cs @@ -35,7 +35,9 @@ namespace Disco.Services.Tasks var scheduledTasksHostAssemblyName = typeof(ScheduledTask).Assembly.GetName().Name; var scheduledTaskTypes = (from a in appDomain.GetAssemblies() - where !a.GlobalAssemblyCache && !a.IsDynamic && a.GetReferencedAssemblies().Any(ra => ra.Name == scheduledTasksHostAssemblyName) + where !a.GlobalAssemblyCache && + !a.IsDynamic && + (a.GetName().Name == scheduledTasksHostAssemblyName || a.GetReferencedAssemblies().Any(ra => ra.Name == scheduledTasksHostAssemblyName)) from type in a.GetTypes() where typeof(ScheduledTask).IsAssignableFrom(type) && !type.IsAbstract select type); diff --git a/Disco.Web/App_Start/AppConfig.cs b/Disco.Web/App_Start/AppConfig.cs index 126c274a..a9b776b5 100644 --- a/Disco.Web/App_Start/AppConfig.cs +++ b/Disco.Web/App_Start/AppConfig.cs @@ -1,4 +1,5 @@ using Disco.Data.Repository; +using Disco.Services.Interop.DiscoServices; using System; using System.Linq; using System.Web; @@ -70,10 +71,10 @@ namespace Disco.Web Disco.Services.Tasks.ScheduledTasks.InitalizeScheduledTasks(Database, DiscoApplication.SchedulerFactory, true); // Schedule Immediate Check for Update (if never updated, or last updated over 2 days ago) - if (Database.DiscoConfiguration.UpdateLastCheck == null || - Database.DiscoConfiguration.UpdateLastCheck.ResponseTimestamp < DateTime.Now.AddDays(-2)) + if (Database.DiscoConfiguration.UpdateLastCheckResponse == null || + Database.DiscoConfiguration.UpdateLastCheckResponse.UpdateResponseDate < DateTime.Now.AddDays(-2)) { - Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow(); + UpdateQueryTask.ScheduleNow(); } // Setup Attachment Monitor diff --git a/Disco.Web/Areas/API/Controllers/SystemController.cs b/Disco.Web/Areas/API/Controllers/SystemController.cs index 8e9eecbe..45a7b88c 100644 --- a/Disco.Web/Areas/API/Controllers/SystemController.cs +++ b/Disco.Web/Areas/API/Controllers/SystemController.cs @@ -2,6 +2,7 @@ using Disco.Data.Configuration; using Disco.Services.Authorization; using Disco.Services.Interop.ActiveDirectory; +using Disco.Services.Interop.DiscoServices; using Disco.Services.Web; using System; using System.Collections.Generic; @@ -66,7 +67,7 @@ namespace Disco.Web.Areas.API.Controllers [DiscoAuthorize(Claims.Config.System.Show)] public virtual ActionResult UpdateCheck() { - var ts = Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow(); + var ts = Disco.Services.Interop.DiscoServices.UpdateQueryTask.ScheduleNow(); ts.SetFinishedUrl(Url.Action(MVC.Config.SystemConfig.Index())); return RedirectToAction(MVC.Config.Logging.TaskStatus(ts.SessionId)); } @@ -354,10 +355,10 @@ namespace Disco.Web.Areas.API.Controllers Database.SaveChanges(); // Try and check for updates if needed - After Proxy Changed - if (Database.DiscoConfiguration.UpdateLastCheck == null - || Database.DiscoConfiguration.UpdateLastCheck.ResponseTimestamp < DateTime.Now.AddDays(-1)) + if (Database.DiscoConfiguration.UpdateLastCheckResponse == null + || Database.DiscoConfiguration.UpdateLastCheckResponse.UpdateResponseDate < DateTime.Now.AddDays(-1)) { - Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow(); + UpdateQueryTask.ScheduleNow(); } if (redirect) @@ -369,4 +370,4 @@ namespace Disco.Web.Areas.API.Controllers #endregion } -} +} \ No newline at end of file diff --git a/Disco.Web/Areas/Config/Controllers/ConfigController.cs b/Disco.Web/Areas/Config/Controllers/ConfigController.cs index 48d9493c..e8123769 100644 --- a/Disco.Web/Areas/Config/Controllers/ConfigController.cs +++ b/Disco.Web/Areas/Config/Controllers/ConfigController.cs @@ -15,7 +15,7 @@ namespace Disco.Web.Areas.Config.Controllers var m = new Models.Config.IndexModel() { - UpdateResponse = Database.DiscoConfiguration.UpdateLastCheck + UpdateResponse = Database.DiscoConfiguration.UpdateLastCheckResponse }; return View(m); diff --git a/Disco.Web/Areas/Config/Models/Config/IndexModel.cs b/Disco.Web/Areas/Config/Models/Config/IndexModel.cs index f47a32bf..22c719f9 100644 --- a/Disco.Web/Areas/Config/Models/Config/IndexModel.cs +++ b/Disco.Web/Areas/Config/Models/Config/IndexModel.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Disco.Models.BI.Interop.Community; +using Disco.Models.Services.Interop.DiscoServices; +using System; namespace Disco.Web.Areas.Config.Models.Config { @@ -14,13 +11,14 @@ namespace Disco.Web.Areas.Config.Models.Config { if (UpdateResponse != null) { - var updateVersion = Version.Parse(UpdateResponse.Version); + var updateVersion = Version.Parse(UpdateResponse.LatestVersion); return (updateVersion > typeof(DiscoApplication).Assembly.GetName().Version); } return false; } } - public UpdateResponse UpdateResponse { get; set; } + + public UpdateResponseV2 UpdateResponse { get; set; } } } \ No newline at end of file diff --git a/Disco.Web/Areas/Config/Models/SystemConfig/IndexModel.cs b/Disco.Web/Areas/Config/Models/SystemConfig/IndexModel.cs index 1a450f42..6552d5ce 100644 --- a/Disco.Web/Areas/Config/Models/SystemConfig/IndexModel.cs +++ b/Disco.Web/Areas/Config/Models/SystemConfig/IndexModel.cs @@ -1,15 +1,13 @@ -using System; +using Disco.Data.Configuration; +using Disco.Models.Services.Interop.DiscoServices; +using Disco.Services.Interop.ActiveDirectory; +using Disco.Services.Interop.DiscoServices; +using Disco.Services.Tasks; +using System; using System.Collections.Generic; -using System.Linq; -using System.Web; -using Disco.Data.Configuration; using System.ComponentModel.DataAnnotations; using System.Data.SqlClient; -using Disco.Data.Repository; -using Disco.Models.BI.Interop.Community; -using Disco.Services.Tasks; -using System.DirectoryServices.ActiveDirectory; -using Disco.Services.Interop.ActiveDirectory; +using System.Linq; namespace Disco.Web.Areas.Config.Models.SystemConfig { @@ -98,7 +96,8 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig public ScheduledTaskStatus UpdateRunningStatus { get; set; } public DateTime? UpdateNextScheduled { get; set; } - public UpdateResponse UpdateLatestResponse { get; set; } + public UpdateResponseV2 UpdateLatestResponse { get; set; } + public bool UpdateAvailable { get; set; } public bool UpdateBetaDeployment { get; set; } public static IndexModel FromConfiguration(SystemConfiguration config) @@ -111,12 +110,15 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig ProxyPort = config.ProxyPort, ProxyUsername = config.ProxyUsername, ProxyPassword = config.ProxyPassword, - UpdateLatestResponse = config.UpdateLastCheck, - UpdateRunningStatus = Disco.BI.Interop.Community.UpdateCheckTask.RunningStatus, - UpdateNextScheduled = Disco.BI.Interop.Community.UpdateCheckTask.NextScheduled, + UpdateLatestResponse = config.UpdateLastCheckResponse, + UpdateRunningStatus = UpdateQueryTask.RunningStatus, + UpdateNextScheduled = UpdateQueryTask.NextScheduled, UpdateBetaDeployment = config.UpdateBetaDeployment }; + // Is an update available? + m.UpdateAvailable = m.UpdateLatestResponse != null && (Version.Parse(m.UpdateLatestResponse.LatestVersion) > m.DiscoVersion); + // AD m.ADDomains = ActiveDirectory.Context.Domains.ToList(); m.ADPrimaryDomain = ActiveDirectory.Context.PrimaryDomain; diff --git a/Disco.Web/Areas/Config/Views/Config/Index.cshtml b/Disco.Web/Areas/Config/Views/Config/Index.cshtml index 14ad8f23..c86db2d6 100644 --- a/Disco.Web/Areas/Config/Views/Config/Index.cshtml +++ b/Disco.Web/Areas/Config/Views/Config/Index.cshtml @@ -145,7 +145,7 @@ diff --git a/Disco.Web/Areas/Config/Views/SystemConfig/Index.generated.cs b/Disco.Web/Areas/Config/Views/SystemConfig/Index.generated.cs index 00598dd2..0fd4c4fa 100644 --- a/Disco.Web/Areas/Config/Views/SystemConfig/Index.generated.cs +++ b/Disco.Web/Areas/Config/Views/SystemConfig/Index.generated.cs @@ -269,7 +269,7 @@ WriteLiteral(">Last Run:\r\n \r\n \r\n #line 88 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" - Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ResponseTimestamp)); + Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.UpdateResponseDate.ToLocalTime())); #line default @@ -278,7 +278,7 @@ WriteLiteral("\r\n \r\n \r\n"); #line 91 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" - if (Model.UpdateLatestResponse.IsUpdatable(typeof(DiscoApplication).Assembly.GetName().Version)) + if (Model.UpdateAvailable) { @@ -297,7 +297,7 @@ WriteLiteral("> Version "); #line 98 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" - Write(Model.UpdateLatestResponse.Version); + Write(Model.UpdateLatestResponse.LatestVersion); #line default @@ -310,7 +310,7 @@ WriteLiteral(">\r\n [Released "); #line 101 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" - Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.VersionReleasedTimestamp)); + Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ReleasedDate)); #line default @@ -323,21 +323,21 @@ WriteLiteral(">"); #line 103 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" - Write(new HtmlString(Model.UpdateLatestResponse.Blurb)); + Write(new HtmlString(Model.UpdateLatestResponse.Description)); #line default #line hidden WriteLiteral("\r\n (Model.UpdateLatestResponse.UrlLink +, Tuple.Create(Tuple.Create("", 3948), Tuple.Create(Model.UpdateLatestResponse.UrlLink #line default #line hidden -, 4003), false) +, 3948), false) ); WriteLiteral(" target=\"_blank\""); @@ -704,18 +704,18 @@ WriteLiteral(" (server.AvailableWhen.Value.ToLongTimeString() + , Tuple.Create(Tuple.Create(" ", 8200), Tuple.Create(server.AvailableWhen.Value.ToLongTimeString() #line default #line hidden -, 8256), false) +, 8201), false) ); WriteLiteral(">\r\n"); @@ -1639,35 +1639,29 @@ WriteLiteral("\r\n - - - - -"); +WriteLiteral("\';\r\n var data = {\r\n " + +" ProxyAddress: $(\'#ProxyAddress\').val(),\r\n " + +" ProxyPort: $(\'#ProxyPort\').val(),\r\n ProxyUs" + +"ername: $(\'#ProxyUsername\').val(),\r\n ProxyPas" + +"sword: $(\'#ProxyPassword\').val()\r\n }\r\n " + +" var ajaxLoading = button.next(\'.ajaxLoading\').first().show(" + +");\r\n\r\n $.ajax({\r\n " + +" type: \'POST\',\r\n dataType: \'json\',\r\n " + +" url: url,\r\n dat" + +"a: data,\r\n success: function (response, resul" + +"t) {\r\n if (result != \'success\' || respons" + +"e != \'OK\') {\r\n alert(\'Unable to chang" + +"e property \"\' + UpdatePropertyName + \'\":\\n\' + response);\r\n " + +" ajaxLoading.hide();\r\n " + +" } else {\r\n ajaxLoading.hide().next" + +"(\'.ajaxOk\').show().delay(\'fast\').fadeOut(\'slow\');\r\n " + +" }\r\n }\r\n " + +" });\r\n });\r\n });\r\n " + +" \r\n \r\n \r\n \r\n \r\n"); - #line 555 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 560 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" } } else @@ -1692,7 +1686,7 @@ WriteLiteral(">Address:\r\n \r\n \r\n"); WriteLiteral(" "); - #line 566 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 571 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" Write(Html.DisplayFor(m => m.ProxyAddress)); @@ -1708,7 +1702,7 @@ WriteLiteral(">Port:\r\n \r\n \r\n"); WriteLiteral(" "); - #line 573 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 578 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" Write(Html.DisplayFor(m => m.ProxyPort)); @@ -1724,7 +1718,7 @@ WriteLiteral(">Username:\r\n \r\n \r\n"); WriteLiteral(" "); - #line 580 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 585 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" Write(Html.DisplayFor(m => m.ProxyUsername)); @@ -1739,7 +1733,7 @@ WriteLiteral(">Password:\r\n \r\n ******* "\r\n \r\n \r\n \r\n"); - #line 591 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 596 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" } @@ -1754,7 +1748,7 @@ WriteLiteral(">\r\n"); WriteLiteral(" "); - #line 593 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" + #line 598 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml" Write(Html.ActionLinkButton("Update Device Last Network Logons", MVC.API.System.UpdateLastNetworkLogonDates())); diff --git a/Disco.Web/Global.asax.cs b/Disco.Web/Global.asax.cs index 0da6da4f..b3d84258 100644 --- a/Disco.Web/Global.asax.cs +++ b/Disco.Web/Global.asax.cs @@ -1,12 +1,10 @@ using Disco.Data.Repository; -using Disco.Services.Authorization; -using Disco.Services.Users; +using Disco.Services.Interop.DiscoServices; using Disco.Services.Web; using System; using System.Configuration; using System.Diagnostics; using System.Net; -using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing; @@ -44,13 +42,13 @@ namespace Disco.Web { // Check for Post-Update var previousVersion = database.DiscoConfiguration.InstalledDatabaseVersion; - bool isVersionUpdate = previousVersion != Disco.BI.Interop.Community.UpdateCheck.CurrentDiscoVersion(); + bool isVersionUpdate = previousVersion != UpdateQuery.CurrentDiscoVersion(); bool ignoreVersionUpdate = false; if (isVersionUpdate) { // Update Database with New Version - database.DiscoConfiguration.InstalledDatabaseVersion = Disco.BI.Interop.Community.UpdateCheck.CurrentDiscoVersion(); + database.DiscoConfiguration.InstalledDatabaseVersion = UpdateQuery.CurrentDiscoVersion(); database.SaveChanges(); // Check if configured to Ignore Plugin Updates (Mainly for Dev environment) diff --git a/Disco.Web/Models/InitialConfig/WelcomeModel.cs b/Disco.Web/Models/InitialConfig/WelcomeModel.cs index 410b0128..76fb8e8d 100644 --- a/Disco.Web/Models/InitialConfig/WelcomeModel.cs +++ b/Disco.Web/Models/InitialConfig/WelcomeModel.cs @@ -1,18 +1,12 @@ -using System; -using System.Collections.Generic; +using Disco.Services.Interop.VicEduDept; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Web; -using System.Net; -using System.Xml.Linq; -using System.IO; using System.Globalization; namespace Disco.Web.Models.InitialConfig { public class WelcomeModel { - [Required(ErrorMessage="The Organisation Name is required.")] + [Required(ErrorMessage = "The Organisation Name is required.")] public string OrganisationName { get; set; } @@ -25,69 +19,17 @@ namespace Disco.Web.Models.InitialConfig return true; } - // DnsQuery for broadband.doe.wan - IPHostEntry doeWanDnsEntry; - try + var whoAmIResult = VicSmart.WhoAmI(); + + if (whoAmIResult != null && !string.IsNullOrWhiteSpace(whoAmIResult.Item2)) { - doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan"); - } - catch (Exception) - { return false; } // Fail on error - - // Try using IPSearch feature - XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(true); - if (doeWanIPSearchResult == null) - doeWanIPSearchResult = TryDownloadDoeIPSearch(false); - - if (doeWanIPSearchResult == null) - return false; - - try - { - var siteName = doeWanIPSearchResult.Element("resultset").Element("site").Element("name").Value.ToLower(); - this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(siteName); + this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(whoAmIResult.Item2); _OrganisationNameCache = this.OrganisationName; + return true; } - catch (Exception) - { return false; } // Fail on error - } - private XDocument TryDownloadDoeIPSearch(bool useProxy) - { - try - { - HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php"); - // Added: 2013-02-08 G# - // Fix for Proxy Servers which dont support KeepAlive - wReq.KeepAlive = false; - // End Added: 2013-02-08 G# - if (!useProxy) - wReq.Proxy = new WebProxy(); // Empty Proxy Config - wReq.Method = WebRequestMethods.Http.Post; - wReq.ContentType = "application/x-www-form-urlencoded"; - wReq.UserAgent = string.Format("Disco/{0}", DiscoApplication.Version); - using (var wrStream = wReq.GetRequestStream()) - { - using (var wrStreamWriter = new StreamWriter(wrStream)) - { - wrStreamWriter.Write("mode=whoami"); - } - } - using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse()) - { - if (wRes.StatusCode == HttpStatusCode.OK) - { - using (var wResStream = wRes.GetResponseStream()) - { - return XDocument.Load(wResStream); - } - } - else - return null; - } - } - catch (Exception) - { return null; } // Fail on error + + return false; } }