Skip to content

Commit 49e0ed6

Browse files
committed
better hyperlink system
1 parent 16e7c67 commit 49e0ed6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/com/fuse/reporting/DocxUtils.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ private void checkTables(String variable, String section, String customCSS)
334334
if (v.getCustomFields() != null) {
335335
for (CustomField cf : v.getCustomFields()) {
336336
// Only perform this action if the variable is plain text and not a hyperlink
337-
Boolean isHyperlink = nxml.matches(
337+
/*Boolean isHyperlink = nxml.matches(
338338
".*<w:hyperlink w:history=\"true\" r:id=\".*\"><w:r><w:rPr><w:rStyle w:val=\"Hyperlink\"/></w:rPr><w:t>\\$\\{cf"+cf.getType().getVariable()+"\\}.*");
339339
if(cf.getType().getFieldType() < 3 && !isHyperlink) {
340+
*/
340341

342+
if(cf.getType().getFieldType() < 3) {
341343
nxml = nxml.replaceAll("\\$\\{cf" + cf.getType().getVariable() + "\\}", CData(cf.getValue()));
342344
if(customFieldMap.containsKey(cf.getType().getVariable()) && colorMap.containsKey(cf.getValue())){
343345
String colorMatch = customFieldMap.get(cf.getType().getVariable());
@@ -381,7 +383,7 @@ private void checkTables(String variable, String section, String customCSS)
381383
// Replace Hyperlinks
382384
if (v.getCustomFields() != null) {
383385
for (CustomField cf : v.getCustomFields()) {
384-
this.replaceHyperlink(newrow, "${cf" + cf.getType().getVariable() + "}", cf.getValue());
386+
this.replaceHyperlink(newrow, "${cf" + cf.getType().getVariable() + " link}", cf.getValue());
385387
}
386388
}
387389

@@ -859,7 +861,7 @@ private void replacement(Vulnerability v, String customCSS)
859861
private void replacementHyperlinks(Object document, Map<String,String> map) {
860862
for (String key : map.keySet()) {
861863
String value = map.get(key);
862-
this.replaceHyperlink(document, "${" + key + "}", value);
864+
this.replaceHyperlink(document, "${" + key + " link}", value);
863865
}
864866
}
865867

@@ -1146,9 +1148,10 @@ private void setFindings(String section, String customCSS)
11461148
nxml="";
11471149
if (v.getCustomFields() != null && !nxml.equals("")) {
11481150
for (CustomField cf : v.getCustomFields()) {
1149-
Boolean isHyperlink = nxml.matches(
1150-
".*<w:hyperlink w:history=\"true\" r:id=\".*\"><w:r><w:rPr><w:rStyle w:val=\"Hyperlink\"/></w:rPr><w:t>\\$\\{cf"+cf.getType().getVariable()+"\\}.*");
1151-
if(cf.getType().getFieldType() < 3 && !isHyperlink) {
1151+
/*Boolean isHyperlink = nxml.matches(
1152+
".*<w:hyperlink w:history=\"true\" r:id=\".*\"><w:r><w:rPr><w:rStyle w:val=\"Hyperlink\"/>(<w:rFonts w:cstheme=\".*\"/>)?</w:rPr><w:t>\\$\\{cf"+cf.getType().getVariable()+"\\}.*");
1153+
if(cf.getType().getFieldType() < 3 && !isHyperlink) {*/
1154+
if(cf.getType().getFieldType() < 3) {
11521155
nxml = nxml.replaceAll("\\$\\{cf" + cf.getType().getVariable() + "\\}", CData(cf.getValue()));
11531156
if(customFieldMap.containsKey(cf.getType().getVariable()) && colorMap.containsKey(cf.getValue())){
11541157
String colorMatch = customFieldMap.get(cf.getType().getVariable());
@@ -1182,8 +1185,9 @@ private void setFindings(String section, String customCSS)
11821185
Object paragraph = XmlUtils.unmarshalString(nxml);
11831186
//Replace Hyperlinks
11841187
for (CustomField cf : v.getCustomFields()) {
1185-
this.replaceHyperlink(paragraph, "${cf" + cf.getType().getVariable() + "}", cf.getValue());
1188+
this.replaceHyperlink(paragraph, "${cf" + cf.getType().getVariable() + " link}", cf.getValue());
11861189
}
1190+
this.replaceHyperlink(paragraph, "${cvssString link}", v.getCvssString());
11871191
mlp.getMainDocumentPart().getContent().add(begin++, paragraph);
11881192
}catch(Exception ex) {
11891193
ex.printStackTrace();
@@ -1470,6 +1474,14 @@ public void replaceHyperlink(Object wordPackage, String searchText, String newUr
14701474
if(updatedTarget.contains("@")) {
14711475
updatedTarget = "mailto:" + updatedTarget;
14721476
}
1477+
if(searchText.contains("cvssString link")) {
1478+
if(this.assessment.getType().isCvss31()){
1479+
updatedTarget = "https://www.first.org/cvss/calculator/3-1#" + newUrl;
1480+
}else {
1481+
updatedTarget = "https://www.first.org/cvss/calculator/4-0#" + newUrl;
1482+
}
1483+
1484+
}
14731485
newRel.setTarget(updatedTarget);
14741486
newRel.setTargetMode("External");
14751487

0 commit comments

Comments
 (0)