line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DMARC::Report::Store::SQL::Grammars::MySQL; |
2
|
|
|
|
|
|
|
our $VERSION = '1.20230215'; |
3
|
4
|
|
|
4
|
|
32
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
139
|
|
4
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
4760
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
8
|
0
|
|
|
|
|
|
my $self = { }; |
9
|
0
|
|
|
|
|
|
bless $self, $class; |
10
|
0
|
|
|
|
|
|
return $self; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub language { |
14
|
0
|
|
|
0
|
0
|
|
return 'mysql'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dsn { |
18
|
0
|
|
|
0
|
0
|
|
return 'mysql'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub and_arg { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $column, $operator) = @_; |
23
|
0
|
|
0
|
|
|
|
$operator //= '='; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return " AND $column $operator ?"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub report_record_id { |
29
|
0
|
|
|
0
|
0
|
|
return 'SELECT id FROM report_record WHERE report_id=?'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub delete_from_where_record_in { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $table) = @_; |
34
|
0
|
|
|
|
|
|
return "DELETE FROM $table WHERE report_record_id IN (??)" |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub delete_from_where_report { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $table) = @_; |
39
|
0
|
|
|
|
|
|
return "DELETE FROM $table WHERE report_id=?"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub delete_report { |
43
|
0
|
|
|
0
|
0
|
|
return "DELETE FROM report WHERE id=?"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub select_domain_id { |
47
|
0
|
|
|
0
|
0
|
|
return 'SELECT id FROM domain WHERE domain=?'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub insert_domain { |
51
|
0
|
|
|
0
|
0
|
|
return 'INSERT INTO domain (domain) VALUES (?)'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub select_author_id { |
55
|
0
|
|
|
0
|
0
|
|
return 'SELECT id FROM author WHERE org_name=?'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub insert_author { |
59
|
0
|
|
|
0
|
0
|
|
return 'INSERT INTO author (org_name,email,extra_contact) VALUES (?,?,?)'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub select_report_id { |
63
|
0
|
|
|
0
|
0
|
|
return 'SELECT id FROM report WHERE uuid=? AND author_id=?'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub select_id_with_end { |
67
|
0
|
|
|
0
|
0
|
|
return 'SELECT id FROM report WHERE from_domain_id=? AND end > ? AND author_id=?'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub insert_report { |
71
|
0
|
|
|
0
|
0
|
|
return 'INSERT INTO report (from_domain_id, begin, end, author_id, uuid) VALUES (?,?,?,?,?)'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub order_by { |
75
|
0
|
|
|
0
|
0
|
|
my ($self, $arg, $order) = @_; |
76
|
0
|
|
|
|
|
|
return " ORDER BY $arg $order"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub count_reports { |
80
|
0
|
|
|
0
|
0
|
|
return 'SELECT COUNT(*) FROM report'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub limit { |
84
|
0
|
|
|
0
|
0
|
|
my ($self, $number_of_entries) = @_; |
85
|
0
|
|
0
|
|
|
|
$number_of_entries //= 1; |
86
|
0
|
|
|
|
|
|
return " LIMIT $number_of_entries"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub limit_args { |
90
|
0
|
|
|
0
|
0
|
|
my ($self, $number_of_entries) = @_; |
91
|
0
|
|
|
|
|
|
my $return = ' LIMIT '; |
92
|
0
|
|
0
|
|
|
|
$number_of_entries //= 1; |
93
|
0
|
|
|
|
|
|
for (my $i = 1; $i <= $number_of_entries; $i++) { |
94
|
0
|
|
|
|
|
|
$return .= '?'; |
95
|
0
|
0
|
|
|
|
|
$return .= ',' if $i < $number_of_entries; |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
return $return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub select_report_policy_published { |
101
|
0
|
|
|
0
|
0
|
|
return 'SELECT * from report_policy_published WHERE report_id=?'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub select_report_reason { |
105
|
0
|
|
|
0
|
0
|
|
return 'SELECT type,comment FROM report_record_reason WHERE report_record_id=?'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub select_report_error { |
109
|
0
|
|
|
0
|
0
|
|
return 'SELECT error FROM report_error WHERE report_id=?'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub select_report_record { |
113
|
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
|
0
|
|
|
0
|
0
|
|
; |
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
|
0
|
|
|
0
|
0
|
|
; |
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
|
0
|
|
|
0
|
0
|
|
; |
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
|
0
|
|
|
0
|
0
|
|
; |
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
|
0
|
|
|
0
|
0
|
|
; |
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
|
0
|
|
|
0
|
0
|
|
; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub select_from { |
204
|
0
|
|
|
0
|
0
|
|
my ($self, $columns, $table) = @_; |
205
|
0
|
|
|
|
|
|
my $colStr = join( ', ', @$columns ); |
206
|
0
|
|
|
|
|
|
return "SELECT $colStr FROM $table WHERE 1=1"; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub insert_error { |
210
|
0
|
|
|
0
|
0
|
|
my ( $self, $which ) = @_; |
211
|
0
|
0
|
|
|
|
|
if ( $which == 0 ) { |
212
|
0
|
|
|
|
|
|
return 'UPDATE report SET end=? WHERE id=?'; |
213
|
|
|
|
|
|
|
} else { |
214
|
0
|
|
|
|
|
|
return 'INSERT INTO report_error (report_id, error) VALUES (?,?)'; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub insert_rr_reason { |
219
|
0
|
|
|
0
|
0
|
|
return 'INSERT INTO report_record_reason (report_record_id, type, comment) VALUES (?,?,?)' |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub insert_rr_dkim { |
223
|
0
|
|
|
0
|
0
|
|
my ( $self, $fields ) = @_; |
224
|
0
|
|
|
|
|
|
my $fields_str = join ', ', @$fields; |
225
|
|
|
|
|
|
|
return <<"EO_DKIM" |
226
|
|
|
|
|
|
|
INSERT INTO report_record_dkim |
227
|
|
|
|
|
|
|
(report_record_id, $fields_str) |
228
|
|
|
|
|
|
|
VALUES (??) |
229
|
|
|
|
|
|
|
EO_DKIM |
230
|
0
|
|
|
|
|
|
; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub insert_rr_spf { |
234
|
0
|
|
|
0
|
0
|
|
my ( $self, $fields ) = @_; |
235
|
0
|
|
|
|
|
|
my $fields_str = join ', ', @$fields; |
236
|
0
|
|
|
|
|
|
return "INSERT INTO report_record_spf (report_record_id, $fields_str) VALUES(??)"; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub insert_rr { |
240
|
|
|
|
|
|
|
return <<'EO_ROW_INSERT' |
241
|
|
|
|
|
|
|
INSERT INTO report_record |
242
|
|
|
|
|
|
|
(report_id, source_ip, count, header_from_did, envelope_to_did, envelope_from_did, |
243
|
|
|
|
|
|
|
disposition, dkim, spf) |
244
|
|
|
|
|
|
|
VALUES (??) |
245
|
|
|
|
|
|
|
EO_ROW_INSERT |
246
|
0
|
|
|
0
|
0
|
|
; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub insert_policy_published { |
250
|
|
|
|
|
|
|
return <<"EO_RPP" |
251
|
|
|
|
|
|
|
INSERT INTO report_policy_published |
252
|
|
|
|
|
|
|
(report_id, adkim, aspf, p, sp, pct, rua) |
253
|
|
|
|
|
|
|
VALUES (??) |
254
|
|
|
|
|
|
|
EO_RPP |
255
|
0
|
|
|
0
|
0
|
|
; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub insert_into { |
259
|
0
|
|
|
0
|
0
|
|
my ($self, $table, $cols) = @_; |
260
|
0
|
|
|
|
|
|
my $columns = join ', ', @$cols; |
261
|
0
|
|
|
|
|
|
return "INSERT INTO $table ($columns) VALUES (??)"; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub replace_into { |
265
|
0
|
|
|
0
|
0
|
|
my ($self, $table, $cols) = @_; |
266
|
0
|
|
|
|
|
|
my $columns = join ', ', @$cols; |
267
|
0
|
|
|
|
|
|
return "REPLACE INTO $table ($columns) VALUES (??)"; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub update { |
271
|
0
|
|
|
0
|
0
|
|
my ($self, $table, $cols) = @_; |
272
|
0
|
|
|
|
|
|
my $columns = join( ' = ?, ') . ' = ?'; |
273
|
0
|
|
|
|
|
|
return "UPDATE $table SET $columns WHERE 1=1"; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub delete_from { |
277
|
0
|
|
|
0
|
0
|
|
my ($self, $table) = @_; |
278
|
0
|
|
|
|
|
|
return "DELETE FROM $table WHERE 1=1"; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |