forked from relaxnow/owasp-asvs-report-generator
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathasvs.js
184 lines (170 loc) · 6.2 KB
/
asvs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
angular.module('asvs', []).
/**
* Recursively average values in object
* @image http://images.wikia.com/transformers/images/b/b9/Ravageboxart.jpg
*/
filter('ravg',function () {
"use strict";
function collectValues(obj) {
var values = [], objKey, value;
for (objKey in obj) {
// Guard against inherited properties
if (!obj.hasOwnProperty(objKey)) {
continue;
}
value = obj[objKey];
if (typeof value === 'object') {
values = values.concat(collectValues(value));
}
else {
values[values.length] = +value;
}
}
return values;
}
return function ravg(obj) {
var avg, values = collectValues(obj);
avg = values.reduce(function (prev, cur) {
return prev + cur;
}, 0) / values.length;
return Math.floor(avg * 10) / 10;
};
}).
controller('WizardController', ['$scope', 'ravgFilter', function ($scope, ravgFilter) {
"use strict";
function getNewReport() {
var report = {};
report.chapters = ASVS.chapters;
report.rules = ASVS.rules;
report.rules = report.rules.map(function (rule) {
var factors = {};
jQuery.extend(true, factors, ASVS.risk.factors);
rule.risk = { factors: factors};
rule.showEdit = 'hide';
rule.showPass = 'hide';
rule.showFail = 'hide';
rule.enableReset = 'disabled';
return rule;
});
report.rules[0].showEdit = '';
return report;
}
var report = (typeof localStorage !== 'undefined') && JSON.parse(localStorage.getItem('report'));
if (!report) {
report = getNewReport();
}
$scope.report = report;
$scope.enableReset = 'disabled';
$scope.showPass = 'hide';
$scope.showFail = 'hide';
$scope.getStatusClass = function (rule) {
return rule.status === 'passed' ? 'pass' : 'fail';
};
$scope.hideIfPassed = function (rule) {
return rule.status !== 'passed' ? '' : 'hide';
};
$scope.hideIfFailed = function (rule) {
return rule.status !== 'passed' ? 'hide' : '';
};
$scope.pass = function (rule) {
rule.status = 'passed';
rule.enableReset = '';
rule.showPass = '';
rule.showFail = 'hide';
};
$scope.fail = function (rule) {
rule.status = 'failed';
rule.enableReset = '';
rule.showPass = 'hide';
rule.showFail = '';
};
$scope.reset = function (rule) {
$("[name=status]").removeAttr("checked");
delete rule.status;
rule.enableReset = 'disabled';
rule.showPass = 'hide';
rule.showFail = 'hide';
};
$scope.getCurrentRule = function () {
return report.rules.filter(function (rule) {
return rule.showEdit !== 'hide';
}).shift();
};
$scope.edittedIsLast = function () {
var rule = $scope.getCurrentRule();
var lastRule = report.rules[report.rules.length - 1];
return rule.chapter === lastRule.chapter && rule.nr === lastRule.nr ? '' : 'hide';
};
$scope.edittedIsNotLast = function () {
var rule = $scope.getCurrentRule();
return $scope.edittedIsLast(rule) === 'hide' ? '' : 'hide';
};
$scope.edittedIsNotFirst = function () {
var rule = $scope.getCurrentRule();
var firstRule = report.rules[0];
return rule.chapter === firstRule.chapter && rule.nr === firstRule.nr ? 'hide' : '';
};
$scope.edittedPercentage = function () {
var percentage = 0;
report.rules.forEach(function (rule, index) {
if (rule.showEdit !== 'hide') {
percentage = (index) / report.rules.length * 100;
}
});
return percentage;
};
$scope.belongsToChapterIndex = function ($index) {
return function (rule) {
return rule.chapter === $index;
};
};
$scope.next = function () {
var setEdit = false;
for (var i = 0; i < report.rules.length; i++) {
if (setEdit === true) {
report.rules[i - 1].showEdit = 'hide';
report.rules[i].showEdit = '';
break;
}
if (report.rules[i].showEdit !== 'hide') {
setEdit = true;
}
}
};
$scope.prev = function () {
var setEdit = false;
for (var i = report.rules.length - 1; i >= 0; i--) {
if (setEdit === true) {
report.rules[i + 1].showEdit = 'hide';
report.rules[i].showEdit = '';
break;
}
if (report.rules[i].showEdit !== 'hide') {
setEdit = true;
}
}
};
$scope.done = function () {
$('#wizard').dialog('close');
};
$scope.getRiskRatingDescription = function (riskFactors) {
var riskRating = ravgFilter(riskFactors);
var riskRange;
for (var i = 0; i < ASVS.risk.ranges.length; i++) {
riskRange = ASVS.risk.ranges[i];
if (riskRating >= riskRange.start && riskRating < riskRange.end) {
return riskRange.title;
}
}
return 'Unknown';
};
$scope.getChapterTitle = function (chapter) {
return ASVS.chapters[chapter - 1];
};
function saveLoop() {
localStorage.setItem('report', JSON.stringify($scope.report));
}
if (typeof localStorage !== 'undefined') {
setInterval(saveLoop, 10000);
}
}]);