private void Init(string settingsPath) { if (!File.Exists(settingsPath)) return; var settingsDoc = XDocument.Load(settingsPath); foreach (var element in settingsDoc.Descendants("SourceUrl")) { var name = element.Attribute("Name") != null ? element.Attribute("Name").Value : String.Empty; var url = element.Attribute("Url") != null ? element.Attribute("Url").Value : String.Empty; var groupId = element.Attribute("GroupId") != null ? element.Attribute("GroupId").Value : String.Empty; if (!url.EndsWith("/")) url += "/"; var sourceUrl = new SourceUrl { Url = url, Name = name, GroupId = groupId }; SourceUrls.Add(sourceUrl); } var node = settingsDoc.Descendants("AutoLoad").FirstOrDefault(); bool temp; AutoLoad = node != null && Boolean.TryParse(node.Value, out temp) && temp; if (!SourceUrls.Any()) return; _isConfigured = true; }
public IEnumerable<SnapshotCollection> GetSnapshots(SourceUrl sourceUrl) { var result = new List<SnapshotCollection>(); if (!_isConfigured) return result; foreach (var item in (IEnumerable)JsonConvert.DeserializeObject(new WebClient().DownloadString(String.Format("{0}{1}{2}", sourceUrl.Url, "contents.php", !String.IsNullOrEmpty(sourceUrl.GroupId) ? String.Format("?gid={0}", sourceUrl.GroupId) : String.Empty)))) { var i = 0; JProperty tmp = null; foreach (var m in (IEnumerable)item) { switch (i) { case 0: tmp = (m as JProperty); i++; break; case 1: var snapshotName = tmp != null ? (String)tmp.Value : String.Empty; var s = new SnapshotCollection(snapshotName); if (m != null) foreach (var property in ((IEnumerable)m).OfType<JArray>()) { foreach (var ss in property.Select(prop => (String)prop).Where(ss => !String.IsNullOrEmpty(ss))) s.Screenshots.Add(new SnapshotItem(ss.Replace(s.Name, String.Empty), String.Format("{0}{1}/{2}/", sourceUrl.Url, s.Name, ss))); break; } if (s.Screenshots.Any()) result.Add(s); break; } if (i > 1) break; // Next } } return result; }
private void Init(StorageFile settingsFile) { if (!settingsFile.ExistsLocal()) { return; } var settingsDoc = XDocument.Load(settingsFile.LocalPath); foreach (var element in settingsDoc.Descendants("SourceUrl")) { var name = element.Attribute("Name") != null?element.Attribute("Name").Value : String.Empty; var url = element.Attribute("Url") != null?element.Attribute("Url").Value : String.Empty; var groupId = element.Attribute("GroupId") != null?element.Attribute("GroupId").Value : String.Empty; if (!url.EndsWith("/")) { url += "/"; } var sourceUrl = new SourceUrl { Url = url, Name = name, GroupId = groupId }; SourceUrls.Add(sourceUrl); } var node = settingsDoc.Descendants("AutoLoad").FirstOrDefault(); bool temp; AutoLoad = node != null && Boolean.TryParse(node.Value, out temp) && temp; if (!SourceUrls.Any()) { return; } _isConfigured = true; }
public override void Parse() { SourceUrl = Arguments[0]; ExternalDependencies = ParseParameterSwitch("-x"); ZipDependencies = ParseParameterSwitch("-z"); DisplayHtml = ParseParameterSwitch("-d"); TargetFile = ParseStringParameterSwitch("-o", null); Verbose = ParseParameterSwitch("-v"); if (string.IsNullOrEmpty(TargetFile)) { ExternalDependencies = false; } if (SourceUrl.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) == -1 && SourceUrl.Contains("%")) { SourceUrl = Environment.ExpandEnvironmentVariables(SourceUrl); } if (!string.IsNullOrEmpty(TargetFile) && TargetFile.Contains("%")) { TargetFile = Environment.ExpandEnvironmentVariables(TargetFile); } }
/// <summary> /// Check if the source exist if not gets its info then add it to the database /// </summary> /// <returns>Task Type</returns> private async Task AddNewSource() { if (IsWorking) { return; } IsWorking = true; try { string trimedUrl = SourceUrl.TrimEnd('/'); var exist = await SourceDataService.SourceExistAsync(trimedUrl); if (exist) { await new MessageDialog("SourcesViewModelSourceExistMessageDialog".GetLocalized()).ShowAsync(); } else { try { var feedString = await RssRequest.GetFeedAsStringAsync(trimedUrl); var xmlSource = feedString.TrimStart(); var source = await SourceDataService.GetSourceInfoFromRssAsync(xmlSource, trimedUrl); if (source == null) { await new MessageDialog("SourcesViewModelSourceInfoNotValidMessageDialog".GetLocalized()).ShowAsync(); return; } Sources.Insert(0, await SourceDataService.AddNewSourceAsync(source)); await new MessageDialog("SourcesViewModelSourceAddedMessageDialog".GetLocalized()).ShowAsync(); ClearPopups(); } catch (HttpRequestException ex) { await new MessageDialog("HttpRequestExceptionMessageDialog".GetLocalized()).ShowAsync(); Debug.WriteLine(ex); } catch (XmlException ex) { await new MessageDialog("XmlExceptionMessageDialog".GetLocalized()).ShowAsync(); Debug.WriteLine(ex); } catch (ArgumentNullException ex) { await new MessageDialog("SourcesViewModelSourceUrlNullExceptionMessageDialog".GetLocalized()).ShowAsync(); Debug.WriteLine(ex); } catch (Exception ex) { Debug.WriteLine(ex); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsWorking = false; } }
private void ResetCurrentContext(ReactContext context) { if (_currentContext == context) { return; } _currentContext = context; if (_devSettings.IsHotModuleReplacementEnabled && context != null) { try { Log.Info(ReactConstants.Tag, "## DevSupportManager ## SourceUrl:[" + SourceUrl.ToString() + "]"); var uri = new Uri(SourceUrl); var path = uri.LocalPath.Substring(1); // strip initial slash in path var host = uri.Host; var port = uri.Port; context.GetJavaScriptModule <HMRClient>().enable("tizen", path, host, port); } catch (Exception ex) { HandleException(ex); } } }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { Span <char> data; if (!stream.ReadLine(out data)) { return; } HttpParse.AnalyzeRequestLine(data, this); HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this); int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } RouteMatchResult routeMatchResult = new RouteMatchResult(); this.IsRewrite = false; if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString)) { this.IsRewrite = true; this.SourceUrl = Url; this.SourceBaseUrl = BaseUrl; this.SourcePath = Path; if (Server.Options.UrlIgnoreCase) { Url = routeMatchResult.RewriteUrlLower; } else { Url = routeMatchResult.RewriteUrl; } if (Server.Options.AgentRewrite) { if (len > 0 && this.SourceUrl.Length > len + 1) { if (Url.IndexOf('?') > 0) { Url += "&"; } else { Url += "?"; } Url += new string(SourceUrl.AsSpan().Slice(len + 1)); } } len = HttpParse.ReadUrlQueryString(Url, null, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } if (Server.EnableLog(EventArgs.LogType.Info)) { Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} {((IPEndPoint)Session.RemoteEndPoint).Address} request {SourceUrl} rewrite to {Url}"); } } mState = LoadedState.Method; } }
private void Download() { if (string.IsNullOrWhiteSpace(SourceUrl)) { throw new InvalidOperationException(string.Format(Resources.MissingParameterError, nameof(SourceUrl))); } string fileName = Path.GetFileName(SourceUrl); #pragma warning disable SecurityIntelliSenseCS // MS Security rules violation string fileWithPath = Path.Combine(Application.UserAppDataPath, fileName); string fileNameWithoutExt = Path.GetFileNameWithoutExtension(SourceUrl); string destFile = Path.Combine(Application.UserAppDataPath, FileName); #pragma warning restore SecurityIntelliSenseCS // MS Security rules violation #if CWE bool cwe = fileNameWithoutExt.StartsWith("cwec_"); #endif bool capec = fileNameWithoutExt.StartsWith("capec_"); #if CWE if (!cwe && !capec) #else if (!capec) #endif { throw new InvalidOperationException(string.Format(Resources.UnsupportedFileTypeError, fileName)); } if (!File.Exists(fileWithPath)) { using (var client = new WebClient()) { #pragma warning disable SecurityIntelliSenseCS // MS Security rules violation client.DownloadFile(new Uri(SourceUrl), fileWithPath); #pragma warning restore SecurityIntelliSenseCS // MS Security rules violation } } if (SourceUrl.EndsWith(".zip")) { ZipFile.ExtractToDirectory(fileWithPath, Application.UserAppDataPath); #pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' #pragma warning disable SecurityIntelliSenseCS // MS Security rules violation File.Move(Path.Combine(Application.UserAppDataPath, fileNameWithoutExt), destFile); #pragma warning restore SecurityIntelliSenseCS // MS Security rules violation #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' } else { if (string.CompareOrdinal(fileName, FileName) != 0) { #pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' #pragma warning disable SecurityIntelliSenseCS // MS Security rules violation File.Move(Path.Combine(Application.UserAppDataPath, fileName), destFile); #pragma warning restore SecurityIntelliSenseCS // MS Security rules violation #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' } } try { _threatSource = capec ? new ThreatSource(ThreatSourceManager.GetCapecCatalog(destFile)) : #if CWE new ThreatSource(ThreatSourceManager.GetCweCatalog(destFile)); #else null; #endif FinalizeDownload(true); } catch (Exception exc) { #if DEBUG Debug.WriteLine(exc.ToString()); #endif if (File.Exists(destFile)) #pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' { File.Delete(destFile); } #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}' FinalizeDownload(false); } }
/// <summary> /// Check if the source exist if not gets its info then add it to the database /// </summary> /// <returns>Task Type</returns> private async Task AddNewSource() { if (IsWorking) { return; } IsWorking = true; try { string trimedUrl = SourceUrl.TrimEnd('/'); var exist = await SourceDataService.SourceExistAsync(trimedUrl); if (exist) { await new MessageDialog("SourcesViewModelSourceExistMessageDialog".GetLocalized()).ShowAsync(); } else { try { var feedString = await RssRequest.GetFeedAsStringAsync(trimedUrl, TokenSource.Token); var source = await SourceDataService.GetSourceInfoFromRssAsync(feedString, trimedUrl); if (source == null) { await new MessageDialog("SourcesViewModelSourceInfoNotValidMessageDialog".GetLocalized()).ShowAsync(); return; } Sources.Insert(0, await SourceDataService.AddNewSourceAsync(source)); RefreshSourcesCommand.OnCanExecuteChanged(); await new MessageDialog("SourcesViewModelSourceAddedMessageDialog".GetLocalized()).ShowAsync(); ClearPopups(); } catch (HttpRequestException ex) { if (ex.Message.StartsWith("Response status code does not indicate success: 403")) { await new MessageDialog("HttpRequestException403MessageDialog".GetLocalized()).ShowAsync(); } else { await new MessageDialog("HttpRequestExceptionMessageDialog".GetLocalized()).ShowAsync(); } Debug.WriteLine(ex); } catch (XmlException ex) { await new MessageDialog("XmlExceptionMessageDialog".GetLocalized()).ShowAsync(); Debug.WriteLine(ex); } catch (ArgumentNullException ex) { await new MessageDialog("SourcesViewModelSourceUrlNullExceptionMessageDialog".GetLocalized()).ShowAsync(); Debug.WriteLine(ex); } catch (Exception ex) { Debug.WriteLine(ex); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsWorking = false; } }