protected override void OnLoad(EventArgs e) { if (!SecurityHelper.CanRunApplication("PowerShell/PowerShell Console") || ServiceAuthorizationManager.TerminateUnauthorizedRequest(WebServiceSettings.ServiceClient, Context.User?.Name)) { PowerShellLog.Error($"User {Context.User?.Name} attempt to access PowerShell Console - denied."); return; } base.OnLoad(e); UpdateWarning(); Settings = ApplicationSettings.GetInstance(ApplicationNames.Context, false); HttpContext.Current.Response.AddHeader("X-UA-Compatible", "IE=edge"); var settings = ApplicationSettings.GetInstance(ApplicationNames.Console, false); if (!Context.ClientPage.IsEvent) { Options.Text = @"<script type='text/javascript'>" + @"$ise(function() { cognifide.powershell.setOptions({ initialPoll: " + WebServiceSettings.InitialPollMillis + @", maxPoll: " + WebServiceSettings.MaxmimumPollMillis + @", fontSize: " + settings.FontSize + $", fontFamily: '{settings.FontFamilyStyle}' }});}});</script>" + @"<style>#terminal {" + $"color: {OutputLine.ProcessHtmlColor(settings.ForegroundColor)};" + $"background-color: {OutputLine.ProcessHtmlColor(settings.BackgroundColor)};" + $"font-family: inherit;" + "}</style>"; } SheerResponse.SetDialogValue("ok"); }
protected override void OnLoad(EventArgs e) { if (!SecurityHelper.CanRunApplication("PowerShell/PowerShellIse") || ServiceAuthorizationManager.TerminateUnauthorizedRequest(WebServiceSettings.ServiceClient, Context.User.Name)) { PowerShellLog.Error($"User {Context.User?.Name} attempt to access PowerShell ISE - denied."); return; } base.OnLoad(e); if (Monitor == null) { if (!Context.ClientPage.IsEvent) { Monitor = new SpeJobMonitor { ID = "Monitor" }; Context.ClientPage.Controls.Add(Monitor); } else { Monitor = (SpeJobMonitor)Context.ClientPage.FindControl("Monitor"); } } Monitor.JobFinished += MonitorOnJobFinished; if (Context.ClientPage.IsEvent) { return; } var settings = ApplicationSettings.GetInstance(ApplicationNames.ISE); if (settings.SaveLastScript) { Editor.Value = settings.LastScript; } var itemId = WebUtil.GetQueryString("id"); var itemDb = WebUtil.GetQueryString("db"); if (itemId.Length > 0) { ScriptItemId = itemId; ScriptItemDb = itemDb; LoadItem(itemDb, itemId); } ContextItemDb = Context.ContentDatabase.Name; var contextItem = Context.ContentDatabase.GetItem(Context.Site.ContentStartPath) ?? UIUtil.GetHomeItem(Context.User); ContextItemId = contextItem?.ID.ToString() ?? String.Empty; CurrentSessionId = DefaultSessionName; CurrentUser = DefaultUser; CurrentLanguage = DefaultLanguage; ParentFrameName = WebUtil.GetQueryString("pfn"); UpdateRibbon(); }
protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); if (ServiceAuthorizationManager.TerminateUnauthorizedRequest(WebServiceSettings.ServiceExecution, Context.User?.Name)) { PowerShellLog.Error($"User {Context.User?.Name} attempt to access PowerShell Download File dialog - denied."); return; } Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } UrlHandle handle = null; if (!TypeResolver.Resolve <IUrlHandleWrapper>().TryGetHandle(out handle)) { FileNameLabel.Text = "Invalid dialog invocation."; SizeLabel.Visible = false; PathPrefix.Visible = false; SizePrefix.Visible = false; OK.Visible = false; DownloadImage.Visible = false; ErrorImage.Visible = true; return; } FileName = handle["fn"]; ItemUri = handle["uri"]; ItemDb = handle["db"]; bool showFullPath; if (!bool.TryParse(handle["fp"], out showFullPath)) { showFullPath = false; } Text.Text = handle["te"]; if (!string.IsNullOrEmpty(ItemUri)) { var item = Factory.GetDatabase(ItemDb).GetItem(new DataUri(ItemUri)); if (MediaManager.HasMediaContent(item)) { FileNameLabel.Text = (showFullPath ? item.GetProviderPath() : item.Name) + "." + item["Extension"]; long size; SizeLabel.Text = Int64.TryParse(item["size"], out size) ? ToFileSize(size) : "unknown"; } else { SheerResponse.Alert("There is no file attached."); } } else if (!string.IsNullOrEmpty(FileName)) { // check if file in approved location var filePath = FileUtil.MapPath(FileName); var webSitePath = FileUtil.MapPath("/"); var dataPath = FileUtil.MapPath(Settings.DataFolder); if (!filePath.StartsWith(webSitePath, StringComparison.InvariantCultureIgnoreCase) && !filePath.StartsWith(dataPath, StringComparison.InvariantCultureIgnoreCase)) { FileNameLabel.Text = "Files from outside of the Sitecore Data and Website folders cannot be downloaded.\n\n" + "Copy the file to the Sitecore Data folder and try again."; SizeLabel.Visible = false; PathPrefix.Visible = false; SizePrefix.Visible = false; OK.Visible = false; DownloadImage.Visible = false; ErrorImage.Visible = true; return; } FileNameLabel.Text = showFullPath ? FileName : Path.GetFileName(FileName); SheerResponse.Download(FileName); Hidden.Value = "downloaded"; var file = new FileInfo(FileName); SizeLabel.Text = ToFileSize(file.Length); } var caption = handle["cp"]; Context.ClientPage.Title = caption; Assert.ArgumentNotNull(e, "e"); Text.Text = handle["te"]; Hidden.Value = "cancelled"; Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value); TypeResolver.Resolve <IUrlHandleWrapper>().DisposeHandle(handle); }