lesli_audit 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/lesli_audit/application.css +183 -0
- data/app/controllers/lesli_audit/analytics_controller.rb +16 -0
- data/app/controllers/lesli_audit/logs_controller.rb +12 -2
- data/app/controllers/lesli_audit/traffic_controller.rb +25 -0
- data/app/controllers/lesli_audit/users_controller.rb +7 -4
- data/app/interfaces/lesli_audit/logger_interface.rb +5 -4
- data/app/jobs/lesli_audit/cloudflare_traffic_sync_job.rb +78 -0
- data/app/models/lesli_audit/account.rb +12 -0
- data/app/models/lesli_audit/cloudflare_traffic_sync.rb +99 -0
- data/app/models/lesli_audit/traffic_breakdown.rb +38 -0
- data/app/models/lesli_audit/traffic_rollup.rb +33 -0
- data/app/models/lesli_audit/user_journal.rb +0 -2
- data/app/services/lesli_audit/activity_audit.rb +8 -4
- data/app/services/lesli_audit/analytics_service.rb +237 -0
- data/app/services/lesli_audit/cloudflare/configuration.rb +92 -0
- data/app/services/lesli_audit/cloudflare/graphql_client.rb +309 -0
- data/app/services/lesli_audit/cloudflare/snapshot_converter.rb +101 -0
- data/app/services/lesli_audit/cloudflare/sync_service.rb +79 -0
- data/app/services/lesli_audit/cloudflare_traffic_snapshot.rb +182 -0
- data/app/services/lesli_audit/log_service.rb +99 -5
- data/app/services/lesli_audit/request_service.rb +73 -10
- data/app/services/lesli_audit/retention_cleanup.rb +16 -16
- data/app/services/lesli_audit/traffic_service.rb +216 -0
- data/app/services/lesli_audit/traffic_snapshot_importer.rb +120 -0
- data/app/services/lesli_audit/user_service.rb +119 -152
- data/app/views/lesli_audit/{visitors → analytics}/index.html.erb +40 -30
- data/app/views/lesli_audit/logs/index.html.erb +88 -19
- data/app/views/lesli_audit/logs/show.html.erb +36 -8
- data/app/views/lesli_audit/partials/_navigation.html.erb +5 -4
- data/app/views/lesli_audit/requests/index.html.erb +80 -19
- data/app/views/lesli_audit/traffic/_breakdown.html.erb +46 -0
- data/app/views/lesli_audit/traffic/index.html.erb +177 -0
- data/app/views/lesli_audit/users/index.html.erb +97 -40
- data/config/locales/translations.en.yml +137 -1
- data/config/locales/translations.es.yml +137 -1
- data/config/locales/translations.fr.yml +132 -1
- data/config/locales/translations.it.yml +132 -1
- data/config/locales/translations.pt.yml +132 -1
- data/config/routes.rb +6 -23
- data/db/migrate/v1.0/0501110110_create_lesli_audit_account_logs.rb +2 -1
- data/db/migrate/v1.0/0501120110_create_lesli_audit_user_logs.rb +2 -1
- data/db/migrate/v1.0/0501120210_create_lesli_audit_user_journals.rb +0 -3
- data/db/migrate/v1.0/0501130110_create_lesli_audit_traffic_rollups.rb +55 -0
- data/db/migrate/v1.0/0501130210_create_lesli_audit_traffic_breakdowns.rb +41 -0
- data/db/migrate/v1.0/0501130310_create_lesli_audit_cloudflare_traffic_syncs.rb +42 -0
- data/db/seed/devices.rb +2 -1
- data/db/seed/traffic.rb +128 -0
- data/db/seed/users.rb +68 -27
- data/db/seeds.rb +3 -2
- data/lib/lesli_audit/version.rb +2 -2
- data/lib/tasks/lesli_audit_cloudflare_traffic.rake +16 -0
- data/readme.md +10 -0
- metadata +24 -5
- data/app/controllers/lesli_audit/visitors_controller.rb +0 -14
- data/app/services/lesli_audit/visitor_service.rb +0 -212
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
=begin
|
|
2
|
-
|
|
3
|
-
Lesli
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2023, Lesli Technologies, S. A.
|
|
6
|
-
|
|
7
|
-
This program is free software: you can redistribute it and/or modify
|
|
8
|
-
it under the terms of the GNU General Public License as published by
|
|
9
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
-
(at your option) any later version.
|
|
11
|
-
|
|
12
|
-
This program is distributed in the hope that it will be useful,
|
|
13
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
-
GNU General Public License for more details.
|
|
16
|
-
|
|
17
|
-
You should have received a copy of the GNU General Public License
|
|
18
|
-
along with this program. If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
|
|
20
|
-
Lesli · Ruby on Rails SaaS development platform.
|
|
21
|
-
|
|
22
|
-
Made with ♥ by https://www.lesli.tech
|
|
23
|
-
Building a better future, one line of code at a time.
|
|
24
|
-
|
|
25
|
-
@contact hello@lesli.tech
|
|
26
|
-
@website https://www.lesli.tech
|
|
27
|
-
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
28
|
-
|
|
29
|
-
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
|
-
// ·
|
|
31
|
-
=end
|
|
32
|
-
|
|
33
|
-
module LesliAudit
|
|
34
|
-
class VisitorService < Lesli::ApplicationLesliService
|
|
35
|
-
|
|
36
|
-
def visits
|
|
37
|
-
requests = apply_time_filter(current_user.account.audit.account_requests)
|
|
38
|
-
|
|
39
|
-
controllers, total_requests = requests.pick(
|
|
40
|
-
Arel.sql("COUNT(DISTINCT request_controller)"),
|
|
41
|
-
Arel.sql("SUM(request_count)")
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
controllers: controllers.to_i,
|
|
46
|
-
requests: total_requests.to_i
|
|
47
|
-
}
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def traffic
|
|
51
|
-
#Rails.cache.fetch(cache_key_for_account(__method__), expires_in: 1.hour) do
|
|
52
|
-
group = 'day'
|
|
53
|
-
#group = params[:bygroup] if ['month','week','day'].include?(params[:bygroup])
|
|
54
|
-
|
|
55
|
-
group_by = "DATE_TRUNC('month', date)" if group == 'month'
|
|
56
|
-
group_by = "DATE_TRUNC('week', date)" if group == 'week'
|
|
57
|
-
group_by = "DATE_TRUNC('day', date)" if group == 'day'
|
|
58
|
-
|
|
59
|
-
# compatibility for SQLite
|
|
60
|
-
if ActiveRecord::Base.connection.adapter_name == "SQLite"
|
|
61
|
-
group_by = "strftime('%Y-%m-%d', date)"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
requests = apply_time_filter(current_user.account.audit.account_requests)
|
|
65
|
-
.group(group_by)
|
|
66
|
-
|
|
67
|
-
requests.limit(10).order("xaxiskey desc").select(
|
|
68
|
-
"sum(request_count) yaxiskey",
|
|
69
|
-
"#{group_by} xaxiskey"
|
|
70
|
-
).as_json
|
|
71
|
-
#end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def requests
|
|
75
|
-
requests = apply_time_filter(current_user.account.audit.account_requests)
|
|
76
|
-
.group("request_controller")
|
|
77
|
-
|
|
78
|
-
requests = requests.limit(LIMIT).order("requests DESC").select(
|
|
79
|
-
:request_controller,
|
|
80
|
-
"sum(request_count) requests"
|
|
81
|
-
).as_json
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def os
|
|
85
|
-
device_counts = apply_time_filter(current_user.account.audit.account_devices)
|
|
86
|
-
.group(:agent_platform)
|
|
87
|
-
.sum(:agent_count)
|
|
88
|
-
|
|
89
|
-
total = device_counts.values.sum
|
|
90
|
-
|
|
91
|
-
device_counts.map do |device, count|
|
|
92
|
-
{
|
|
93
|
-
device: device,
|
|
94
|
-
count: count,
|
|
95
|
-
icon: platform_icon(device),
|
|
96
|
-
percentage: total.zero? ? 0 : ((count.to_f / total) * 100).round()
|
|
97
|
-
}
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def devices
|
|
102
|
-
device_counts = apply_time_filter(current_user.account.audit.account_devices)
|
|
103
|
-
.group(:agent_device)
|
|
104
|
-
.sum(:agent_count)
|
|
105
|
-
|
|
106
|
-
total = device_counts.values.sum
|
|
107
|
-
|
|
108
|
-
device_counts.map do |device, count|
|
|
109
|
-
{
|
|
110
|
-
device: device,
|
|
111
|
-
count: count,
|
|
112
|
-
icon: device_icon(device),
|
|
113
|
-
percentage: total.zero? ? 0 : ((count.to_f / total) * 100).round()
|
|
114
|
-
}
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def browsers
|
|
119
|
-
browser_counts = apply_time_filter(current_user.account.audit.account_devices)
|
|
120
|
-
.group(:agent_browser)
|
|
121
|
-
.sum(:agent_count)
|
|
122
|
-
|
|
123
|
-
total = browser_counts.values.sum
|
|
124
|
-
|
|
125
|
-
browser_counts.map do |browser, count|
|
|
126
|
-
{
|
|
127
|
-
browser: browser,
|
|
128
|
-
count: count,
|
|
129
|
-
icon: browser_icon(browser),
|
|
130
|
-
percentage: total.zero? ? 0 : ((count.to_f / total) * 100).round()
|
|
131
|
-
}
|
|
132
|
-
end
|
|
133
|
-
#Rails.cache.fetch(cache_key_for_account(__method__), expires_in: 4.hour) do
|
|
134
|
-
# current_user.account.audit.account_devices
|
|
135
|
-
# .group(:agent_browser, :date)
|
|
136
|
-
# .select(
|
|
137
|
-
# 'date as xaxiskey',
|
|
138
|
-
# 'agent_browser as dataname',
|
|
139
|
-
# 'sum(agent_count) as yaxiskey'
|
|
140
|
-
# ).as_json
|
|
141
|
-
#end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
LIMIT=15
|
|
147
|
-
|
|
148
|
-
DEFAULT_PLATFORM_ICON_CLASS = "computer-fill"
|
|
149
|
-
PLATFORM_ICON_CLASSES = {
|
|
150
|
-
/chrome os|cros/i => "chrome-fill",
|
|
151
|
-
/ios|ipad|iphone|mac/i => "apple-fill",
|
|
152
|
-
/windows/i => "windows-fill",
|
|
153
|
-
/ubuntu/i => "ubuntu-fill",
|
|
154
|
-
/debian|fedora|linux/i => "linux-fill",
|
|
155
|
-
/android/i => "android-fill"
|
|
156
|
-
}.freeze
|
|
157
|
-
|
|
158
|
-
DEFAULT_BROWSER_ICON_CLASS = "global-fill"
|
|
159
|
-
BROWSER_ICON_CLASSES = {
|
|
160
|
-
/chrome|chromium/i => "chrome-fill",
|
|
161
|
-
/firefox/i => "firefox-fill",
|
|
162
|
-
/safari/i => "safari-fill",
|
|
163
|
-
/edge/i => "edge-fill",
|
|
164
|
-
/opera|opr/i => "opera-fill",
|
|
165
|
-
/internet explorer|msie/i => "ie-fill",
|
|
166
|
-
/brave/i => "brave-fill"
|
|
167
|
-
}.freeze
|
|
168
|
-
|
|
169
|
-
DEVICE_ICON_CLASSES = {
|
|
170
|
-
"desktop" => "mac-line",
|
|
171
|
-
"tablet" => "tablet-line",
|
|
172
|
-
"smartphone" => "smartphone-line",
|
|
173
|
-
"unknown" => "file-unknow-line"
|
|
174
|
-
}.freeze
|
|
175
|
-
|
|
176
|
-
def platform_icon(platform)
|
|
177
|
-
return DEFAULT_PLATFORM_ICON_CLASS if platform.blank?
|
|
178
|
-
|
|
179
|
-
match = PLATFORM_ICON_CLASSES.find do |pattern, _icon_class|
|
|
180
|
-
platform.match?(pattern)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
match ? match.last : DEFAULT_PLATFORM_ICON_CLASS
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def browser_icon(browser)
|
|
187
|
-
return DEFAULT_BROWSER_ICON_CLASS if browser.blank?
|
|
188
|
-
|
|
189
|
-
match = BROWSER_ICON_CLASSES.find do |pattern, _icon_class|
|
|
190
|
-
browser.match?(pattern)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
match ? match.last : DEFAULT_BROWSER_ICON_CLASS
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def device_icon(device)
|
|
197
|
-
DEVICE_ICON_CLASSES.fetch(device.to_s, DEVICE_ICON_CLASSES["unknown"])
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def apply_time_filter(relation)
|
|
201
|
-
start_date = case query[:bytime]
|
|
202
|
-
when "day" then Date.current
|
|
203
|
-
when "week" then 6.days.ago.to_date
|
|
204
|
-
when "month" then 29.days.ago.to_date
|
|
205
|
-
when "sixmonth" then 6.months.ago.to_date
|
|
206
|
-
when "year" then 1.year.ago.to_date
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
start_date ? relation.where(date: start_date..) : relation
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|