line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DMARC::Report::Store::SQL::Grammars::SQLite; |
2
|
|
|
|
|
|
|
our $VERSION = '1.20210927'; |
3
|
4
|
|
|
4
|
|
28
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
124
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
4793
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
10
|
|
|
10
|
0
|
35
|
my $class = shift; |
8
|
10
|
|
|
|
|
25
|
my $self = { }; |
9
|
10
|
|
|
|
|
22
|
bless $self, $class; |
10
|
10
|
|
|
|
|
34
|
return $self; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub language { |
14
|
26
|
|
|
26
|
0
|
199
|
return 'sqlite'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dsn { |
18
|
621
|
|
|
621
|
0
|
1438
|
return 'SQLite'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub and_arg { |
22
|
16
|
|
|
16
|
0
|
44
|
my ($self, $column, $operator) = @_; |
23
|
16
|
|
100
|
|
|
81
|
$operator //= '='; |
24
|
|
|
|
|
|
|
|
25
|
16
|
|
|
|
|
97
|
return " AND $column $operator ?"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub report_record_id { |
29
|
8
|
|
|
8
|
0
|
41
|
return 'SELECT id FROM report_record WHERE report_id=?'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub delete_from_where_record_in { |
33
|
12
|
|
|
12
|
0
|
31
|
my ($self, $table) = @_; |
34
|
12
|
|
|
|
|
54
|
return "DELETE FROM $table WHERE report_record_id IN (??)" |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub delete_from_where_report { |
38
|
24
|
|
|
24
|
0
|
72
|
my ($self, $table) = @_; |
39
|
24
|
|
|
|
|
106
|
return "DELETE FROM $table WHERE report_id=?"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub delete_report { |
43
|
8
|
|
|
8
|
0
|
37
|
return "DELETE FROM report WHERE id=?"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub select_domain_id { |
47
|
48
|
|
|
48
|
0
|
244
|
return 'SELECT id FROM domain WHERE domain=?'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub insert_domain { |
51
|
22
|
|
|
22
|
0
|
134
|
return 'INSERT INTO domain (domain) VALUES (?)'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub select_author_id { |
55
|
12
|
|
|
12
|
0
|
49
|
return 'SELECT id FROM author WHERE org_name=?'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub insert_author { |
59
|
9
|
|
|
9
|
0
|
114
|
return 'INSERT INTO author (org_name,email,extra_contact) VALUES (?,?,?)'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub select_report_id { |
63
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT id FROM report WHERE uuid=? AND author_id=?'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub select_id_with_end { |
67
|
9
|
|
|
9
|
0
|
104
|
return 'SELECT id FROM report WHERE from_domain_id=? AND end > ? AND author_id=?'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub insert_report { |
71
|
9
|
|
|
9
|
0
|
53
|
return 'INSERT INTO report (from_domain_id, begin, end, author_id, uuid) VALUES (?,?,?,?,?)'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub order_by { |
75
|
0
|
|
|
0
|
0
|
0
|
my ($self, $arg, $order) = @_; |
76
|
0
|
|
|
|
|
0
|
return " ORDER BY $arg $order"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub count_reports { |
80
|
4
|
|
|
4
|
0
|
20
|
return 'SELECT COUNT(*) FROM report'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub limit { |
84
|
2
|
|
|
2
|
0
|
5
|
my ($self, $number_of_entries) = @_; |
85
|
2
|
|
100
|
|
|
9
|
$number_of_entries //= 1; |
86
|
2
|
|
|
|
|
10
|
return " LIMIT $number_of_entries"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub limit_args { |
90
|
1
|
|
|
1
|
0
|
4
|
my ($self, $number_of_entries) = @_; |
91
|
1
|
|
|
|
|
2
|
my $return = ' LIMIT '; |
92
|
1
|
|
50
|
|
|
7
|
$number_of_entries //= 1; |
93
|
1
|
|
|
|
|
4
|
for (my $i = 1; $i <= $number_of_entries; $i++) { |
94
|
1
|
|
|
|
|
3
|
$return .= '?'; |
95
|
1
|
50
|
|
|
|
6
|
$return .= ',' if $i < $number_of_entries; |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
4
|
return $return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub select_report_policy_published { |
101
|
6
|
|
|
6
|
0
|
31
|
return 'SELECT * from report_policy_published WHERE report_id=?'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub select_report_reason { |
105
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT type,comment FROM report_record_reason WHERE report_record_id=?'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub select_report_error { |
109
|
6
|
|
|
6
|
0
|
31
|
return 'SELECT error FROM report_error WHERE report_id=?'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub select_report_record { |
113
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT id FROM report_record WHERE report_id=? AND source_ip=? AND count=?' |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub select_todo_query { |
117
|
|
|
|
|
|
|
return <<'EO_TODO_QUERY' |
118
|
|
|
|
|
|
|
SELECT r.id AS rid, |
119
|
|
|
|
|
|
|
r.begin AS begin, |
120
|
|
|
|
|
|
|
r.end AS end, |
121
|
|
|
|
|
|
|
a.org_name AS author, |
122
|
|
|
|
|
|
|
fd.domain AS from_domain |
123
|
|
|
|
|
|
|
FROM report r |
124
|
|
|
|
|
|
|
LEFT JOIN report_record rr ON r.id=rr.report_id |
125
|
|
|
|
|
|
|
LEFT JOIN author a ON r.author_id=a.id |
126
|
|
|
|
|
|
|
LEFT JOIN domain fd ON r.from_domain_id=fd.id |
127
|
|
|
|
|
|
|
WHERE rr.count IS NULL |
128
|
|
|
|
|
|
|
AND rr.report_id IS NOT NULL |
129
|
|
|
|
|
|
|
AND r.end < ? |
130
|
|
|
|
|
|
|
GROUP BY r.id |
131
|
|
|
|
|
|
|
ORDER BY r.id ASC |
132
|
|
|
|
|
|
|
EO_TODO_QUERY |
133
|
5
|
|
|
5
|
0
|
31
|
; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub select_row_spf { |
137
|
|
|
|
|
|
|
return <<"EO_SPF_ROW" |
138
|
|
|
|
|
|
|
SELECT d.domain AS domain, |
139
|
|
|
|
|
|
|
s.result AS result, |
140
|
|
|
|
|
|
|
s.scope AS scope |
141
|
|
|
|
|
|
|
FROM report_record_spf s |
142
|
|
|
|
|
|
|
LEFT JOIN domain d ON s.domain_id=d.id |
143
|
|
|
|
|
|
|
WHERE s.report_record_id=? |
144
|
|
|
|
|
|
|
EO_SPF_ROW |
145
|
7
|
|
|
7
|
0
|
32
|
; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub select_row_dkim { |
150
|
|
|
|
|
|
|
return <<"EO_DKIM_ROW" |
151
|
|
|
|
|
|
|
SELECT d.domain AS domain, |
152
|
|
|
|
|
|
|
k.selector AS selector, |
153
|
|
|
|
|
|
|
k.result AS result, |
154
|
|
|
|
|
|
|
k.human_result AS human_result |
155
|
|
|
|
|
|
|
FROM report_record_dkim k |
156
|
|
|
|
|
|
|
LEFT JOIN domain d ON k.domain_id=d.id |
157
|
|
|
|
|
|
|
WHERE report_record_id=? |
158
|
|
|
|
|
|
|
EO_DKIM_ROW |
159
|
7
|
|
|
7
|
0
|
29
|
; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub select_row_reason { |
163
|
|
|
|
|
|
|
return <<"EO_ROW_QUERY" |
164
|
|
|
|
|
|
|
SELECT type,comment |
165
|
|
|
|
|
|
|
FROM report_record_reason |
166
|
|
|
|
|
|
|
WHERE report_record_id=? |
167
|
|
|
|
|
|
|
EO_ROW_QUERY |
168
|
7
|
|
|
7
|
0
|
30
|
; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub select_rr_query { |
172
|
|
|
|
|
|
|
return <<'EO_ROW_QUERY' |
173
|
|
|
|
|
|
|
SELECT rr.*, |
174
|
|
|
|
|
|
|
etd.domain AS envelope_to, |
175
|
|
|
|
|
|
|
efd.domain AS envelope_from, |
176
|
|
|
|
|
|
|
hfd.domain AS header_from |
177
|
|
|
|
|
|
|
FROM report_record rr |
178
|
|
|
|
|
|
|
LEFT JOIN domain etd ON etd.id=rr.envelope_to_did |
179
|
|
|
|
|
|
|
LEFT JOIN domain efd ON efd.id=rr.envelope_from_did |
180
|
|
|
|
|
|
|
LEFT JOIN domain hfd ON hfd.id=rr.header_from_did |
181
|
|
|
|
|
|
|
WHERE report_id = ? |
182
|
|
|
|
|
|
|
ORDER BY id ASC |
183
|
|
|
|
|
|
|
EO_ROW_QUERY |
184
|
6
|
|
|
6
|
0
|
24
|
; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub select_report_query { |
188
|
|
|
|
|
|
|
return <<'EO_REPORTS' |
189
|
|
|
|
|
|
|
SELECT r.id AS rid, |
190
|
|
|
|
|
|
|
r.uuid, |
191
|
|
|
|
|
|
|
r.begin AS begin, |
192
|
|
|
|
|
|
|
r.end AS end, |
193
|
|
|
|
|
|
|
a.org_name AS author, |
194
|
|
|
|
|
|
|
fd.domain AS from_domain |
195
|
|
|
|
|
|
|
FROM report r |
196
|
|
|
|
|
|
|
LEFT JOIN author a ON r.author_id=a.id |
197
|
|
|
|
|
|
|
LEFT JOIN domain fd ON r.from_domain_id=fd.id |
198
|
|
|
|
|
|
|
WHERE 1=1 |
199
|
|
|
|
|
|
|
EO_REPORTS |
200
|
10
|
|
|
10
|
0
|
24
|
; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub insert_error { |
204
|
2
|
|
|
2
|
0
|
8
|
my ( $self, $which ) = @_; |
205
|
2
|
100
|
|
|
|
13
|
if ( $which == 0 ) { |
206
|
1
|
|
|
|
|
6
|
return 'UPDATE report SET end=? WHERE id=?'; |
207
|
|
|
|
|
|
|
} else { |
208
|
1
|
|
|
|
|
8
|
return 'INSERT INTO report_error (report_id, error) VALUES (?,?)'; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub insert_rr_reason { |
213
|
8
|
|
|
8
|
0
|
65
|
return 'INSERT INTO report_record_reason (report_record_id, type, comment) VALUES (?,?,?)' |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub insert_rr_dkim { |
217
|
8
|
|
|
8
|
0
|
29
|
my ( $self, $fields ) = @_; |
218
|
8
|
|
|
|
|
32
|
my $fields_str = join ', ', @$fields; |
219
|
|
|
|
|
|
|
return <<"EO_DKIM" |
220
|
|
|
|
|
|
|
INSERT INTO report_record_dkim |
221
|
|
|
|
|
|
|
(report_record_id, $fields_str) |
222
|
|
|
|
|
|
|
VALUES (??) |
223
|
|
|
|
|
|
|
EO_DKIM |
224
|
8
|
|
|
|
|
39
|
; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub insert_rr_spf { |
228
|
13
|
|
|
13
|
0
|
47
|
my ( $self, $fields ) = @_; |
229
|
13
|
|
|
|
|
73
|
my $fields_str = join ', ', @$fields; |
230
|
13
|
|
|
|
|
79
|
return "INSERT INTO report_record_spf (report_record_id, $fields_str) VALUES(??)"; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub insert_rr { |
234
|
|
|
|
|
|
|
return <<'EO_ROW_INSERT' |
235
|
|
|
|
|
|
|
INSERT INTO report_record |
236
|
|
|
|
|
|
|
(report_id, source_ip, count, header_from_did, envelope_to_did, envelope_from_did, |
237
|
|
|
|
|
|
|
disposition, dkim, spf) |
238
|
|
|
|
|
|
|
VALUES (??) |
239
|
|
|
|
|
|
|
EO_ROW_INSERT |
240
|
6
|
|
|
6
|
0
|
25
|
; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub insert_policy_published { |
244
|
|
|
|
|
|
|
return <<"EO_RPP" |
245
|
|
|
|
|
|
|
INSERT INTO report_policy_published |
246
|
|
|
|
|
|
|
(report_id, adkim, aspf, p, sp, pct, rua) |
247
|
|
|
|
|
|
|
VALUES (??) |
248
|
|
|
|
|
|
|
EO_RPP |
249
|
10
|
|
|
10
|
0
|
50
|
; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub select_from { |
253
|
9
|
|
|
9
|
0
|
34
|
my ($self, $columns, $table) = @_; |
254
|
9
|
|
|
|
|
37
|
my $colStr = join( ', ', @$columns ); |
255
|
9
|
|
|
|
|
48
|
return "SELECT $colStr FROM $table WHERE 1=1"; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub insert_into { |
259
|
8
|
|
|
8
|
0
|
28
|
my ($self, $table, $cols) = @_; |
260
|
8
|
|
|
|
|
37
|
my $columns = join ', ', @$cols; |
261
|
8
|
|
|
|
|
98
|
return "INSERT INTO $table ($columns) VALUES (??)"; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub update { |
265
|
0
|
|
|
0
|
0
|
0
|
my ($self, $table, $cols) = @_; |
266
|
0
|
|
|
|
|
0
|
my $columns = join( ' = ?, ') . ' = ?'; |
267
|
0
|
|
|
|
|
0
|
return "UPDATE $table SET $columns WHERE 1=1"; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub replace_into { |
271
|
1
|
|
|
1
|
0
|
4
|
my ($self, $table, $cols) = @_; |
272
|
1
|
|
|
|
|
6
|
my $columns = join ', ', @$cols; |
273
|
1
|
|
|
|
|
8
|
return "REPLACE INTO $table ($columns) VALUES (??)"; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub delete_from { |
277
|
5
|
|
|
5
|
0
|
16
|
my ($self, $table) = @_; |
278
|
5
|
|
|
|
|
27
|
return "DELETE FROM $table WHERE 1=1"; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |