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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
class CreateLesliAuditTrafficRollups < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :lesli_audit_traffic_rollups do |t|
|
|
4
|
+
t.string :provider, null: false
|
|
5
|
+
t.string :hostname, null: false
|
|
6
|
+
t.string :path, null: false
|
|
7
|
+
t.string :resource_type, null: false
|
|
8
|
+
t.bigint :resource_id, null: false
|
|
9
|
+
t.date :date, null: false
|
|
10
|
+
t.bigint :page_views, null: false, default: 0
|
|
11
|
+
t.bigint :visits, null: false, default: 0
|
|
12
|
+
t.datetime :snapshot_at, null: false
|
|
13
|
+
t.timestamps null: false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
add_reference(
|
|
17
|
+
:lesli_audit_traffic_rollups,
|
|
18
|
+
:account,
|
|
19
|
+
null: false,
|
|
20
|
+
foreign_key: { to_table: :lesli_audit_accounts, on_delete: :cascade }
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
add_check_constraint(
|
|
24
|
+
:lesli_audit_traffic_rollups,
|
|
25
|
+
"resource_id > 0",
|
|
26
|
+
name: "lesli_audit_traffic_rollups_resource_id_positive"
|
|
27
|
+
)
|
|
28
|
+
add_check_constraint(
|
|
29
|
+
:lesli_audit_traffic_rollups,
|
|
30
|
+
"page_views >= 0",
|
|
31
|
+
name: "lesli_audit_traffic_rollups_page_views_nonnegative"
|
|
32
|
+
)
|
|
33
|
+
add_check_constraint(
|
|
34
|
+
:lesli_audit_traffic_rollups,
|
|
35
|
+
"visits >= 0",
|
|
36
|
+
name: "lesli_audit_traffic_rollups_visits_nonnegative"
|
|
37
|
+
)
|
|
38
|
+
add_index(
|
|
39
|
+
:lesli_audit_traffic_rollups,
|
|
40
|
+
%i[account_id provider hostname path date],
|
|
41
|
+
unique: true,
|
|
42
|
+
name: "index_lesli_audit_traffic_rollups_on_provider_path_and_date"
|
|
43
|
+
)
|
|
44
|
+
add_index(
|
|
45
|
+
:lesli_audit_traffic_rollups,
|
|
46
|
+
%i[account_id resource_type resource_id date],
|
|
47
|
+
name: "index_lesli_audit_traffic_rollups_on_resource_and_date"
|
|
48
|
+
)
|
|
49
|
+
add_index(
|
|
50
|
+
:lesli_audit_traffic_rollups,
|
|
51
|
+
:date,
|
|
52
|
+
name: "index_lesli_audit_traffic_rollups_on_date"
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class CreateLesliAuditTrafficBreakdowns < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :lesli_audit_traffic_breakdowns do |t|
|
|
4
|
+
t.string :dimension, null: false
|
|
5
|
+
t.string :value, null: false
|
|
6
|
+
t.bigint :page_views, null: false, default: 0
|
|
7
|
+
t.bigint :visits, null: false, default: 0
|
|
8
|
+
t.timestamps null: false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
add_reference(
|
|
12
|
+
:lesli_audit_traffic_breakdowns,
|
|
13
|
+
:account,
|
|
14
|
+
null: false,
|
|
15
|
+
foreign_key: { to_table: :lesli_audit_accounts, on_delete: :cascade }
|
|
16
|
+
)
|
|
17
|
+
add_reference(
|
|
18
|
+
:lesli_audit_traffic_breakdowns,
|
|
19
|
+
:traffic_rollup,
|
|
20
|
+
null: false,
|
|
21
|
+
foreign_key: { to_table: :lesli_audit_traffic_rollups, on_delete: :cascade }
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
add_check_constraint(
|
|
25
|
+
:lesli_audit_traffic_breakdowns,
|
|
26
|
+
"page_views >= 0",
|
|
27
|
+
name: "lesli_audit_traffic_breakdowns_page_views_nonnegative"
|
|
28
|
+
)
|
|
29
|
+
add_check_constraint(
|
|
30
|
+
:lesli_audit_traffic_breakdowns,
|
|
31
|
+
"visits >= 0",
|
|
32
|
+
name: "lesli_audit_traffic_breakdowns_visits_nonnegative"
|
|
33
|
+
)
|
|
34
|
+
add_index(
|
|
35
|
+
:lesli_audit_traffic_breakdowns,
|
|
36
|
+
%i[account_id traffic_rollup_id dimension value],
|
|
37
|
+
unique: true,
|
|
38
|
+
name: "index_lesli_audit_traffic_breakdowns_on_dimension"
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class CreateLesliAuditCloudflareTrafficSyncs < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :lesli_audit_cloudflare_traffic_syncs do |t|
|
|
4
|
+
t.references :account,
|
|
5
|
+
null: false,
|
|
6
|
+
foreign_key: { to_table: :lesli_audit_accounts, on_delete: :cascade }
|
|
7
|
+
t.string :zone_id, null: false
|
|
8
|
+
t.date :period_start, null: false
|
|
9
|
+
t.date :period_end, null: false
|
|
10
|
+
t.string :status, null: false, default: "pending"
|
|
11
|
+
t.string :execution_id
|
|
12
|
+
t.integer :snapshots_count, null: false, default: 0
|
|
13
|
+
t.datetime :started_at
|
|
14
|
+
t.datetime :finished_at
|
|
15
|
+
t.datetime :last_synced_at
|
|
16
|
+
t.text :error_message
|
|
17
|
+
t.timestamps null: false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
add_index(
|
|
21
|
+
:lesli_audit_cloudflare_traffic_syncs,
|
|
22
|
+
%i[account_id zone_id period_start period_end],
|
|
23
|
+
unique: true,
|
|
24
|
+
name: "index_lesli_audit_cloudflare_syncs_on_account_zone_and_period"
|
|
25
|
+
)
|
|
26
|
+
add_check_constraint(
|
|
27
|
+
:lesli_audit_cloudflare_traffic_syncs,
|
|
28
|
+
"period_start <= period_end",
|
|
29
|
+
name: "lesli_audit_cloudflare_syncs_valid_period"
|
|
30
|
+
)
|
|
31
|
+
add_check_constraint(
|
|
32
|
+
:lesli_audit_cloudflare_traffic_syncs,
|
|
33
|
+
"snapshots_count >= 0",
|
|
34
|
+
name: "lesli_audit_cloudflare_syncs_snapshots_count_nonnegative"
|
|
35
|
+
)
|
|
36
|
+
add_check_constraint(
|
|
37
|
+
:lesli_audit_cloudflare_traffic_syncs,
|
|
38
|
+
"status IN ('pending', 'running', 'succeeded', 'failed')",
|
|
39
|
+
name: "lesli_audit_cloudflare_syncs_valid_status"
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
data/db/seed/devices.rb
CHANGED
data/db/seed/traffic.rb
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
core_account = Lesli::Account.first
|
|
4
|
+
return unless core_account
|
|
5
|
+
|
|
6
|
+
audit_account = core_account.audit || LesliAudit::Account.create!(
|
|
7
|
+
account: core_account,
|
|
8
|
+
name: core_account.name
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
resources = [ {
|
|
12
|
+
resource_type: "Profile",
|
|
13
|
+
resource_id: 1_001,
|
|
14
|
+
path: "/demo/sofia",
|
|
15
|
+
baseline: 92
|
|
16
|
+
}, {
|
|
17
|
+
resource_type: "Profile",
|
|
18
|
+
resource_id: 1_002,
|
|
19
|
+
path: "/demo/mateo",
|
|
20
|
+
baseline: 78
|
|
21
|
+
}, {
|
|
22
|
+
resource_type: "Profile",
|
|
23
|
+
resource_id: 1_003,
|
|
24
|
+
path: "/demo/valentina",
|
|
25
|
+
baseline: 72
|
|
26
|
+
}, {
|
|
27
|
+
resource_type: "Profile",
|
|
28
|
+
resource_id: 1_004,
|
|
29
|
+
path: "/demo/santiago",
|
|
30
|
+
baseline: 68
|
|
31
|
+
}, {
|
|
32
|
+
resource_type: "Business",
|
|
33
|
+
resource_id: 2_001,
|
|
34
|
+
path: "/demo/cafe",
|
|
35
|
+
baseline: 64
|
|
36
|
+
}, {
|
|
37
|
+
resource_type: "Business",
|
|
38
|
+
resource_id: 2_002,
|
|
39
|
+
path: "/demo/studio",
|
|
40
|
+
baseline: 56
|
|
41
|
+
}, {
|
|
42
|
+
resource_type: "Business",
|
|
43
|
+
resource_id: 2_003,
|
|
44
|
+
path: "/demo/bakery",
|
|
45
|
+
baseline: 52
|
|
46
|
+
}, {
|
|
47
|
+
resource_type: "Event",
|
|
48
|
+
resource_id: 3_001,
|
|
49
|
+
path: "/demo/festival",
|
|
50
|
+
baseline: 38
|
|
51
|
+
}, {
|
|
52
|
+
resource_type: "Event",
|
|
53
|
+
resource_id: 3_002,
|
|
54
|
+
path: "/demo/conference",
|
|
55
|
+
baseline: 44
|
|
56
|
+
}, {
|
|
57
|
+
resource_type: "Event",
|
|
58
|
+
resource_id: 3_003,
|
|
59
|
+
path: "/demo/workshop",
|
|
60
|
+
baseline: 34
|
|
61
|
+
} ].freeze
|
|
62
|
+
|
|
63
|
+
split = lambda do |total, weights|
|
|
64
|
+
remaining = total
|
|
65
|
+
weights.each_with_index.map do |weight, index|
|
|
66
|
+
value = index == weights.length - 1 ? remaining : (total * weight).round
|
|
67
|
+
remaining -= value
|
|
68
|
+
value
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
resources.each_with_index do |resource, resource_index|
|
|
73
|
+
(29.days.ago.to_date..Date.current).each_with_index do |date, day_index|
|
|
74
|
+
weekday_lift = date.on_weekend? ? 8 : 18
|
|
75
|
+
trend = day_index * (resource_index + 1)
|
|
76
|
+
page_views = resource[:baseline] + weekday_lift + trend
|
|
77
|
+
visits = (page_views * 0.72).round
|
|
78
|
+
|
|
79
|
+
country_views = split.call(page_views, [ 0.72, 0.18, 0.10 ])
|
|
80
|
+
country_visits = split.call(visits, [ 0.72, 0.18, 0.10 ])
|
|
81
|
+
device_views = split.call(page_views, [ 0.68, 0.27, 0.05 ])
|
|
82
|
+
device_visits = split.call(visits, [ 0.68, 0.27, 0.05 ])
|
|
83
|
+
referrer_views = split.call(page_views, [ 0.42, 0.31, 0.17, 0.10 ])
|
|
84
|
+
referrer_visits = split.call(visits, [ 0.42, 0.31, 0.17, 0.10 ])
|
|
85
|
+
|
|
86
|
+
breakdowns = []
|
|
87
|
+
%w[GT US MX].each_with_index do |value, index|
|
|
88
|
+
breakdowns << {
|
|
89
|
+
dimension: "country",
|
|
90
|
+
value:,
|
|
91
|
+
page_views: country_views[index],
|
|
92
|
+
visits: country_visits[index]
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
%w[mobile desktop tablet].each_with_index do |value, index|
|
|
96
|
+
breakdowns << {
|
|
97
|
+
dimension: "device",
|
|
98
|
+
value:,
|
|
99
|
+
page_views: device_views[index],
|
|
100
|
+
visits: device_visits[index]
|
|
101
|
+
}
|
|
102
|
+
end
|
|
103
|
+
%w[direct instagram google facebook].each_with_index do |value, index|
|
|
104
|
+
breakdowns << {
|
|
105
|
+
dimension: "referrer",
|
|
106
|
+
value:,
|
|
107
|
+
page_views: referrer_views[index],
|
|
108
|
+
visits: referrer_visits[index]
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
snapshot = LesliAudit::CloudflareTrafficSnapshot.new(
|
|
113
|
+
hostname: "demo.lesli.dev",
|
|
114
|
+
path: resource[:path],
|
|
115
|
+
resource_type: resource[:resource_type],
|
|
116
|
+
resource_id: resource[:resource_id],
|
|
117
|
+
date:,
|
|
118
|
+
page_views:,
|
|
119
|
+
visits:,
|
|
120
|
+
snapshot_at: date.in_time_zone.end_of_day,
|
|
121
|
+
breakdowns:
|
|
122
|
+
)
|
|
123
|
+
LesliAudit::TrafficSnapshotImporter.call(
|
|
124
|
+
account: audit_account,
|
|
125
|
+
snapshot:
|
|
126
|
+
)
|
|
127
|
+
end
|
|
128
|
+
end
|
data/db/seed/users.rb
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
return unless Rails.env.development?
|
|
4
|
-
|
|
5
3
|
account = Lesli::Account.first!
|
|
4
|
+
audit_account = account.audit || LesliAudit::Account.create!(
|
|
5
|
+
account:,
|
|
6
|
+
name: account.name
|
|
7
|
+
)
|
|
6
8
|
|
|
7
|
-
password = if defined?(Devise)
|
|
9
|
+
password = if defined?(Devise::Encryptor)
|
|
8
10
|
Devise::Encryptor.digest(Lesli::User, "password123")
|
|
9
11
|
else
|
|
10
|
-
|
|
12
|
+
""
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
now = Time.current
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
totals = {
|
|
18
|
+
users: 100,
|
|
19
|
+
inactive: 12,
|
|
20
|
+
locked: 5,
|
|
21
|
+
unconfirmed: 8,
|
|
22
|
+
never_signed_in: 14,
|
|
23
|
+
active_last_30_days: 52,
|
|
24
|
+
new_last_30_days: 10,
|
|
25
|
+
failed_attempts: 6,
|
|
26
|
+
deleted: 3
|
|
27
|
+
}.freeze
|
|
25
28
|
|
|
26
29
|
users = []
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
totals.fetch(:users).times do |index|
|
|
29
32
|
uid = "DEV-USR-#{index.to_s.rjust(5, "0")}"
|
|
30
33
|
|
|
31
34
|
users << {
|
|
@@ -55,32 +58,32 @@ TOTAL_USERS.times do |index|
|
|
|
55
58
|
locked_until: nil,
|
|
56
59
|
unlock_token: nil,
|
|
57
60
|
|
|
58
|
-
created_at: now -
|
|
61
|
+
created_at: now - (index % 330).days,
|
|
59
62
|
updated_at: now,
|
|
60
63
|
deleted_at: nil
|
|
61
64
|
}
|
|
62
65
|
end
|
|
63
66
|
|
|
64
67
|
# Inactive users
|
|
65
|
-
users.first(
|
|
68
|
+
users.first(totals.fetch(:inactive)).each do |user|
|
|
66
69
|
user[:active] = false
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
# Locked users
|
|
70
|
-
users.slice(
|
|
73
|
+
users.slice(12, totals.fetch(:locked)).each do |user|
|
|
71
74
|
user[:locked_at] = now - rand(1..15).days
|
|
72
75
|
user[:locked_until] = now + rand(1..15).days
|
|
73
76
|
end
|
|
74
77
|
|
|
75
78
|
# Unconfirmed users
|
|
76
|
-
users.slice(
|
|
79
|
+
users.slice(20, totals.fetch(:unconfirmed)).each do |user|
|
|
77
80
|
user[:confirmed_at] = nil
|
|
78
81
|
user[:confirmation_sent_at] = now - rand(1..10).days
|
|
79
82
|
user[:confirmation_token] = SecureRandom.hex(16)
|
|
80
83
|
end
|
|
81
84
|
|
|
82
85
|
# Never signed in
|
|
83
|
-
users.slice(
|
|
86
|
+
users.slice(30, totals.fetch(:never_signed_in)).each do |user|
|
|
84
87
|
user[:sign_in_count] = 0
|
|
85
88
|
user[:current_sign_in_at] = nil
|
|
86
89
|
user[:last_sign_in_at] = nil
|
|
@@ -89,29 +92,67 @@ users.slice(300, TOTAL_USERS_NEVER_SIGNED_IN).each do |user|
|
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
# Active in the last 30 days
|
|
92
|
-
users.slice(
|
|
95
|
+
users.slice(45, totals.fetch(:active_last_30_days)).each do |user|
|
|
93
96
|
user[:sign_in_count] = rand(1..100)
|
|
94
97
|
user[:last_sign_in_at] = now - rand(0..29).days
|
|
95
98
|
user[:current_sign_in_at] = user[:last_sign_in_at]
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
# New users in the last 30 days
|
|
99
|
-
users.last(
|
|
102
|
+
users.last(totals.fetch(:new_last_30_days)).each do |user|
|
|
100
103
|
user[:created_at] = now - rand(0..29).days
|
|
101
104
|
user[:updated_at] = now
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
# Users with failed attempts
|
|
105
|
-
users.slice(
|
|
108
|
+
users.slice(70, totals.fetch(:failed_attempts)).each do |user|
|
|
106
109
|
user[:failed_attempts] = rand(1..5)
|
|
107
110
|
end
|
|
108
111
|
|
|
109
112
|
# Soft-deleted users
|
|
110
|
-
users.last(
|
|
113
|
+
users.last(totals.fetch(:deleted)).each do |user|
|
|
111
114
|
user[:deleted_at] = now - rand(1..30).days
|
|
112
115
|
end
|
|
113
116
|
|
|
114
|
-
# Remove
|
|
115
|
-
|
|
117
|
+
# Remove only records owned by this seed so running it again is safe.
|
|
118
|
+
audit_account.user_journals.where("event_uid LIKE ?", "DEV-USR-ACTIVITY-%").delete_all
|
|
119
|
+
Lesli::User.unscoped.where("uid LIKE ?", "DEV-USR-%").delete_all!
|
|
120
|
+
|
|
121
|
+
# `unscoped` is required so acts_as_paranoid does not replace the explicit
|
|
122
|
+
# `deleted_at` values used to demonstrate deleted-user totals.
|
|
123
|
+
Lesli::User.unscoped.insert_all!(users)
|
|
124
|
+
|
|
125
|
+
# Retained journals provide realistic first/last activity for the Users report.
|
|
126
|
+
# They do not create request aggregates; the Requests report has its own seed.
|
|
127
|
+
demo_users = Lesli::User.where("uid LIKE ?", "DEV-USR-%").order(:id).limit(20)
|
|
128
|
+
journals = demo_users.flat_map do |user|
|
|
129
|
+
(13.days.ago.to_date..Date.current).flat_map do |date|
|
|
130
|
+
first_activity = date.in_time_zone + 8.hours + (user.id % 45).minutes
|
|
131
|
+
last_activity = first_activity + 8.hours + (user.id % 90).minutes
|
|
132
|
+
event_prefix = "DEV-USR-ACTIVITY-#{user.uid}-#{date.iso8601}"
|
|
133
|
+
|
|
134
|
+
[ {
|
|
135
|
+
account_id: audit_account.id,
|
|
136
|
+
user_id: user.id,
|
|
137
|
+
event_uid: "#{event_prefix}-FIRST",
|
|
138
|
+
request_controller: "lesli_audit/users",
|
|
139
|
+
request_action: "index",
|
|
140
|
+
date:,
|
|
141
|
+
retain: true,
|
|
142
|
+
created_at: first_activity,
|
|
143
|
+
updated_at: first_activity
|
|
144
|
+
}, {
|
|
145
|
+
account_id: audit_account.id,
|
|
146
|
+
user_id: user.id,
|
|
147
|
+
event_uid: "#{event_prefix}-LAST",
|
|
148
|
+
request_controller: "lesli_audit/users",
|
|
149
|
+
request_action: "index",
|
|
150
|
+
date:,
|
|
151
|
+
retain: true,
|
|
152
|
+
created_at: last_activity,
|
|
153
|
+
updated_at: last_activity
|
|
154
|
+
} ]
|
|
155
|
+
end
|
|
156
|
+
end
|
|
116
157
|
|
|
117
|
-
|
|
158
|
+
LesliAudit::UserJournal.insert_all!(journals)
|
data/db/seeds.rb
CHANGED
|
@@ -27,15 +27,16 @@ Building a better future, one line of code at a time.
|
|
|
27
27
|
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
28
28
|
|
|
29
29
|
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
|
-
// ·
|
|
30
|
+
// ·
|
|
31
31
|
=end
|
|
32
32
|
|
|
33
33
|
Termline.info("Loading seeds for: LesliAudit #{LesliAudit::VERSION} (#{LesliAudit::BUILD})")
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
# · load specific environment seeds
|
|
37
|
-
if Rails.env.development? || Lesli.config.demo
|
|
37
|
+
if Rails.env.development? || Lesli.config.demo
|
|
38
38
|
load LesliAudit::Engine.root.join("db", "seed", "requests.rb")
|
|
39
39
|
load LesliAudit::Engine.root.join("db", "seed", "devices.rb")
|
|
40
|
+
load LesliAudit::Engine.root.join("db", "seed", "traffic.rb")
|
|
40
41
|
load LesliAudit::Engine.root.join("db", "seed", "users.rb")
|
|
41
42
|
end
|
data/lib/lesli_audit/version.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
namespace :cloudflare_traffic do
|
|
2
|
+
desc "Enqueue recent Cloudflare traffic for every configured account"
|
|
3
|
+
task sync: :environment do
|
|
4
|
+
LesliAudit::CloudflareTrafficSyncJob.enqueue_recent
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
desc "Enqueue the initial Cloudflare traffic backfill"
|
|
8
|
+
task :backfill, %i[account_id days] => :environment do |_task, arguments|
|
|
9
|
+
account_ids = arguments[:account_id].presence ||
|
|
10
|
+
LesliAudit::Cloudflare::Configuration.from_application.account_ids
|
|
11
|
+
|
|
12
|
+
Array(account_ids).each do |account_id|
|
|
13
|
+
LesliAudit::CloudflareTrafficSyncJob.enqueue_backfill(account_id, days: arguments[:days])
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/readme.md
CHANGED
|
@@ -48,6 +48,7 @@ It records account activity and provides administrators with searchable operatio
|
|
|
48
48
|
- Account activity and audit logs
|
|
49
49
|
- Request and navigation history
|
|
50
50
|
- Request, device, and authenticated-user analytics
|
|
51
|
+
- Cloudflare-imported traffic snapshots for resources served outside Rails
|
|
51
52
|
- Direct account and authenticated-user request counters
|
|
52
53
|
- Configurable batched data retention
|
|
53
54
|
- Normalized browser, platform, and device categories
|
|
@@ -57,6 +58,13 @@ Activity logs are explicit append-only business or security events. They are
|
|
|
57
58
|
separate from request analytics: user requests are grouped counters, while
|
|
58
59
|
user journals are individual normalized HTTP request events.
|
|
59
60
|
|
|
61
|
+
The interface uses five single-word reports in a fixed order: **Users**,
|
|
62
|
+
**Analytics**, **Traffic**, **Requests**, and **Logs**. Analytics measures
|
|
63
|
+
authenticated application use. Traffic presents aggregate resource visits
|
|
64
|
+
imported from Cloudflare without logging individual requests. Cloudflare
|
|
65
|
+
`count` is presented as mapped-resource page views and `sum.visits` as visits;
|
|
66
|
+
neither metric is a unique person or audit evidence.
|
|
67
|
+
|
|
60
68
|
<br />
|
|
61
69
|
|
|
62
70
|
## Try LesliAudit
|
|
@@ -153,6 +161,8 @@ bin/rails test
|
|
|
153
161
|
- [Architecture and data policy](./docs/about/architecture.md)
|
|
154
162
|
- [Configuration](./docs/about/configuration.md)
|
|
155
163
|
- [Request analytics](./docs/analytics/overview.md)
|
|
164
|
+
- [Provider traffic](./docs/traffic/overview.md)
|
|
165
|
+
- [Cloudflare Traffic integration](./docs/traffic/cloudflare.md)
|
|
156
166
|
- [Activity events](./docs/events/overview.md)
|
|
157
167
|
- [Operational tasks](./docs/about/tasks.md)
|
|
158
168
|
- [Database](./docs/about/database.md)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lesli_audit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Lesli Development Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lesli
|
|
@@ -50,12 +50,13 @@ files:
|
|
|
50
50
|
- app/assets/javascripts/lesli_audit/application.js
|
|
51
51
|
- app/assets/stylesheets/lesli_audit/application.css
|
|
52
52
|
- app/controllers/lesli_audit/accounts_controller.rb
|
|
53
|
+
- app/controllers/lesli_audit/analytics_controller.rb
|
|
53
54
|
- app/controllers/lesli_audit/application_controller.rb
|
|
54
55
|
- app/controllers/lesli_audit/dashboards_controller.rb
|
|
55
56
|
- app/controllers/lesli_audit/logs_controller.rb
|
|
56
57
|
- app/controllers/lesli_audit/requests_controller.rb
|
|
58
|
+
- app/controllers/lesli_audit/traffic_controller.rb
|
|
57
59
|
- app/controllers/lesli_audit/users_controller.rb
|
|
58
|
-
- app/controllers/lesli_audit/visitors_controller.rb
|
|
59
60
|
- app/helpers/lesli_audit/accounts_helper.rb
|
|
60
61
|
- app/helpers/lesli_audit/application_helper.rb
|
|
61
62
|
- app/helpers/lesli_audit/dashboards_helper.rb
|
|
@@ -65,6 +66,7 @@ files:
|
|
|
65
66
|
- app/helpers/lesli_audit/users_helper.rb
|
|
66
67
|
- app/interfaces/lesli_audit/logger_interface.rb
|
|
67
68
|
- app/jobs/lesli_audit/application_job.rb
|
|
69
|
+
- app/jobs/lesli_audit/cloudflare_traffic_sync_job.rb
|
|
68
70
|
- app/jobs/lesli_audit/retention_cleanup_job.rb
|
|
69
71
|
- app/mailers/lesli_audit/application_mailer.rb
|
|
70
72
|
- app/models/concerns/lesli_audit/append_only.rb
|
|
@@ -73,17 +75,28 @@ files:
|
|
|
73
75
|
- app/models/lesli_audit/account_log.rb
|
|
74
76
|
- app/models/lesli_audit/account_request.rb
|
|
75
77
|
- app/models/lesli_audit/application_record.rb
|
|
78
|
+
- app/models/lesli_audit/cloudflare_traffic_sync.rb
|
|
76
79
|
- app/models/lesli_audit/dashboard.rb
|
|
80
|
+
- app/models/lesli_audit/traffic_breakdown.rb
|
|
81
|
+
- app/models/lesli_audit/traffic_rollup.rb
|
|
77
82
|
- app/models/lesli_audit/user_journal.rb
|
|
78
83
|
- app/models/lesli_audit/user_log.rb
|
|
79
84
|
- app/models/lesli_audit/user_request.rb
|
|
80
85
|
- app/services/lesli_audit/activity_audit.rb
|
|
86
|
+
- app/services/lesli_audit/analytics_service.rb
|
|
87
|
+
- app/services/lesli_audit/cloudflare/configuration.rb
|
|
88
|
+
- app/services/lesli_audit/cloudflare/graphql_client.rb
|
|
89
|
+
- app/services/lesli_audit/cloudflare/snapshot_converter.rb
|
|
90
|
+
- app/services/lesli_audit/cloudflare/sync_service.rb
|
|
91
|
+
- app/services/lesli_audit/cloudflare_traffic_snapshot.rb
|
|
81
92
|
- app/services/lesli_audit/log_service.rb
|
|
82
93
|
- app/services/lesli_audit/request_service.rb
|
|
83
94
|
- app/services/lesli_audit/retention_cleanup.rb
|
|
95
|
+
- app/services/lesli_audit/traffic_service.rb
|
|
96
|
+
- app/services/lesli_audit/traffic_snapshot_importer.rb
|
|
84
97
|
- app/services/lesli_audit/user_agent_parser.rb
|
|
85
98
|
- app/services/lesli_audit/user_service.rb
|
|
86
|
-
- app/
|
|
99
|
+
- app/views/lesli_audit/analytics/index.html.erb
|
|
87
100
|
- app/views/lesli_audit/dashboards/_component-calendar.html.erb
|
|
88
101
|
- app/views/lesli_audit/dashboards/edit.html.erb
|
|
89
102
|
- app/views/lesli_audit/dashboards/index.html.erb
|
|
@@ -93,8 +106,9 @@ files:
|
|
|
93
106
|
- app/views/lesli_audit/logs/show.html.erb
|
|
94
107
|
- app/views/lesli_audit/partials/_navigation.html.erb
|
|
95
108
|
- app/views/lesli_audit/requests/index.html.erb
|
|
109
|
+
- app/views/lesli_audit/traffic/_breakdown.html.erb
|
|
110
|
+
- app/views/lesli_audit/traffic/index.html.erb
|
|
96
111
|
- app/views/lesli_audit/users/index.html.erb
|
|
97
|
-
- app/views/lesli_audit/visitors/index.html.erb
|
|
98
112
|
- config/locales/translations.en.yml
|
|
99
113
|
- config/locales/translations.es.yml
|
|
100
114
|
- config/locales/translations.fr.yml
|
|
@@ -108,14 +122,19 @@ files:
|
|
|
108
122
|
- db/migrate/v1.0/0501120110_create_lesli_audit_user_logs.rb
|
|
109
123
|
- db/migrate/v1.0/0501120210_create_lesli_audit_user_journals.rb
|
|
110
124
|
- db/migrate/v1.0/0501120310_create_lesli_audit_user_requests.rb
|
|
125
|
+
- db/migrate/v1.0/0501130110_create_lesli_audit_traffic_rollups.rb
|
|
126
|
+
- db/migrate/v1.0/0501130210_create_lesli_audit_traffic_breakdowns.rb
|
|
127
|
+
- db/migrate/v1.0/0501130310_create_lesli_audit_cloudflare_traffic_syncs.rb
|
|
111
128
|
- db/seed/devices.rb
|
|
112
129
|
- db/seed/requests.rb
|
|
130
|
+
- db/seed/traffic.rb
|
|
113
131
|
- db/seed/users.rb
|
|
114
132
|
- db/seeds.rb
|
|
115
133
|
- db/version_structure.rb
|
|
116
134
|
- lib/lesli_audit.rb
|
|
117
135
|
- lib/lesli_audit/engine.rb
|
|
118
136
|
- lib/lesli_audit/version.rb
|
|
137
|
+
- lib/tasks/lesli_audit_cloudflare_traffic.rake
|
|
119
138
|
- lib/tasks/lesli_audit_tasks.rake
|
|
120
139
|
- license
|
|
121
140
|
- readme.md
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module LesliAudit
|
|
2
|
-
class VisitorsController < ApplicationController
|
|
3
|
-
|
|
4
|
-
# GET /analytics
|
|
5
|
-
def index
|
|
6
|
-
@visits = VisitorService.new(current_user, query).visits
|
|
7
|
-
@traffic = VisitorService.new(current_user, query).traffic
|
|
8
|
-
@requests = VisitorService.new(current_user, query).requests
|
|
9
|
-
@browsers = VisitorService.new(current_user, query).browsers
|
|
10
|
-
@devices = VisitorService.new(current_user, query).devices
|
|
11
|
-
@os = VisitorService.new(current_user, query).os
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|