-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from kuettai/main
Bug Fixes, Visual Improvement, Performance Improvement, and WATools integration
- Loading branch information
Showing
33 changed files
with
710 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,90 @@ | ||
import json | ||
import json, re | ||
|
||
import constants as _C | ||
from utils.Config import Config | ||
from utils.Tools import _warn, _info | ||
from frameworks.Framework import Framework | ||
from frameworks.helper.WATools import WATools | ||
|
||
class WAFS(Framework): | ||
WATools = None | ||
ResultCache = {} | ||
isBeta = False | ||
def __init__(self, data): | ||
super().__init__(data) | ||
self.isBeta = Config.get('beta', False) | ||
|
||
if self.isBeta == False: | ||
return | ||
|
||
waTools = WATools('security') | ||
cliParams = Config.get('_SS_PARAMS') | ||
|
||
tmpParams = {} | ||
if 'others' in cliParams and not cliParams['others'] == None: | ||
params = cliParams['others'] | ||
cfg = json.loads(params) | ||
|
||
if 'WA' in cfg: | ||
tmpParams = cfg['WA'] | ||
|
||
if waTools.preCheck(tmpParams): | ||
self.WATools = waTools | ||
self.WATools.init(tmpParams) | ||
self.WATools.createReportIfNotExists() | ||
self.WATools.listAnswers() | ||
# print(self.WATools.answerSets) | ||
|
||
|
||
def _hookPostItemActivity(self, title, section, checks, comp): | ||
if self.WATools == None or self.WATools.HASPERMISSION == False: | ||
return title, section, checks, comp | ||
|
||
titleNum = self.extractNumber(title) | ||
sectNum = self.extractNumber(section) | ||
|
||
paired = "{}::{}".format(titleNum, sectNum) | ||
|
||
newChecks = "<h4>{}</h4>{}".format(self.getDescription(titleNum, paired), checks) | ||
|
||
titleKey = self.WATools.answerSets.get(titleNum, [None])[0] | ||
if not titleKey in self.ResultCache: | ||
self.ResultCache[titleKey] = { | ||
"0": [], | ||
"1": [], | ||
"-1": [] | ||
} | ||
|
||
if not titleKey == None: | ||
if comp == 1: | ||
self.ResultCache[titleKey]["1"].append(self.WATools.answerSets.get(paired, [None])[0]) | ||
elif comp == -1: | ||
self.ResultCache[titleKey]["-1"].append(self.WATools.answerSets.get(paired, [None, None])[1]) | ||
else: | ||
self.ResultCache[titleKey]["0"].append(self.WATools.answerSets.get(paired, [None])[0]) | ||
|
||
return title, section, newChecks, comp | ||
|
||
def _hookPostItemsLoop(self): | ||
if self.WATools == None or self.WATools.HASPERMISSION == False: | ||
return | ||
|
||
for title, opts in self.ResultCache.items(): | ||
if len(opts["1"]) == 0 and len(opts["-1"]) == 0: | ||
continue | ||
|
||
ansStr = opts["1"] | ||
unselectedNotes = "***Generated by SS\n\nHere are the items failed SS checks (if any):\n- {}".format("\n- ".join(opts["-1"])) | ||
|
||
self.WATools.updateAnswers(title, ansStr, unselectedNotes) | ||
|
||
pass | ||
|
||
def extractNumber(self, s): | ||
match = re.search(r'\d+', s) | ||
return match.group() if match else None | ||
|
||
if __name__ == "__main__": | ||
data = json.loads(open(_C.FRAMEWORK_DIR + '/api.json').read()) | ||
# print(data) | ||
o = WARS(data) | ||
o.readFile() | ||
# o.obj() | ||
o.generateMappingInformation() | ||
def getDescription(self, titleNum, paired): | ||
titleStr = self.WATools.answerSets.get(titleNum, [None])[1] | ||
sectStr = self.WATools.answerSets.get(paired, [None])[1] | ||
return f"{titleStr} - {sectStr}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.