diff --git a/WebHandler/ADCompareWebHandler.cs b/WebHandler/ADCompareWebHandler.cs index b69596f..7a11cbc 100644 --- a/WebHandler/ADCompareWebHandler.cs +++ b/WebHandler/ADCompareWebHandler.cs @@ -1,6 +1,5 @@ using Disco.Plugins.ADCompare.Features; using Disco.Services.Plugins; -using Newtonsoft.Json; using System; using System.Linq; using System.Text; @@ -19,8 +18,8 @@ namespace Disco.Plugins.ADCompare.WebHandler case "": case "index": return Index(); - case "compare": - return Compare(); + case "run": + return Run(); case "export": return ExportCsv(); default: @@ -30,24 +29,14 @@ namespace Disco.Plugins.ADCompare.WebHandler private ActionResult Index() { - return new ContentResult - { - Content = BuildDashboardHtml(), - ContentType = "text/html", - ContentEncoding = Encoding.UTF8 - }; + return HtmlResult(BuildPage(null)); } - private ActionResult Compare() + private ActionResult Run() { var service = new DeviceCompareService(Database); var summary = service.CompareAllDevices(); - return new ContentResult - { - Content = JsonConvert.SerializeObject(summary, Formatting.Indented), - ContentType = "application/json", - ContentEncoding = Encoding.UTF8 - }; + return HtmlResult(BuildPage(summary)); } private ActionResult ExportCsv() @@ -59,14 +48,13 @@ namespace Disco.Plugins.ADCompare.WebHandler foreach (var r in summary.Results.Where(r => !r.IsMatch)) { sb.AppendLine(string.Join(",", - CsvEscape(r.SerialNumber), CsvEscape(r.ComputerName), - CsvEscape(r.DiscoAssignedUserId), CsvEscape(r.DiscoAssignedUserDisplayName), - CsvEscape(r.ADManagedByUserId), CsvEscape(r.ADManagedByDisplayName), - r.IsMatch.ToString(), CsvEscape(r.MismatchReason))); + CsvEsc(r.SerialNumber), CsvEsc(r.ComputerName), + CsvEsc(r.DiscoAssignedUserId), CsvEsc(r.DiscoAssignedUserDisplayName), + CsvEsc(r.ADManagedByUserId), CsvEsc(r.ADManagedByDisplayName), + r.IsMatch.ToString(), CsvEsc(r.MismatchReason))); } var fileName = "AD_ManagedBy_Compare_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv"; - HostController.Response.Headers.Add("Content-Disposition", - "attachment; filename=\"" + fileName + "\""); + HostController.Response.Headers.Add("Content-Disposition", "attachment; filename=\"" + fileName + "\""); return new ContentResult { Content = sb.ToString(), @@ -75,75 +63,134 @@ namespace Disco.Plugins.ADCompare.WebHandler }; } - private string CsvEscape(string v) + private ActionResult HtmlResult(string html) + { + return new ContentResult + { + Content = html, + ContentType = "text/html", + ContentEncoding = Encoding.UTF8 + }; + } + + private string CsvEsc(string v) { if (v == null) v = ""; return "\"" + v.Replace("\"", "\"\"") + "\""; } - private string BuildDashboardHtml() + private string H(string v) { - // Build the plugin URL manually (T4MVC's MVC.API class isn't available outside the Disco solution) - var pluginUrl = "/Plugin/" + HttpUtility.UrlEncode(Manifest.Id); + if (string.IsNullOrEmpty(v)) return ""; + return HttpUtility.HtmlEncode(v); + } - return @" -
Compares the AD computer Managed By field against the Disco Assigned User.
-Compares the AD computer Managed By field against the Disco Assigned User.
"); + + sb.Append("| Status | Serial Number | Computer Name | "); + sb.Append("Disco Assigned User | AD Managed By | Reason | "); + sb.Append("
|---|---|---|---|---|---|
| " + badge + " | "); + sb.Append("" + H(r.SerialNumber) + " | "); + sb.Append("" + H(r.ComputerName) + " | "); + sb.Append("" + discoUser + " | "); + sb.Append("" + adUser + " | "); + sb.Append("" + H(r.MismatchReason) + " | "); + sb.Append("