public static Tracking_Application saveLog(this Tracking_Application tracking) { try { var logData = PublicDI.log.LogRedirectionTarget.prop("LogData").str(); if (logData.notNull()) { //tracking.Name = DateTime.Now.str().safeFileName(); var logFile = tracking.LogFilePath; //var logFile = tracking.Location.pathCombine("ApplicationLog.txt"); "Saving Application Tracking Log to: {0}".info(logFile); var tmArticle = new TeamMentor_Article { Metadata = { Title = "Log Files" }, Content = { Data = { Value = logData } } }; tmArticle.saveAs(logFile + ".xml"); logData.saveAs(logFile); } } catch (Exception ex) { ex.log("[Tracking_Application] in saveLog"); } return(tracking); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { UserRole.EditArticles.demand(); if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } if (article.Content.DataType.lower() == "html") // tidy the html { var cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]> in the text var tidiedHtml = cdataContent.tidyHtml(); article.Content.Data.Value = tidiedHtml; if (article.serialize(false).inValid()) // see if the tidied content can be serialized and if not use the original data { article.Content.Data.Value = cdataContent; } } article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache tmDatabase.Events.Article_Saved.raise(article); // TODO find way to identify save issues (like the return value of the save action) return(true); }
[EditArticles] public static TeamMentor_Article xmlDB_NewGuidanceItem(this TM_Xml_Database tmDatabase, Guid guidanceItemId, string title, string images, string topic, string technology, string category, string ruleType, string priority, string status, string author, string phase, string htmlContent, Guid libraryId) { var article = new TeamMentor_Article { Metadata = new TeamMentor_Article_Metadata { Id = (guidanceItemId == Guid.Empty) ? Guid.NewGuid() : guidanceItemId, Library_Id = libraryId, Author = author, Category = category, Priority = priority, Type = ruleType, Status = status, Technology = technology, Title = title, Phase = phase, }, Content = new TeamMentor_Article_Content { DataType = "html", Data = { Value = htmlContent } } }; if (article.xmlDB_Save_Article(libraryId, tmDatabase)) { return(article); } return(null); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } article.sanitize(); article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache if (tmDatabase.UsingFileStorage) // save to disk { var guidanceXmlPath = tmDatabase.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId); if (guidanceXmlPath.valid()) { "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath); article.saveAs(guidanceXmlPath); return(guidanceXmlPath.fileExists()); } } return(true); }
public static Tracking_Application saveLog(this Tracking_Application tracking) { try { var logData = PublicDI.log.LogRedirectionTarget.prop("LogData").str() ; if (logData.notNull()) { //tracking.Name = DateTime.Now.str().safeFileName(); var logFile = tracking.LogFilePath; //var logFile = tracking.Location.pathCombine("ApplicationLog.txt"); "Saving Application Tracking Log to: {0}".info(logFile); var tmArticle = new TeamMentor_Article { Metadata = {Title = "Log Files"}, Content = {Data = {Value = logData}} }; tmArticle.saveAs(logFile + ".xml"); logData.saveAs(logFile); } } catch (Exception ex) { ex.log("[Tracking_Application] in saveLog"); } return tracking; }
public static bool titleMatch(TeamMentor_Article article, string title1, string title2) { var match = (article.Metadata.Title.notNull() && (article.Metadata.Title.lower() == title1) || article.Metadata.Title.lower() == title2); if (match) { } return match; }
public static bool titleMatch(TeamMentor_Article article, string title1, string title2) { var match = (article.Metadata.Title.notNull() && (article.Metadata.Title.lower() == title1) || article.Metadata.Title.lower() == title2); if (match) { } return(match); }
public static TeamMentor_Article createArticle_from_ExternalServiceData(this string service, string serviceData) { try { Func <string, string, TeamMentor_Article> createArticleFromUrl = (title, url) => { var externalArticle = new TeamMentor_Article { Metadata = { Title = title } }; var webClient = new System.Net.WebClient(); webClient.Headers.Add("User-Agent", "TeamMentor"); var htmlContent = webClient.DownloadString(url); var sanitizedHtml = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(htmlContent); externalArticle.Content.Data.Value = sanitizedHtml; return(externalArticle); }; //Web.Https.ignoreServerSslErrors(); switch (service) { case "wikipedia": { var url = "https://en.wikipedia.org/wiki/{0}?action=render".format(serviceData); return(createArticleFromUrl("From Wikipedia.org: " + serviceData, url)); } case "owasp": { var title = "From owasp.org: " + serviceData; var url = "https://www.owasp.org/index.php/{0}?action=render".format(serviceData); return(createArticleFromUrl(title, url)); } case "msdn": { var externalArticle = new TeamMentor_Article { Metadata = { Title = "From MSDN: " + service } }; var msdnUrl = "http://msdn.microsoft.com/en-us/library/{0}.aspx".format(serviceData); externalArticle.Content.Data.Value = @"<IFrame src='{0}'/ id='msdnContent' style='width:99%;height:500px' frameborder='0'></IFrame> <script>$('#msdnContent').height(document.height-180)</script>" .format(msdnUrl); return(externalArticle); } } } catch (Exception ex) { ex.log("in createArticleFromExternalServiceData"); } return(null); }
public void handleAction_Create(string data) { var article = new TeamMentor_Article { Metadata = { Title = data.urlDecode() } }; var xmlContent = article.serialize(false) .add_Xslt("Article_Edit.xslt"); context.Response.ContentType = "application/xml"; context.Response.Write(xmlContent); endResponse(); }
public static bool article_Save(this TM_FileStorage tmFileStorage, TeamMentor_Article article) { editArticles.demand(); var libraryId = article.Metadata.Library_Id; var guidanceXmlPath = tmFileStorage.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId); if (guidanceXmlPath.valid()) { "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath); article.saveAs(guidanceXmlPath); return guidanceXmlPath.fileExists(); } return true; }
public static TeamMentor_Article createArticle_from_ExternalServiceData(this string service, string serviceData) { try { Func<string, string, TeamMentor_Article> createArticleFromUrl = (title, url) => { var externalArticle = new TeamMentor_Article {Metadata = {Title = title}}; var webClient = new System.Net.WebClient(); webClient.Headers.Add("User-Agent", "TeamMentor"); var htmlContent = webClient.DownloadString(url); var sanitizedHtml = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(htmlContent); externalArticle.Content.Data.Value = sanitizedHtml; return externalArticle; }; //Web.Https.ignoreServerSslErrors(); switch (service) { case "wikipedia": { var url = "https://en.wikipedia.org/wiki/{0}?action=render".format(serviceData); return createArticleFromUrl("From Wikipedia.org: " + serviceData, url); } case "owasp": { var title = "From owasp.org: " + serviceData; var url = "https://www.owasp.org/index.php/{0}?action=render".format(serviceData); return createArticleFromUrl(title, url); } case "msdn": { var externalArticle = new TeamMentor_Article {Metadata = {Title = "From MSDN: " + service}}; var msdnUrl = "http://msdn.microsoft.com/en-us/library/{0}.aspx".format(serviceData); externalArticle.Content.Data.Value = @"<IFrame src='{0}'/ id='msdnContent' style='width:99%;height:500px' frameborder='0'></IFrame> <script>$('#msdnContent').height(document.height-180)</script>".format(msdnUrl); return externalArticle; } } } catch (Exception ex) { ex.log("in createArticleFromExternalServiceData"); } return null; }
public void handleAction_Create(string data) { var article = new TeamMentor_Article { Metadata = { Title = data.urlDecode() } }; var xmlContent = article.serialize(false) .add_Xslt("Article_Edit.xslt"); context.Response.ContentType = "application/xml"; context.Response.Write(xmlContent); tmWebServices.logUserActivity("Create Article (Notepad)", "{0} ({1})".info(article.Metadata.Title, data)); endResponse(); }
public static bool article_Delete(this TM_FileStorage tmFileStorage, TeamMentor_Article article) { editArticles.demand(); var guidanceItemId = article.Metadata.Id; var guidanceItemXmlPath = tmFileStorage.removeGuidanceItemFileMapping(guidanceItemId); "removing GuidanceItem with Id:{0} located at {1}".info(guidanceItemId, guidanceItemXmlPath); if (guidanceItemXmlPath.valid()) Files.deleteFile(guidanceItemXmlPath); tmFileStorage.tmXmlDatabase().Events.Articles_Cache_Updated.raise(); //tmDatabase.queue_Save_GuidanceItemsCache(); //TM_Xml_Database.mapGuidanceItemsViews(); return true; }
public static void sanitize(this TeamMentor_Article article) { if (article.Content.DataType.lower() == "html") // tidy the html { string cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]> in the text string tidiedHtml = cdataContent.tidyHtml(); article.Content.Data.Value = tidiedHtml; if (article.serialize(false).inValid()) // see if the tidied content can be serialized and if not use the original data { article.Content.Data.Value = cdataContent; } } }
public Guid CreateArticle_Simple(Guid libraryId, string title, string dataType, string htmlCode) { resetCache(); var article = new TeamMentor_Article { Metadata = { Library_Id = libraryId, Title = title }, Content = { DataType = dataType, Data = { Value = htmlCode } } }; return CreateArticle(article); }
[WebMethod(EnableSession = true)][EditArticles] public Guid CreateArticle_Simple(Guid libraryId, string title, string dataType, string htmlCode) { resetCache(); var article = new TeamMentor_Article { Metadata = { Library_Id = libraryId, Title = title }, Content = { DataType = dataType, Data = { Value = htmlCode } } }; return(CreateArticle(article)); }
public static TeamMentor_Article update_Cache_GuidanceItems(this TeamMentor_Article guidanceItem, TM_Xml_Database tmDatabase) { guidanceItem.htmlEncode(); // ensure MetaData is encoded var guidanceItemGuid = guidanceItem.Metadata.Id; if (TM_Xml_Database.Current.Cached_GuidanceItems.hasKey(guidanceItemGuid)) { TM_Xml_Database.Current.Cached_GuidanceItems[guidanceItemGuid] = guidanceItem; } else { TM_Xml_Database.Current.Cached_GuidanceItems.Add(guidanceItem.Metadata.Id, guidanceItem); } tmDatabase.queue_Save_GuidanceItemsCache(); return(guidanceItem); }
public TeamMentor_Article transform() { // fix the issue with older SI Library Articles if (phase == null) { phase = Rule_Type; Rule_Type = Type; } var teamMentor_Article = new TeamMentor_Article { Metadata = new TeamMentor_Article_Metadata { Id = id.guid(), Id_History = id_Original, Library_Id = libraryId.guid(), Title = title, Category = Category, Phase = phase, Technology = Technology, Type = Rule_Type, Author = Author, Priority = Priority, Status = Status, Source = Source, DirectLink = "", Tag = "", Security_Demand = "", }, Content = new TeamMentor_Article_Content { Sanitized = true, DataType = "Html", Data = { Value = content } } }; teamMentor_Article.setHashes(); teamMentor_Article.htmlEncode(); //encode contents return(teamMentor_Article); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } if (article.Content.DataType.lower() == "html") // tidy the html { var cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]> in the text var tidiedHtml = cdataContent.tidyHtml(); article.Content.Data.Value = tidiedHtml; if (article.serialize(false).inValid()) // see if the tidied content can be serialized and if not use the original data { article.Content.Data.Value = cdataContent; } } article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache if (tmDatabase.UsingFileStorage) // save to disk { var guidanceXmlPath = tmDatabase.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId); if (guidanceXmlPath.valid()) { "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath); article.saveAs(guidanceXmlPath); return(guidanceXmlPath.fileExists()); } } return(true); }
//this causes double encoding problems with some properties (like the Title on Html Editor) , but removing it opens up more XSS on other viewers (like the Table) public static TeamMentor_Article htmlEncode(this TeamMentor_Article article) { if (article.isNull()) { return(null); } var metaData = article.Metadata; foreach (var prop in metaData.type().properties()) { if (prop.PropertyType == typeof(string)) { var value = (string)metaData.prop(prop.Name); metaData.prop(prop.Name, Encoder.HtmlEncode(value)); } } if (TMConfig.Current.TMSecurity.Sanitize_HtmlContent) { article.Content.Data.Value = Sanitizer.GetSafeHtmlFragment(article.Content.Data.Value); article.Content.Sanitized = true; } return(article); }
public static IE_TeamMentor article_Raw(this IE_TeamMentor ieTeamMentor, TeamMentor_Article tmArticle) { return ieTeamMentor.article_Raw(tmArticle.Metadata.Id); }
public bool UpdateGuidanceItem(TeamMentor_Article guidanceItem) { resetCache(); return guidanceItem.xmlDB_Save_Article(tmXmlDatabase); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, TM_Xml_Database tmDatabase) { return(article.xmlDB_Save_Article(article.Metadata.Library_Id, tmDatabase)); }
[EditArticles] public static TeamMentor_Article xmlDB_Preview_Article(this TeamMentor_Article article) { article.sanitize(); return(article); }
private bool handleAction_Create(string data) { var article = new TeamMentor_Article {Metadata = {Title = data.urlDecode()}}; var xmlContent = article.serialize(false) .add_Xslt("Article_Edit.xslt"); context.Response.ContentType = "application/xml"; context.Response.Write(xmlContent); return true; }
[EditArticles] public static Guid xmlDB_Create_Article(this TM_Xml_Database tmDatabase, TeamMentor_Article article) { article.Metadata.Id = Guid.NewGuid(); if (article.xmlDB_Save_Article(tmDatabase)) { return(article.Metadata.Id); } return(Guid.Empty); }
[WebMethod(EnableSession = true)][EditArticles] public bool UpdateGuidanceItem(TeamMentor_Article guidanceItem) { if (guidanceItem.isNull()) { return(false); } resetCache(); var result = guidanceItem.xmlDB_Save_Article(tmXmlDatabase); this.logUserActivity("Update Article", "{0} ({1})".format(guidanceItem.Metadata.Title, guidanceItem.Metadata.Id)); return(result); }
public void transfer_ArticleEditor(TeamMentor_Article article) { tmWebServices.logUserActivity("Edit Article (WYSIWYG)", "{0} ({1})".format(article.Metadata.Title, article.Metadata.Id)); transfer_Request("articleEditor"); }
[WebMethod(EnableSession = true)][EditArticles] public Guid CreateArticle(TeamMentor_Article article) { resetCache(); return(tmXmlDatabase.xmlDB_Create_Article(article)); }
public static TeamMentor_Article setHashes(this TeamMentor_Article article) { article.Metadata_Hash = article.Metadata.serialize(false).hash(); article.Content_Hash = article.Content.serialize(false).hash(); return(article); }
public bool UpdateGuidanceItem(TeamMentor_Article guidanceItem) { resetCache(); var result = guidanceItem.xmlDB_Save_Article(tmXmlDatabase); this.LogUserActivity("Update Article", "{0} - {1} [{2}".format(guidanceItem.Metadata.Id, guidanceItem.Metadata.Title, result)); return result; }
public bool UpdateGuidanceItem(TeamMentor_Article guidanceItem) { editArticles.demand(); if (guidanceItem.isNull()) return false; resetCache(); var result = guidanceItem.xmlDB_Save_Article(tmXmlDatabase); this.logUserActivity("Update Article", "{0} ({1})".format(guidanceItem.Metadata.Title, guidanceItem.Metadata.Id)); return result; }
public static Guid xmlDB_Create_Article(this TM_Xml_Database tmDatabase, TeamMentor_Article article) { UserRole.EditArticles.demand(); if (article.notNull()) { article.Metadata.Id = Guid.NewGuid(); if(article.xmlDB_Save_Article(tmDatabase)) return article.Metadata.Id; } return Guid.Empty; }
public Guid CreateArticle(TeamMentor_Article article) { editArticles.demand(); resetCache(); return tmXmlDatabase.xmlDB_Create_Article(article); }
public TeamMentor_Article transform() { // fix the issue with older SI Library Articles if (phase == null) { phase = Rule_Type; Rule_Type = Type; } var teamMentor_Article = new TeamMentor_Article { Metadata = new TeamMentor_Article_Metadata { Id = id.guid(), Id_History = id_Original, Library_Id = libraryId.guid(), Title = title, Category = Category, Phase = phase, Technology = Technology, Type = Rule_Type, Author = Author, Priority = Priority, Status = Status, Source = Source, DirectLink = "", Tag = "", Security_Demand = "", }, Content = new TeamMentor_Article_Content { Sanitized = true, DataType = "Html", Data = {Value = content} } }; teamMentor_Article.setHashes(); teamMentor_Article.htmlEncode(); //encode contents return teamMentor_Article; }
public static IE_TeamMentor article_Html(this IE_TeamMentor ieTeamMentor, TeamMentor_Article tmArticle) { return (ieTeamMentor.notNull() && tmArticle.notNull()) ? ieTeamMentor.article_Html(tmArticle.Metadata.Id) : ieTeamMentor; }
public void handleAction_Create(string data) { var article = new TeamMentor_Article {Metadata = {Title = data.urlDecode()}}; var xmlContent = article.serialize(false) .add_Xslt("Article_Edit.xslt"); context.Response.ContentType = "application/xml"; context.Response.Write(xmlContent); tmWebServices.logUserActivity("Create Article (Notepad)", "{0} ({1})".info(article.Metadata.Title, data)); endResponse(); }
public static Guid xmlDB_Create_Article(this TM_Xml_Database tmDatabase, TeamMentor_Article article) { article.Metadata.Id = Guid.NewGuid(); if(article.xmlDB_Save_Article(tmDatabase)) return article.Metadata.Id; return Guid.Empty; }
public static TeamMentor_Article xmlDB_NewGuidanceItem(this TM_Xml_Database tmDatabase, Guid guidanceItemId, string title, string images, string topic, string technology, string category, string ruleType, string priority, string status, string author,string phase, string htmlContent, Guid libraryId) { var article = new TeamMentor_Article { Metadata = new TeamMentor_Article_Metadata { Id = (guidanceItemId == Guid.Empty) ? Guid.NewGuid() : guidanceItemId, Library_Id = libraryId, Author = author, Category = category, Priority = priority, Type = ruleType, Status = status, Technology = technology, Title = title, Phase = phase, }, Content = new TeamMentor_Article_Content { DataType = "html", Data = {Value = htmlContent} } }; article.xmlDB_Save_Article(libraryId, tmDatabase); return article; }
[WebMethod(EnableSession = true)][EditArticles] public TeamMentor_Article GetPreview(TeamMentor_Article guidanceItem) { return(guidanceItem.xmlDB_Preview_Article()); }