Skip to content
This repository was archived by the owner on Mar 15, 2021. It is now read-only.

Commit 973b135

Browse files
author
y0no
authored
Merge pull request #81 from synhack/Fix_graph's_color
Fix graph's color
2 parents bfefbff + cabae89 commit 973b135

File tree

6 files changed

+67
-20
lines changed

6 files changed

+67
-20
lines changed

phishing/jinja2/phishing/campaign_dashboard.html

+17-7
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
};
5050
var colors_list = [
5151
//Light1
52-
"#EC7553",
5352
"#3A7696",
53+
"#EC7553",
5454
"#ECA653",
5555
"#3BA76D",
5656
//Basic
@@ -182,15 +182,25 @@
182182
}
183183

184184
function load_pie(canvas, values) {
185+
var labels = [];
186+
var data = [];
187+
var pie_color = [];
188+
189+
Object.keys(values).map(function (key) {
190+
labels.push(key);
191+
data.push(values[key]['value']);
192+
193+
if (values[key]['color'])
194+
pie_color.push(values[key]['color']);
195+
});
196+
185197
var data = {
186-
labels: Object.keys(values),
198+
labels: labels,
187199
datasets: [
188200
{
189-
data: Object.keys(values).map(function (key) {
190-
return values[key];
191-
}),
192-
backgroundColor: colors_list,
193-
hoverBackgroundColor: colors_list
201+
data: data,
202+
backgroundColor: pie_color.length ? pie_color : colors_list,
203+
hoverBackgroundColor: pie_color.length ? pie_color : colors_list,
194204
}
195205
]
196206
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% if graphs.attachment_executed_pie %}
2+
<div class="col-md-3">
3+
<h3>{% trans %}Attachment open{% endtrans %}</h3>
4+
<canvas id="attachment_executed_pie"></canvas>
5+
{% if graphs.attachment_executed_opened_tracker_count %}
6+
<p title="{% trans %}This number is the sum of ALL the attachment opened. One people can open one the attachment several times{% endtrans %}">
7+
<b>{% trans %}Total opened{% endtrans %}:</b> {{ graphs.attachment_executed_opened_tracker_count }}
8+
</p>
9+
{% else %}
10+
<b>{% trans %}Not opened{% endtrans %}</b>
11+
{% endif %}
12+
</div>
13+
{% endif %}

phishing/jinja2/phishing/dashboard_parts/email_open.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<div class="col-md-3">
33
<h3>{% trans %}Emails open{% endtrans %}</h3>
44
<canvas id="email_open_pie"></canvas>
5-
<p><b>{% trans %}Total opened{% endtrans %}:</b> {{ graphs.email_open_opened_tracker_count or 0 }}</p>
5+
{% if graphs.email_open_opened_tracker_count %}
6+
<p title="{% trans %}This number is the sum of ALL the email opened. One people can open one the email several times{% endtrans %}">
7+
<b>{% trans %}Total opened{% endtrans %}:</b> {{ graphs.email_open_opened_tracker_count }}
8+
</p>
9+
{% else %}
10+
<b>{% trans %}Not opened{% endtrans %}</b>
11+
{% endif %}
612
</div>
713
{% endif %}

phishing/jinja2/phishing/dashboard_parts/landing_page.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22
<div class="col-md-3">
33
<h3>{% trans %}Landing page open{% endtrans %}</h3>
44
<canvas id="landing_page_open_pie"></canvas>
5-
<p><b>{% trans %}Total open{% endtrans %}:</b> {{ graphs.landing_page_open_pie.opened or 0 }}</p>
5+
{% if graphs.landing_page_open_opened_tracker_count %}
6+
<p title="{% trans %}This number is the sum of ALL the landingpage opened. One people can open one the landingpage several times{% endtrans %}">
7+
<b>{% trans %}Total opened{% endtrans %}:</b> {{ graphs.landing_page_open_opened_tracker_count }}
8+
</p>
9+
{% else %}
10+
<b>{% trans %}Not opened{% endtrans %}</b>
11+
{% endif %}
612
</div>
713
{% endif %}
814

915
{% if graphs.landing_page_post_pie %}
1016
<div class="col-md-3">
1117
<h3>{% trans %}Landing page post{% endtrans %}</h3>
1218
<canvas id="landing_page_post_pie"></canvas>
13-
<p><b>{% trans %}Total POST{% endtrans %}:</b> {{ graphs.landing_page_post_pie.yes or 0 }}</p>
19+
{% if graphs.landing_page_post_yes_tracker_count %}
20+
<p title="{% trans %}This number is the sum of ALL the post on the landingpage opened. One people can post multiple times on the landingpage.{% endtrans %}">
21+
<b>{% trans %}Total posted{% endtrans %}:</b> {{ graphs.landing_page_post_yes_tracker_count }}
22+
</p>
23+
{% else %}
24+
<b>{% trans %}Not opened{% endtrans %}</b>
25+
{% endif %}
1426
</div>
1527
{% endif %}

phishing/tests/campaign.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,17 @@ def check(var_name, group1_count, group2_count):
115115
)
116116

117117
# check values
118-
self.assertEqual(data.get(target_group1_name, 0), group1_count,
118+
self.assertEqual(data.get(target_group1_name, 0)['value'], group1_count,
119119
test_infos)
120-
self.assertEqual(data.get(target_group2_name, 0), group2_count,
120+
self.assertEqual(data.get(target_group2_name, 0)['value'], group2_count,
121121
test_infos)
122122

123123
# email open check
124124
self.assertContains(resp, 'id="target_group_email_open_pie"')
125125
check('target_group_email_open_pie', 2, 1)
126126

127127
# open landing page
128+
128129
self.assertContains(resp, 'id="target_group_landing_page_open_pie"')
129130
check('target_group_landing_page_open_pie', 1, 2)
130131

phishing/views/campaign.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def add_histogram_value(name, datetime, value):
7979
# add value
8080
graphs[graph_name][value][to_hour_timestamp(datetime)] += 1
8181

82-
def add_pie_value(name, value):
82+
def add_pie_value(name, value, fixed_color=''):
8383
"""Add value to pie graph.
8484
8585
:param name: graph name
@@ -91,28 +91,33 @@ def add_pie_value(name, value):
9191
graphs[graph_name] = {}
9292

9393
if value not in graphs[graph_name]:
94-
graphs[graph_name][value] = 1
95-
else:
96-
graphs[graph_name][value] += 1
94+
graphs[graph_name][value] = {
95+
'value': 0,
96+
'color': fixed_color,
97+
}
98+
99+
graphs[graph_name][value]['value'] += 1
97100

98101
def clean_name(name):
99102
return re.sub('[^0-9a-zA-Z]+', '_', name)
100103

101104
# generate tracker graph
102105
for tracker in Tracker.objects.filter(campaign_id=pk) \
103-
.order_by('-created_at'):
106+
.order_by('created_at'): # order column (in user details)
104107
# init targets details
105108
if tracker.target_id not in targets_details:
106109
targets_details[tracker.target_id] = OrderedDict({
107110
'email': tracker.target.email,
108111
})
109-
110112
# add values
111113
key = clean_name(tracker.key)
112114
targets_details[tracker.target_id][tracker.key] = tracker
113115
value = '%s (%s)' % (tracker.key, tracker.value)
116+
unchanged_value = (
117+
tracker.updated_at - tracker.created_at).total_seconds() < 1
118+
pie_color_value = '#bdc3c7' if unchanged_value else '#e67e22'
114119

115-
add_pie_value(key, value)
120+
add_pie_value(key, value, pie_color_value)
116121
add_histogram_value(key, tracker.updated_at, value)
117122

118123
# can has trakerInfos entry ?
@@ -190,7 +195,7 @@ def clean_name(name):
190195
# init graph layout
191196
tabs_layout = OrderedDict()
192197
tabs_layout['Global'] = ['global.html', 'email_open.html',
193-
'landing_page.html']
198+
'landing_page.html', 'attachment.html']
194199

195200
# add target group graph
196201
if campaign.target_groups.count() > 1:

0 commit comments

Comments
 (0)