blob: e781f944ff5eb0fe9fac35ee6f314b5760ead8a6 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2function init_db_schema() {
3 try {
4 global $pdo;
5
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01006 $db_version = "23122022_1445";
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01007
8 $stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
9 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
10 if ($num_results != 0) {
11 $stmt = $pdo->query("SELECT `version` FROM `versions` WHERE `application` = 'db_schema'");
12 if ($stmt->fetch(PDO::FETCH_ASSOC)['version'] == $db_version) {
13 return true;
14 }
15 if (!preg_match('/y|yes/i', getenv('MASTER'))) {
16 $_SESSION['return'][] = array(
17 'type' => 'warning',
18 'log' => array(__FUNCTION__),
19 'msg' => 'Database not initialized: not running db_init on slave.'
20 );
21 return true;
22 }
23 }
24
25 $views = array(
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010026 "grouped_mail_aliases" => "CREATE VIEW grouped_mail_aliases (username, aliases) AS
27 SELECT goto, IFNULL(GROUP_CONCAT(address ORDER BY address SEPARATOR ' '), '') AS address FROM alias
28 WHERE address!=goto
29 AND active = '1'
30 AND sogo_visible = '1'
31 AND address NOT LIKE '@%'
32 GROUP BY goto;",
33 // START
34 // Unused at the moment - we cannot allow to show a foreign mailbox as sender address in SOGo, as SOGo does not like this
35 // We need to create delegation in SOGo AND set a sender_acl in mailcow to allow to send as user X
36 "grouped_sender_acl" => "CREATE VIEW grouped_sender_acl (username, send_as_acl) AS
37 SELECT logged_in_as, IFNULL(GROUP_CONCAT(send_as SEPARATOR ' '), '') AS send_as_acl FROM sender_acl
38 WHERE send_as NOT LIKE '@%'
39 GROUP BY logged_in_as;",
40 // END
41 "grouped_sender_acl_external" => "CREATE VIEW grouped_sender_acl_external (username, send_as_acl) AS
42 SELECT logged_in_as, IFNULL(GROUP_CONCAT(send_as SEPARATOR ' '), '') AS send_as_acl FROM sender_acl
43 WHERE send_as NOT LIKE '@%' AND external = '1'
44 GROUP BY logged_in_as;",
45 "grouped_domain_alias_address" => "CREATE VIEW grouped_domain_alias_address (username, ad_alias) AS
46 SELECT username, IFNULL(GROUP_CONCAT(local_part, '@', alias_domain SEPARATOR ' '), '') AS ad_alias FROM mailbox
47 LEFT OUTER JOIN alias_domain ON target_domain=domain
48 GROUP BY username;",
49 "sieve_before" => "CREATE VIEW sieve_before (id, username, script_name, script_data) AS
50 SELECT md5(script_data), username, script_name, script_data FROM sieve_filters
51 WHERE filter_type = 'prefilter';",
52 "sieve_after" => "CREATE VIEW sieve_after (id, username, script_name, script_data) AS
53 SELECT md5(script_data), username, script_name, script_data FROM sieve_filters
54 WHERE filter_type = 'postfilter';"
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010055 );
56
57 $tables = array(
58 "versions" => array(
59 "cols" => array(
60 "application" => "VARCHAR(255) NOT NULL",
61 "version" => "VARCHAR(100) NOT NULL",
62 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
63 ),
64 "keys" => array(
65 "primary" => array(
66 "" => array("application")
67 )
68 ),
69 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
70 ),
71 "admin" => array(
72 "cols" => array(
73 "username" => "VARCHAR(255) NOT NULL",
74 "password" => "VARCHAR(255) NOT NULL",
75 "superadmin" => "TINYINT(1) NOT NULL DEFAULT '0'",
76 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
77 "modified" => "DATETIME ON UPDATE NOW(0)",
78 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
79 ),
80 "keys" => array(
81 "primary" => array(
82 "" => array("username")
83 )
84 ),
85 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
86 ),
87 "fido2" => array(
88 "cols" => array(
89 "username" => "VARCHAR(255) NOT NULL",
90 "friendlyName" => "VARCHAR(255)",
91 "rpId" => "VARCHAR(255) NOT NULL",
92 "credentialPublicKey" => "TEXT NOT NULL",
93 "certificateChain" => "TEXT",
94 // Can be null for format "none"
95 "certificate" => "TEXT",
96 "certificateIssuer" => "VARCHAR(255)",
97 "certificateSubject" => "VARCHAR(255)",
98 "signatureCounter" => "INT",
99 "AAGUID" => "BLOB",
100 "credentialId" => "BLOB NOT NULL",
101 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
102 "modified" => "DATETIME ON UPDATE NOW(0)",
103 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
104 ),
105 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
106 ),
107 "_sogo_static_view" => array(
108 "cols" => array(
109 "c_uid" => "VARCHAR(255) NOT NULL",
110 "domain" => "VARCHAR(255) NOT NULL",
111 "c_name" => "VARCHAR(255) NOT NULL",
112 "c_password" => "VARCHAR(255) NOT NULL DEFAULT ''",
113 "c_cn" => "VARCHAR(255)",
114 "mail" => "VARCHAR(255) NOT NULL",
115 // TODO -> use TEXT and check if SOGo login breaks on empty aliases
116 "aliases" => "TEXT NOT NULL",
117 "ad_aliases" => "VARCHAR(6144) NOT NULL DEFAULT ''",
118 "ext_acl" => "VARCHAR(6144) NOT NULL DEFAULT ''",
119 "kind" => "VARCHAR(100) NOT NULL DEFAULT ''",
120 "multiple_bookings" => "INT NOT NULL DEFAULT -1"
121 ),
122 "keys" => array(
123 "primary" => array(
124 "" => array("c_uid")
125 ),
126 "key" => array(
127 "domain" => array("domain")
128 )
129 ),
130 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
131 ),
132 "relayhosts" => array(
133 "cols" => array(
134 "id" => "INT NOT NULL AUTO_INCREMENT",
135 "hostname" => "VARCHAR(255) NOT NULL",
136 "username" => "VARCHAR(255) NOT NULL",
137 "password" => "VARCHAR(255) NOT NULL",
138 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
139 ),
140 "keys" => array(
141 "primary" => array(
142 "" => array("id")
143 ),
144 "key" => array(
145 "hostname" => array("hostname")
146 )
147 ),
148 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
149 ),
150 "transports" => array(
151 "cols" => array(
152 "id" => "INT NOT NULL AUTO_INCREMENT",
153 "destination" => "VARCHAR(255) NOT NULL",
154 "nexthop" => "VARCHAR(255) NOT NULL",
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200155 "username" => "VARCHAR(255) NOT NULL DEFAULT ''",
156 "password" => "VARCHAR(255) NOT NULL DEFAULT ''",
157 "is_mx_based" => "TINYINT(1) NOT NULL DEFAULT '0'",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100158 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
159 ),
160 "keys" => array(
161 "primary" => array(
162 "" => array("id")
163 ),
164 "key" => array(
165 "destination" => array("destination"),
166 "nexthop" => array("nexthop"),
167 )
168 ),
169 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
170 ),
171 "alias" => array(
172 "cols" => array(
173 "id" => "INT NOT NULL AUTO_INCREMENT",
174 "address" => "VARCHAR(255) NOT NULL",
175 "goto" => "TEXT NOT NULL",
176 "domain" => "VARCHAR(255) NOT NULL",
177 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
178 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
179 "private_comment" => "TEXT",
180 "public_comment" => "TEXT",
181 "sogo_visible" => "TINYINT(1) NOT NULL DEFAULT '1'",
182 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
183 ),
184 "keys" => array(
185 "primary" => array(
186 "" => array("id")
187 ),
188 "unique" => array(
189 "address" => array("address")
190 ),
191 "key" => array(
192 "domain" => array("domain")
193 )
194 ),
195 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
196 ),
197 "api" => array(
198 "cols" => array(
199 "api_key" => "VARCHAR(255) NOT NULL",
200 "allow_from" => "VARCHAR(512) NOT NULL",
201 "skip_ip_check" => "TINYINT(1) NOT NULL DEFAULT '0'",
202 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
203 "modified" => "DATETIME ON UPDATE NOW(0)",
204 "access" => "ENUM('ro', 'rw') NOT NULL DEFAULT 'rw'",
205 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
206 ),
207 "keys" => array(
208 "primary" => array(
209 "" => array("api_key")
210 ),
211 ),
212 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
213 ),
214 "sender_acl" => array(
215 "cols" => array(
216 "id" => "INT NOT NULL AUTO_INCREMENT",
217 "logged_in_as" => "VARCHAR(255) NOT NULL",
218 "send_as" => "VARCHAR(255) NOT NULL",
219 "external" => "TINYINT(1) NOT NULL DEFAULT '0'"
220 ),
221 "keys" => array(
222 "primary" => array(
223 "" => array("id")
224 )
225 ),
226 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
227 ),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100228 "templates" => array(
229 "cols" => array(
230 "id" => "INT NOT NULL AUTO_INCREMENT",
231 "template" => "VARCHAR(255) NOT NULL",
232 "type" => "VARCHAR(255) NOT NULL",
233 "attributes" => "JSON",
234 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
235 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP"
236 ),
237 "keys" => array(
238 "primary" => array(
239 "" => array("id")
240 )
241 ),
242 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
243 ),
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100244 "domain" => array(
245 // Todo: Move some attributes to json
246 "cols" => array(
247 "domain" => "VARCHAR(255) NOT NULL",
248 "description" => "VARCHAR(255)",
249 "aliases" => "INT(10) NOT NULL DEFAULT '0'",
250 "mailboxes" => "INT(10) NOT NULL DEFAULT '0'",
251 "defquota" => "BIGINT(20) NOT NULL DEFAULT '3072'",
252 "maxquota" => "BIGINT(20) NOT NULL DEFAULT '102400'",
253 "quota" => "BIGINT(20) NOT NULL DEFAULT '102400'",
254 "relayhost" => "VARCHAR(255) NOT NULL DEFAULT '0'",
255 "backupmx" => "TINYINT(1) NOT NULL DEFAULT '0'",
256 "gal" => "TINYINT(1) NOT NULL DEFAULT '1'",
257 "relay_all_recipients" => "TINYINT(1) NOT NULL DEFAULT '0'",
258 "relay_unknown_only" => "TINYINT(1) NOT NULL DEFAULT '0'",
259 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
260 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
261 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
262 ),
263 "keys" => array(
264 "primary" => array(
265 "" => array("domain")
266 )
267 ),
268 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
269 ),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100270 "tags_domain" => array(
271 "cols" => array(
272 "tag_name" => "VARCHAR(255) NOT NULL",
273 "domain" => "VARCHAR(255) NOT NULL"
274 ),
275 "keys" => array(
276 "fkey" => array(
277 "fk_tags_domain" => array(
278 "col" => "domain",
279 "ref" => "domain.domain",
280 "delete" => "CASCADE",
281 "update" => "NO ACTION"
282 )
283 ),
284 "unique" => array(
285 "tag_name" => array("tag_name", "domain")
286 )
287 ),
288 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
289 ),
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100290 "tls_policy_override" => array(
291 "cols" => array(
292 "id" => "INT NOT NULL AUTO_INCREMENT",
293 "dest" => "VARCHAR(255) NOT NULL",
294 "policy" => "ENUM('none', 'may', 'encrypt', 'dane', 'dane-only', 'fingerprint', 'verify', 'secure') NOT NULL",
295 "parameters" => "VARCHAR(255) DEFAULT ''",
296 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
297 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
298 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
299 ),
300 "keys" => array(
301 "primary" => array(
302 "" => array("id")
303 ),
304 "unique" => array(
305 "dest" => array("dest")
306 ),
307 ),
308 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
309 ),
310 "quarantine" => array(
311 "cols" => array(
312 "id" => "INT NOT NULL AUTO_INCREMENT",
313 "qid" => "VARCHAR(30) NOT NULL",
314 "subject" => "VARCHAR(500)",
315 "score" => "FLOAT(8,2)",
316 "ip" => "VARCHAR(50)",
317 "action" => "CHAR(20) NOT NULL DEFAULT 'unknown'",
318 "symbols" => "JSON",
319 "fuzzy_hashes" => "JSON",
320 "sender" => "VARCHAR(255) NOT NULL DEFAULT 'unknown'",
321 "rcpt" => "VARCHAR(255)",
322 "msg" => "LONGTEXT",
323 "domain" => "VARCHAR(255)",
324 "notified" => "TINYINT(1) NOT NULL DEFAULT '0'",
325 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
326 "user" => "VARCHAR(255) NOT NULL DEFAULT 'unknown'",
327 ),
328 "keys" => array(
329 "primary" => array(
330 "" => array("id")
331 )
332 ),
333 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
334 ),
335 "mailbox" => array(
336 "cols" => array(
337 "username" => "VARCHAR(255) NOT NULL",
338 "password" => "VARCHAR(255) NOT NULL",
339 "name" => "VARCHAR(255)",
340 "description" => "VARCHAR(255)",
341 // mailbox_path_prefix is followed by domain/local_part/
342 "mailbox_path_prefix" => "VARCHAR(150) DEFAULT '/var/vmail/'",
343 "quota" => "BIGINT(20) NOT NULL DEFAULT '102400'",
344 "local_part" => "VARCHAR(255) NOT NULL",
345 "domain" => "VARCHAR(255) NOT NULL",
346 "attributes" => "JSON",
347 "kind" => "VARCHAR(100) NOT NULL DEFAULT ''",
348 "multiple_bookings" => "INT NOT NULL DEFAULT -1",
349 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
350 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
351 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
352 ),
353 "keys" => array(
354 "primary" => array(
355 "" => array("username")
356 ),
357 "key" => array(
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200358 "domain" => array("domain"),
359 "kind" => array("kind")
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100360 )
361 ),
362 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
363 ),
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100364 "tags_mailbox" => array(
365 "cols" => array(
366 "tag_name" => "VARCHAR(255) NOT NULL",
367 "username" => "VARCHAR(255) NOT NULL"
368 ),
369 "keys" => array(
370 "fkey" => array(
371 "fk_tags_mailbox" => array(
372 "col" => "username",
373 "ref" => "mailbox.username",
374 "delete" => "CASCADE",
375 "update" => "NO ACTION"
376 )
377 ),
378 "unique" => array(
379 "tag_name" => array("tag_name", "username")
380 )
381 ),
382 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
383 ),
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100384 "sieve_filters" => array(
385 "cols" => array(
386 "id" => "INT NOT NULL AUTO_INCREMENT",
387 "username" => "VARCHAR(255) NOT NULL",
388 "script_desc" => "VARCHAR(255) NOT NULL",
389 "script_name" => "ENUM('active','inactive')",
390 "script_data" => "TEXT NOT NULL",
391 "filter_type" => "ENUM('postfilter','prefilter')",
392 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
393 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP"
394 ),
395 "keys" => array(
396 "primary" => array(
397 "" => array("id")
398 ),
399 "key" => array(
400 "username" => array("username"),
401 "script_desc" => array("script_desc")
402 ),
403 "fkey" => array(
404 "fk_username_sieve_global_before" => array(
405 "col" => "username",
406 "ref" => "mailbox.username",
407 "delete" => "CASCADE",
408 "update" => "NO ACTION"
409 )
410 )
411 ),
412 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
413 ),
414 "app_passwd" => array(
415 "cols" => array(
416 "id" => "INT NOT NULL AUTO_INCREMENT",
417 "name" => "VARCHAR(255) NOT NULL",
418 "mailbox" => "VARCHAR(255) NOT NULL",
419 "domain" => "VARCHAR(255) NOT NULL",
420 "password" => "VARCHAR(255) NOT NULL",
421 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
422 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100423 "imap_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
424 "smtp_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
425 "dav_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
426 "eas_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
427 "pop3_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
428 "sieve_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100429 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
430 ),
431 "keys" => array(
432 "primary" => array(
433 "" => array("id")
434 ),
435 "key" => array(
436 "mailbox" => array("mailbox"),
437 "password" => array("password"),
438 "domain" => array("domain"),
439 ),
440 "fkey" => array(
441 "fk_username_app_passwd" => array(
442 "col" => "mailbox",
443 "ref" => "mailbox.username",
444 "delete" => "CASCADE",
445 "update" => "NO ACTION"
446 )
447 )
448 ),
449 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
450 ),
451 "user_acl" => array(
452 "cols" => array(
453 "username" => "VARCHAR(255) NOT NULL",
454 "spam_alias" => "TINYINT(1) NOT NULL DEFAULT '1'",
455 "tls_policy" => "TINYINT(1) NOT NULL DEFAULT '1'",
456 "spam_score" => "TINYINT(1) NOT NULL DEFAULT '1'",
457 "spam_policy" => "TINYINT(1) NOT NULL DEFAULT '1'",
458 "delimiter_action" => "TINYINT(1) NOT NULL DEFAULT '1'",
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100459 "syncjobs" => "TINYINT(1) NOT NULL DEFAULT '0'",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100460 "eas_reset" => "TINYINT(1) NOT NULL DEFAULT '1'",
461 "sogo_profile_reset" => "TINYINT(1) NOT NULL DEFAULT '0'",
462 "pushover" => "TINYINT(1) NOT NULL DEFAULT '1'",
463 // quarantine is for quarantine actions, todo: rename
464 "quarantine" => "TINYINT(1) NOT NULL DEFAULT '1'",
465 "quarantine_attachments" => "TINYINT(1) NOT NULL DEFAULT '1'",
466 "quarantine_notification" => "TINYINT(1) NOT NULL DEFAULT '1'",
467 "quarantine_category" => "TINYINT(1) NOT NULL DEFAULT '1'",
468 "app_passwds" => "TINYINT(1) NOT NULL DEFAULT '1'",
469 ),
470 "keys" => array(
471 "primary" => array(
472 "" => array("username")
473 ),
474 "fkey" => array(
475 "fk_username" => array(
476 "col" => "username",
477 "ref" => "mailbox.username",
478 "delete" => "CASCADE",
479 "update" => "NO ACTION"
480 )
481 )
482 ),
483 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
484 ),
485 "alias_domain" => array(
486 "cols" => array(
487 "alias_domain" => "VARCHAR(255) NOT NULL",
488 "target_domain" => "VARCHAR(255) NOT NULL",
489 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
490 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
491 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
492 ),
493 "keys" => array(
494 "primary" => array(
495 "" => array("alias_domain")
496 ),
497 "key" => array(
498 "active" => array("active"),
499 "target_domain" => array("target_domain")
500 )
501 ),
502 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
503 ),
504 "spamalias" => array(
505 "cols" => array(
506 "address" => "VARCHAR(255) NOT NULL",
507 "goto" => "TEXT NOT NULL",
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200508 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
509 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
510 "validity" => "INT(11)"
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100511 ),
512 "keys" => array(
513 "primary" => array(
514 "" => array("address")
515 ),
516 ),
517 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
518 ),
519 "filterconf" => array(
520 "cols" => array(
521 "object" => "VARCHAR(255) NOT NULL DEFAULT ''",
522 "option" => "VARCHAR(50) NOT NULL DEFAULT ''",
523 "value" => "VARCHAR(100) NOT NULL DEFAULT ''",
524 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
525 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
526 "prefid" => "INT(11) NOT NULL AUTO_INCREMENT"
527 ),
528 "keys" => array(
529 "primary" => array(
530 "" => array("prefid")
531 ),
532 "key" => array(
533 "object" => array("object")
534 )
535 ),
536 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
537 ),
538 "settingsmap" => array(
539 "cols" => array(
540 "id" => "INT NOT NULL AUTO_INCREMENT",
541 "desc" => "VARCHAR(255) NOT NULL",
542 "content" => "LONGTEXT NOT NULL",
543 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
544 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
545 "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
546 ),
547 "keys" => array(
548 "primary" => array(
549 "" => array("id")
550 )
551 ),
552 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
553 ),
554 "logs" => array(
555 "cols" => array(
556 "id" => "INT NOT NULL AUTO_INCREMENT",
557 "task" => "CHAR(32) NOT NULL DEFAULT '000000'",
558 "type" => "VARCHAR(32) DEFAULT ''",
559 "msg" => "TEXT",
560 "call" => "TEXT",
561 "user" => "VARCHAR(64) NOT NULL",
562 "role" => "VARCHAR(32) NOT NULL",
563 "remote" => "VARCHAR(39) NOT NULL",
564 "time" => "INT(11) NOT NULL"
565 ),
566 "keys" => array(
567 "primary" => array(
568 "" => array("id")
569 )
570 ),
571 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
572 ),
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200573 "sasl_log" => array(
574 "cols" => array(
575 "service" => "VARCHAR(32) NOT NULL DEFAULT ''",
576 "app_password" => "INT",
577 "username" => "VARCHAR(255) NOT NULL",
578 "real_rip" => "VARCHAR(64) NOT NULL",
579 "datetime" => "DATETIME(0) NOT NULL DEFAULT NOW(0)"
580 ),
581 "keys" => array(
582 "primary" => array(
583 "" => array("service", "real_rip", "username")
584 ),
585 "key" => array(
586 "username" => array("username"),
587 "service" => array("service"),
588 "datetime" => array("datetime"),
589 "real_rip" => array("real_rip")
590 )
591 ),
592 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
593 ),
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100594 "quota2" => array(
595 "cols" => array(
596 "username" => "VARCHAR(255) NOT NULL",
597 "bytes" => "BIGINT(20) NOT NULL DEFAULT '0'",
598 "messages" => "BIGINT(20) NOT NULL DEFAULT '0'"
599 ),
600 "keys" => array(
601 "primary" => array(
602 "" => array("username")
603 )
604 ),
605 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
606 ),
607 "quota2replica" => array(
608 "cols" => array(
609 "username" => "VARCHAR(255) NOT NULL",
610 "bytes" => "BIGINT(20) NOT NULL DEFAULT '0'",
611 "messages" => "BIGINT(20) NOT NULL DEFAULT '0'"
612 ),
613 "keys" => array(
614 "primary" => array(
615 "" => array("username")
616 )
617 ),
618 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
619 ),
620 "domain_admins" => array(
621 "cols" => array(
622 "id" => "INT NOT NULL AUTO_INCREMENT",
623 "username" => "VARCHAR(255) NOT NULL",
624 "domain" => "VARCHAR(255) NOT NULL",
625 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
626 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
627 ),
628 "keys" => array(
629 "primary" => array(
630 "" => array("id")
631 ),
632 "key" => array(
633 "username" => array("username")
634 )
635 ),
636 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
637 ),
638 "da_acl" => array(
639 "cols" => array(
640 "username" => "VARCHAR(255) NOT NULL",
641 "syncjobs" => "TINYINT(1) NOT NULL DEFAULT '1'",
642 "quarantine" => "TINYINT(1) NOT NULL DEFAULT '1'",
643 "login_as" => "TINYINT(1) NOT NULL DEFAULT '1'",
644 "sogo_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
645 "app_passwds" => "TINYINT(1) NOT NULL DEFAULT '1'",
646 "bcc_maps" => "TINYINT(1) NOT NULL DEFAULT '1'",
647 "pushover" => "TINYINT(1) NOT NULL DEFAULT '0'",
648 "filters" => "TINYINT(1) NOT NULL DEFAULT '1'",
649 "ratelimit" => "TINYINT(1) NOT NULL DEFAULT '1'",
650 "spam_policy" => "TINYINT(1) NOT NULL DEFAULT '1'",
651 "extend_sender_acl" => "TINYINT(1) NOT NULL DEFAULT '0'",
652 "unlimited_quota" => "TINYINT(1) NOT NULL DEFAULT '0'",
653 "protocol_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
654 "smtp_ip_access" => "TINYINT(1) NOT NULL DEFAULT '1'",
655 "alias_domains" => "TINYINT(1) NOT NULL DEFAULT '0'",
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200656 "mailbox_relayhost" => "TINYINT(1) NOT NULL DEFAULT '1'",
657 "domain_relayhost" => "TINYINT(1) NOT NULL DEFAULT '1'",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100658 "domain_desc" => "TINYINT(1) NOT NULL DEFAULT '0'"
659 ),
660 "keys" => array(
661 "primary" => array(
662 "" => array("username")
663 )
664 ),
665 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
666 ),
667 "imapsync" => array(
668 "cols" => array(
669 "id" => "INT NOT NULL AUTO_INCREMENT",
670 "user2" => "VARCHAR(255) NOT NULL",
671 "host1" => "VARCHAR(255) NOT NULL",
672 "authmech1" => "ENUM('PLAIN','LOGIN','CRAM-MD5') DEFAULT 'PLAIN'",
673 "regextrans2" => "VARCHAR(255) DEFAULT ''",
674 "authmd51" => "TINYINT(1) NOT NULL DEFAULT 0",
675 "domain2" => "VARCHAR(255) NOT NULL DEFAULT ''",
676 "subfolder2" => "VARCHAR(255) NOT NULL DEFAULT ''",
677 "user1" => "VARCHAR(255) NOT NULL",
678 "password1" => "VARCHAR(255) NOT NULL",
679 "exclude" => "VARCHAR(500) NOT NULL DEFAULT ''",
680 "maxage" => "SMALLINT NOT NULL DEFAULT '0'",
681 "mins_interval" => "SMALLINT UNSIGNED NOT NULL DEFAULT '0'",
682 "maxbytespersecond" => "VARCHAR(50) NOT NULL DEFAULT '0'",
683 "port1" => "SMALLINT UNSIGNED NOT NULL",
684 "enc1" => "ENUM('TLS','SSL','PLAIN') DEFAULT 'TLS'",
685 "delete2duplicates" => "TINYINT(1) NOT NULL DEFAULT '1'",
686 "delete1" => "TINYINT(1) NOT NULL DEFAULT '0'",
687 "delete2" => "TINYINT(1) NOT NULL DEFAULT '0'",
688 "automap" => "TINYINT(1) NOT NULL DEFAULT '0'",
689 "skipcrossduplicates" => "TINYINT(1) NOT NULL DEFAULT '0'",
690 "custom_params" => "VARCHAR(512) NOT NULL DEFAULT ''",
691 "timeout1" => "SMALLINT NOT NULL DEFAULT '600'",
692 "timeout2" => "SMALLINT NOT NULL DEFAULT '600'",
693 "subscribeall" => "TINYINT(1) NOT NULL DEFAULT '1'",
694 "is_running" => "TINYINT(1) NOT NULL DEFAULT '0'",
695 "returned_text" => "LONGTEXT",
696 "last_run" => "TIMESTAMP NULL DEFAULT NULL",
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100697 "success" => "TINYINT(1) UNSIGNED DEFAULT NULL",
698 "exit_status" => "VARCHAR(50) DEFAULT NULL",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100699 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
700 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
701 "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
702 ),
703 "keys" => array(
704 "primary" => array(
705 "" => array("id")
706 )
707 ),
708 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
709 ),
710 "bcc_maps" => array(
711 "cols" => array(
712 "id" => "INT NOT NULL AUTO_INCREMENT",
713 "local_dest" => "VARCHAR(255) NOT NULL",
714 "bcc_dest" => "VARCHAR(255) NOT NULL",
715 "domain" => "VARCHAR(255) NOT NULL",
716 "type" => "ENUM('sender','rcpt')",
717 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
718 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
719 "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
720 ),
721 "keys" => array(
722 "primary" => array(
723 "" => array("id")
724 ),
725 "key" => array(
726 "local_dest" => array("local_dest"),
727 )
728 ),
729 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
730 ),
731 "recipient_maps" => array(
732 "cols" => array(
733 "id" => "INT NOT NULL AUTO_INCREMENT",
734 "old_dest" => "VARCHAR(255) NOT NULL",
735 "new_dest" => "VARCHAR(255) NOT NULL",
736 "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
737 "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
738 "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
739 ),
740 "keys" => array(
741 "primary" => array(
742 "" => array("id")
743 ),
744 "key" => array(
745 "local_dest" => array("old_dest"),
746 )
747 ),
748 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
749 ),
750 "tfa" => array(
751 "cols" => array(
752 "id" => "INT NOT NULL AUTO_INCREMENT",
753 "key_id" => "VARCHAR(255) NOT NULL",
754 "username" => "VARCHAR(255) NOT NULL",
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100755 "authmech" => "ENUM('yubi_otp', 'u2f', 'hotp', 'totp', 'webauthn')",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100756 "secret" => "VARCHAR(255) DEFAULT NULL",
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100757 "keyHandle" => "VARCHAR(1023) DEFAULT NULL",
758 "publicKey" => "VARCHAR(4096) DEFAULT NULL",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100759 "counter" => "INT NOT NULL DEFAULT '0'",
760 "certificate" => "TEXT",
761 "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
762 ),
763 "keys" => array(
764 "primary" => array(
765 "" => array("id")
766 )
767 ),
768 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
769 ),
770 "forwarding_hosts" => array(
771 "cols" => array(
772 "host" => "VARCHAR(255) NOT NULL",
773 "source" => "VARCHAR(255) NOT NULL",
774 "filter_spam" => "TINYINT(1) NOT NULL DEFAULT '0'"
775 ),
776 "keys" => array(
777 "primary" => array(
778 "" => array("host")
779 ),
780 ),
781 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
782 ),
783 "sogo_acl" => array(
784 "cols" => array(
785 "id" => "INT NOT NULL AUTO_INCREMENT",
786 "c_folder_id" => "INT NOT NULL",
787 "c_object" => "VARCHAR(255) NOT NULL",
788 "c_uid" => "VARCHAR(255) NOT NULL",
789 "c_role" => "VARCHAR(80) NOT NULL"
790 ),
791 "keys" => array(
792 "primary" => array(
793 "" => array("id")
794 ),
795 "key" => array(
796 "sogo_acl_c_folder_id_idx" => array("c_folder_id"),
797 "sogo_acl_c_uid_idx" => array("c_uid")
798 )
799 ),
800 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
801 ),
802 "sogo_alarms_folder" => array(
803 "cols" => array(
804 "id" => "INT NOT NULL AUTO_INCREMENT",
805 "c_path" => "VARCHAR(255) NOT NULL",
806 "c_name" => "VARCHAR(255) NOT NULL",
807 "c_uid" => "VARCHAR(255) NOT NULL",
808 "c_recurrence_id" => "INT(11) DEFAULT NULL",
809 "c_alarm_number" => "INT(11) NOT NULL",
810 "c_alarm_date" => "INT(11) NOT NULL"
811 ),
812 "keys" => array(
813 "primary" => array(
814 "" => array("id")
815 )
816 ),
817 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
818 ),
819 "sogo_cache_folder" => array(
820 "cols" => array(
821 "c_uid" => "VARCHAR(255) NOT NULL",
822 "c_path" => "VARCHAR(255) NOT NULL",
823 "c_parent_path" => "VARCHAR(255) DEFAULT NULL",
824 "c_type" => "TINYINT(3) unsigned NOT NULL",
825 "c_creationdate" => "INT(11) NOT NULL",
826 "c_lastmodified" => "INT(11) NOT NULL",
827 "c_version" => "INT(11) NOT NULL DEFAULT '0'",
828 "c_deleted" => "TINYINT(4) NOT NULL DEFAULT '0'",
829 "c_content" => "LONGTEXT"
830 ),
831 "keys" => array(
832 "primary" => array(
833 "" => array("c_uid", "c_path")
834 ),
835 ),
836 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
837 ),
838 "sogo_folder_info" => array(
839 "cols" => array(
840 "c_folder_id" => "BIGINT(20) unsigned NOT NULL AUTO_INCREMENT",
841 "c_path" => "VARCHAR(255) NOT NULL",
842 "c_path1" => "VARCHAR(255) NOT NULL",
843 "c_path2" => "VARCHAR(255) DEFAULT NULL",
844 "c_path3" => "VARCHAR(255) DEFAULT NULL",
845 "c_path4" => "VARCHAR(255) DEFAULT NULL",
846 "c_foldername" => "VARCHAR(255) NOT NULL",
847 "c_location" => "VARCHAR(2048) DEFAULT NULL",
848 "c_quick_location" => "VARCHAR(2048) DEFAULT NULL",
849 "c_acl_location" => "VARCHAR(2048) DEFAULT NULL",
850 "c_folder_type" => "VARCHAR(255) NOT NULL"
851 ),
852 "keys" => array(
853 "primary" => array(
854 "" => array("c_path")
855 ),
856 "unique" => array(
857 "c_folder_id" => array("c_folder_id")
858 )
859 ),
860 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
861 ),
862 "sogo_quick_appointment" => array(
863 "cols" => array(
864 "c_folder_id" => "INT NOT NULL",
865 "c_name" => "VARCHAR(255) NOT NULL",
866 "c_uid" => "VARCHAR(1000) NOT NULL",
867 "c_startdate" => "INT",
868 "c_enddate" => "INT",
869 "c_cycleenddate" => "INT",
870 "c_title" => "VARCHAR(1000) NOT NULL",
871 "c_participants" => "TEXT",
872 "c_isallday" => "INT",
873 "c_iscycle" => "INT",
874 "c_cycleinfo" => "TEXT",
875 "c_classification" => "INT NOT NULL",
876 "c_isopaque" => "INT NOT NULL",
877 "c_status" => "INT NOT NULL",
878 "c_priority" => "INT",
879 "c_location" => "VARCHAR(255)",
880 "c_orgmail" => "VARCHAR(255)",
881 "c_partmails" => "TEXT",
882 "c_partstates" => "TEXT",
883 "c_category" => "VARCHAR(255)",
884 "c_sequence" => "INT",
885 "c_component" => "VARCHAR(10) NOT NULL",
886 "c_nextalarm" => "INT",
887 "c_description" => "TEXT"
888 ),
889 "keys" => array(
890 "primary" => array(
891 "" => array("c_folder_id", "c_name")
892 )
893 ),
894 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
895 ),
896 "sogo_quick_contact" => array(
897 "cols" => array(
898 "c_folder_id" => "INT NOT NULL",
899 "c_name" => "VARCHAR(255) NOT NULL",
900 "c_givenname" => "VARCHAR(255)",
901 "c_cn" => "VARCHAR(255)",
902 "c_sn" => "VARCHAR(255)",
903 "c_screenname" => "VARCHAR(255)",
904 "c_l" => "VARCHAR(255)",
905 "c_mail" => "TEXT",
906 "c_o" => "VARCHAR(500)",
907 "c_ou" => "VARCHAR(255)",
908 "c_telephonenumber" => "VARCHAR(255)",
909 "c_categories" => "VARCHAR(255)",
910 "c_component" => "VARCHAR(10) NOT NULL",
911 "c_hascertificate" => "INT4 DEFAULT 0"
912 ),
913 "keys" => array(
914 "primary" => array(
915 "" => array("c_folder_id", "c_name")
916 )
917 ),
918 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
919 ),
920 "sogo_sessions_folder" => array(
921 "cols" => array(
922 "c_id" => "VARCHAR(255) NOT NULL",
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100923 "c_value" => "VARCHAR(4096) NOT NULL",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100924 "c_creationdate" => "INT(11) NOT NULL",
925 "c_lastseen" => "INT(11) NOT NULL"
926 ),
927 "keys" => array(
928 "primary" => array(
929 "" => array("c_id")
930 )
931 ),
932 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
933 ),
934 "sogo_store" => array(
935 "cols" => array(
936 "c_folder_id" => "INT NOT NULL",
937 "c_name" => "VARCHAR(255) NOT NULL",
938 "c_content" => "MEDIUMTEXT NOT NULL",
939 "c_creationdate" => "INT NOT NULL",
940 "c_lastmodified" => "INT NOT NULL",
941 "c_version" => "INT NOT NULL",
942 "c_deleted" => "INT"
943 ),
944 "keys" => array(
945 "primary" => array(
946 "" => array("c_folder_id", "c_name")
947 )
948 ),
949 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
950 ),
951 "pushover" => array(
952 "cols" => array(
953 "username" => "VARCHAR(255) NOT NULL",
954 "key" => "VARCHAR(255) NOT NULL",
955 "token" => "VARCHAR(255) NOT NULL",
956 "attributes" => "JSON",
957 "title" => "TEXT",
958 "text" => "TEXT",
959 "senders" => "TEXT",
960 "senders_regex" => "TEXT",
961 "active" => "TINYINT(1) NOT NULL DEFAULT '1'"
962 ),
963 "keys" => array(
964 "primary" => array(
965 "" => array("username")
966 )
967 ),
968 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
969 ),
970 "sogo_user_profile" => array(
971 "cols" => array(
972 "c_uid" => "VARCHAR(255) NOT NULL",
973 "c_defaults" => "LONGTEXT",
974 "c_settings" => "LONGTEXT"
975 ),
976 "keys" => array(
977 "primary" => array(
978 "" => array("c_uid")
979 )
980 ),
981 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
982 ),
983 "oauth_clients" => array(
984 "cols" => array(
985 "id" => "INT NOT NULL AUTO_INCREMENT",
986 "client_id" => "VARCHAR(80) NOT NULL",
987 "client_secret" => "VARCHAR(80)",
988 "redirect_uri" => "VARCHAR(2000)",
989 "grant_types" => "VARCHAR(80)",
990 "scope" => "VARCHAR(4000)",
991 "user_id" => "VARCHAR(80)"
992 ),
993 "keys" => array(
994 "primary" => array(
995 "" => array("client_id")
996 ),
997 "unique" => array(
998 "id" => array("id")
999 )
1000 ),
1001 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
1002 ),
1003 "oauth_access_tokens" => array(
1004 "cols" => array(
1005 "access_token" => "VARCHAR(40) NOT NULL",
1006 "client_id" => "VARCHAR(80) NOT NULL",
1007 "user_id" => "VARCHAR(80)",
1008 "expires" => "TIMESTAMP NOT NULL",
1009 "scope" => "VARCHAR(4000)"
1010 ),
1011 "keys" => array(
1012 "primary" => array(
1013 "" => array("access_token")
1014 )
1015 ),
1016 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
1017 ),
1018 "oauth_authorization_codes" => array(
1019 "cols" => array(
1020 "authorization_code" => "VARCHAR(40) NOT NULL",
1021 "client_id" => "VARCHAR(80) NOT NULL",
1022 "user_id" => "VARCHAR(80)",
1023 "redirect_uri" => "VARCHAR(2000)",
1024 "expires" => "TIMESTAMP NOT NULL",
1025 "scope" => "VARCHAR(4000)",
1026 "id_token" => "VARCHAR(1000)"
1027 ),
1028 "keys" => array(
1029 "primary" => array(
1030 "" => array("authorization_code")
1031 )
1032 ),
1033 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
1034 ),
1035 "oauth_refresh_tokens" => array(
1036 "cols" => array(
1037 "refresh_token" => "VARCHAR(40) NOT NULL",
1038 "client_id" => "VARCHAR(80) NOT NULL",
1039 "user_id" => "VARCHAR(80)",
1040 "expires" => "TIMESTAMP NOT NULL",
1041 "scope" => "VARCHAR(4000)"
1042 ),
1043 "keys" => array(
1044 "primary" => array(
1045 "" => array("refresh_token")
1046 )
1047 ),
1048 "attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
1049 )
1050 );
1051
1052 foreach ($tables as $table => $properties) {
1053 // Migrate to quarantine
1054 if ($table == 'quarantine') {
1055 $stmt = $pdo->query("SHOW TABLES LIKE 'quarantaine'");
1056 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1057 if ($num_results != 0) {
1058 $stmt = $pdo->query("SHOW TABLES LIKE 'quarantine'");
1059 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1060 if ($num_results == 0) {
1061 $pdo->query("RENAME TABLE `quarantaine` TO `quarantine`");
1062 }
1063 }
1064 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001065
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001066 // Migrate tls_enforce_* options
1067 if ($table == 'mailbox') {
1068 $stmt = $pdo->query("SHOW TABLES LIKE 'mailbox'");
1069 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1070 if ($num_results != 0) {
1071 $stmt = $pdo->query("SHOW COLUMNS FROM `mailbox` LIKE '%tls_enforce%'");
1072 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1073 if ($num_results != 0) {
1074 $stmt = $pdo->query("SELECT `username`, `tls_enforce_in`, `tls_enforce_out` FROM `mailbox`");
1075 $tls_options_rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
1076 while ($row = array_shift($tls_options_rows)) {
1077 $tls_options[$row['username']] = array('tls_enforce_in' => $row['tls_enforce_in'], 'tls_enforce_out' => $row['tls_enforce_out']);
1078 }
1079 }
1080 }
1081 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001082
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001083 $stmt = $pdo->query("SHOW TABLES LIKE '" . $table . "'");
1084 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1085 if ($num_results != 0) {
1086 $stmt = $pdo->prepare("SELECT CONCAT('ALTER TABLE ', `table_schema`, '.', `table_name`, ' DROP FOREIGN KEY ', `constraint_name`, ';') AS `FKEY_DROP` FROM `information_schema`.`table_constraints`
1087 WHERE `constraint_type` = 'FOREIGN KEY' AND `table_name` = :table;");
1088 $stmt->execute(array(':table' => $table));
1089 $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
1090 while ($row = array_shift($rows)) {
1091 $pdo->query($row['FKEY_DROP']);
1092 }
1093 foreach($properties['cols'] as $column => $type) {
1094 $stmt = $pdo->query("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "'");
1095 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1096 if ($num_results == 0) {
1097 if (strpos($type, 'AUTO_INCREMENT') !== false) {
1098 $type = $type . ' PRIMARY KEY ';
1099 // Adding an AUTO_INCREMENT key, need to drop primary keys first, if exists
1100 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = 'PRIMARY'");
1101 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1102 if ($num_results != 0) {
1103 $pdo->query("ALTER TABLE `" . $table . "` DROP PRIMARY KEY");
1104 }
1105 }
1106 $pdo->query("ALTER TABLE `" . $table . "` ADD `" . $column . "` " . $type);
1107 }
1108 else {
1109 $pdo->query("ALTER TABLE `" . $table . "` MODIFY COLUMN `" . $column . "` " . $type);
1110 }
1111 }
1112 foreach($properties['keys'] as $key_type => $key_content) {
1113 if (strtolower($key_type) == 'primary') {
1114 foreach ($key_content as $key_values) {
1115 $fields = "`" . implode("`, `", $key_values) . "`";
1116 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = 'PRIMARY'");
1117 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1118 $is_drop = ($num_results != 0) ? "DROP PRIMARY KEY, " : "";
1119 $pdo->query("ALTER TABLE `" . $table . "` " . $is_drop . "ADD PRIMARY KEY (" . $fields . ")");
1120 }
1121 }
1122 if (strtolower($key_type) == 'key') {
1123 foreach ($key_content as $key_name => $key_values) {
1124 $fields = "`" . implode("`, `", $key_values) . "`";
1125 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = '" . $key_name . "'");
1126 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1127 $is_drop = ($num_results != 0) ? "DROP INDEX `" . $key_name . "`, " : "";
1128 $pdo->query("ALTER TABLE `" . $table . "` " . $is_drop . "ADD KEY `" . $key_name . "` (" . $fields . ")");
1129 }
1130 }
1131 if (strtolower($key_type) == 'unique') {
1132 foreach ($key_content as $key_name => $key_values) {
1133 $fields = "`" . implode("`, `", $key_values) . "`";
1134 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = '" . $key_name . "'");
1135 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1136 $is_drop = ($num_results != 0) ? "DROP INDEX `" . $key_name . "`, " : "";
1137 $pdo->query("ALTER TABLE `" . $table . "` " . $is_drop . "ADD UNIQUE KEY `" . $key_name . "` (" . $fields . ")");
1138 }
1139 }
1140 if (strtolower($key_type) == 'fkey') {
1141 foreach ($key_content as $key_name => $key_values) {
1142 $fields = "`" . implode("`, `", $key_values) . "`";
1143 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = '" . $key_name . "'");
1144 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1145 if ($num_results != 0) {
1146 $pdo->query("ALTER TABLE `" . $table . "` DROP INDEX `" . $key_name . "`");
1147 }
1148 @list($table_ref, $field_ref) = explode('.', $key_values['ref']);
1149 $pdo->query("ALTER TABLE `" . $table . "` ADD FOREIGN KEY `" . $key_name . "` (" . $key_values['col'] . ") REFERENCES `" . $table_ref . "` (`" . $field_ref . "`)
1150 ON DELETE " . $key_values['delete'] . " ON UPDATE " . $key_values['update']);
1151 }
1152 }
1153 }
1154 // Drop all vanished columns
1155 $stmt = $pdo->query("SHOW COLUMNS FROM `" . $table . "`");
1156 $cols_in_table = $stmt->fetchAll(PDO::FETCH_ASSOC);
1157 while ($row = array_shift($cols_in_table)) {
1158 if (!array_key_exists($row['Field'], $properties['cols'])) {
1159 $pdo->query("ALTER TABLE `" . $table . "` DROP COLUMN `" . $row['Field'] . "`;");
1160 }
1161 }
1162
1163 // Step 1: Get all non-primary keys, that currently exist and those that should exist
1164 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE `Key_name` != 'PRIMARY'");
1165 $keys_in_table = $stmt->fetchAll(PDO::FETCH_ASSOC);
1166 $keys_to_exist = array();
1167 if (isset($properties['keys']['unique']) && is_array($properties['keys']['unique'])) {
1168 foreach ($properties['keys']['unique'] as $key_name => $key_values) {
1169 $keys_to_exist[] = $key_name;
1170 }
1171 }
1172 if (isset($properties['keys']['key']) && is_array($properties['keys']['key'])) {
1173 foreach ($properties['keys']['key'] as $key_name => $key_values) {
1174 $keys_to_exist[] = $key_name;
1175 }
1176 }
1177 // Index for foreign key must exist
1178 if (isset($properties['keys']['fkey']) && is_array($properties['keys']['fkey'])) {
1179 foreach ($properties['keys']['fkey'] as $key_name => $key_values) {
1180 $keys_to_exist[] = $key_name;
1181 }
1182 }
1183 // Step 2: Drop all vanished indexes
1184 while ($row = array_shift($keys_in_table)) {
1185 if (!in_array($row['Key_name'], $keys_to_exist)) {
1186 $pdo->query("ALTER TABLE `" . $table . "` DROP INDEX `" . $row['Key_name'] . "`");
1187 }
1188 }
1189 // Step 3: Drop all vanished primary keys
1190 if (!isset($properties['keys']['primary'])) {
1191 $stmt = $pdo->query("SHOW KEYS FROM `" . $table . "` WHERE Key_name = 'PRIMARY'");
1192 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1193 if ($num_results != 0) {
1194 $pdo->query("ALTER TABLE `" . $table . "` DROP PRIMARY KEY");
1195 }
1196 }
1197 }
1198 else {
1199 // Create table if it is missing
1200 $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (";
1201 foreach($properties['cols'] as $column => $type) {
1202 $sql .= "`" . $column . "` " . $type . ",";
1203 }
1204 foreach($properties['keys'] as $key_type => $key_content) {
1205 if (strtolower($key_type) == 'primary') {
1206 foreach ($key_content as $key_values) {
1207 $fields = "`" . implode("`, `", $key_values) . "`";
1208 $sql .= "PRIMARY KEY (" . $fields . ")" . ",";
1209 }
1210 }
1211 elseif (strtolower($key_type) == 'key') {
1212 foreach ($key_content as $key_name => $key_values) {
1213 $fields = "`" . implode("`, `", $key_values) . "`";
1214 $sql .= "KEY `" . $key_name . "` (" . $fields . ")" . ",";
1215 }
1216 }
1217 elseif (strtolower($key_type) == 'unique') {
1218 foreach ($key_content as $key_name => $key_values) {
1219 $fields = "`" . implode("`, `", $key_values) . "`";
1220 $sql .= "UNIQUE KEY `" . $key_name . "` (" . $fields . ")" . ",";
1221 }
1222 }
1223 elseif (strtolower($key_type) == 'fkey') {
1224 foreach ($key_content as $key_name => $key_values) {
1225 @list($table_ref, $field_ref) = explode('.', $key_values['ref']);
1226 $sql .= "FOREIGN KEY `" . $key_name . "` (" . $key_values['col'] . ") REFERENCES `" . $table_ref . "` (`" . $field_ref . "`)
1227 ON DELETE " . $key_values['delete'] . " ON UPDATE " . $key_values['update'] . ",";
1228 }
1229 }
1230 }
1231 $sql = rtrim($sql, ",");
1232 $sql .= ") " . $properties['attr'];
1233 $pdo->query($sql);
1234 }
1235 // Reset table attributes
1236 $pdo->query("ALTER TABLE `" . $table . "` " . $properties['attr'] . ";");
1237
1238 }
1239
1240 // Recreate SQL views
1241 foreach ($views as $view => $create) {
1242 $pdo->query("DROP VIEW IF EXISTS `" . $view . "`;");
1243 $pdo->query($create);
1244 }
1245
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001246 // Mitigate imapsync argument injection issue
1247 $pdo->query("UPDATE `imapsync` SET `custom_params` = ''
1248 WHERE `custom_params` LIKE '%pipemess%'
1249 OR custom_params LIKE '%skipmess%'
1250 OR custom_params LIKE '%delete2foldersonly%'
1251 OR custom_params LIKE '%delete2foldersbutnot%'
1252 OR custom_params LIKE '%regexflag%'
1253 OR custom_params LIKE '%pipemess%'
1254 OR custom_params LIKE '%regextrans2%'
1255 OR custom_params LIKE '%maxlinelengthcmd%';");
1256
1257 // Migrate webauthn tfa
1258 $stmt = $pdo->query("ALTER TABLE `tfa` MODIFY COLUMN `authmech` ENUM('yubi_otp', 'u2f', 'hotp', 'totp', 'webauthn')");
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001259
1260 // Inject admin if not exists
1261 $stmt = $pdo->query("SELECT NULL FROM `admin`");
1262 $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
1263 if ($num_results == 0) {
1264 $pdo->query("INSERT INTO `admin` (`username`, `password`, `superadmin`, `created`, `modified`, `active`)
1265 VALUES ('admin', '{SSHA256}K8eVJ6YsZbQCfuJvSUbaQRLr0HPLz5rC9IAp0PAFl0tmNDBkMDc0NDAyOTAxN2Rk', 1, NOW(), NOW(), 1)");
1266 $pdo->query("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
1267 SELECT `username`, 'ALL', NOW(), 1 FROM `admin`
1268 WHERE superadmin='1' AND `username` NOT IN (SELECT `username` FROM `domain_admins`);");
1269 $pdo->query("DELETE FROM `admin` WHERE `username` NOT IN (SELECT `username` FROM `domain_admins`);");
1270 }
1271 // Insert new DB schema version
1272 $pdo->query("REPLACE INTO `versions` (`application`, `version`) VALUES ('db_schema', '" . $db_version . "');");
1273
1274 // Fix dangling domain admins
1275 $pdo->query("DELETE FROM `admin` WHERE `superadmin` = 0 AND `username` NOT IN (SELECT `username`FROM `domain_admins`);");
1276 $pdo->query("DELETE FROM `da_acl` WHERE `username` NOT IN (SELECT `username`FROM `domain_admins`);");
1277
1278 // Migrate attributes
1279 // pushover
1280 $pdo->query("UPDATE `pushover` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;");
1281 $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.evaluate_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.evaluate_x_prio') IS NULL;");
1282 $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.only_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.only_x_prio') IS NULL;");
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001283 $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.sound', \"pushover\") WHERE JSON_VALUE(`attributes`, '$.sound') IS NULL;");
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001284 // mailbox
1285 $pdo->query("UPDATE `mailbox` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;");
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001286 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.passwd_update', \"0\") WHERE JSON_VALUE(`attributes`, '$.passwd_update') IS NULL;");
1287 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.relayhost', \"0\") WHERE JSON_VALUE(`attributes`, '$.relayhost') IS NULL;");
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001288 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.force_pw_update', \"0\") WHERE JSON_VALUE(`attributes`, '$.force_pw_update') IS NULL;");
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001289 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.sieve_access', \"1\") WHERE JSON_VALUE(`attributes`, '$.sieve_access') IS NULL;");
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001290 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.sogo_access', \"1\") WHERE JSON_VALUE(`attributes`, '$.sogo_access') IS NULL;");
1291 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.imap_access', \"1\") WHERE JSON_VALUE(`attributes`, '$.imap_access') IS NULL;");
1292 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.pop3_access', \"1\") WHERE JSON_VALUE(`attributes`, '$.pop3_access') IS NULL;");
1293 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.smtp_access', \"1\") WHERE JSON_VALUE(`attributes`, '$.smtp_access') IS NULL;");
1294 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.mailbox_format', \"maildir:\") WHERE JSON_VALUE(`attributes`, '$.mailbox_format') IS NULL;");
1295 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.quarantine_notification', \"never\") WHERE JSON_VALUE(`attributes`, '$.quarantine_notification') IS NULL;");
1296 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.quarantine_category', \"reject\") WHERE JSON_VALUE(`attributes`, '$.quarantine_category') IS NULL;");
1297 foreach($tls_options as $tls_user => $tls_options) {
1298 $stmt = $pdo->prepare("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_in', :tls_enforce_in),
1299 `attributes` = JSON_SET(`attributes`, '$.tls_enforce_out', :tls_enforce_out)
1300 WHERE `username` = :username");
1301 $stmt->execute(array(':tls_enforce_in' => $tls_options['tls_enforce_in'], ':tls_enforce_out' => $tls_options['tls_enforce_out'], ':username' => $tls_user));
1302 }
1303 // Set tls_enforce_* if still missing (due to deleted attrs for example)
1304 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_out', \"1\") WHERE JSON_VALUE(`attributes`, '$.tls_enforce_out') IS NULL;");
1305 $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_in', \"1\") WHERE JSON_VALUE(`attributes`, '$.tls_enforce_in') IS NULL;");
1306 // Fix ACL
1307 $pdo->query("INSERT INTO `user_acl` (`username`) SELECT `username` FROM `mailbox` WHERE `kind` = '' AND NOT EXISTS (SELECT `username` FROM `user_acl`);");
1308 $pdo->query("INSERT INTO `da_acl` (`username`) SELECT DISTINCT `username` FROM `domain_admins` WHERE `username` != 'admin' AND NOT EXISTS (SELECT `username` FROM `da_acl`);");
1309 // Fix domain_admins
1310 $pdo->query("DELETE FROM `domain_admins` WHERE `domain` = 'ALL';");
1311
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001312 // add default templates
1313 $default_domain_template = array(
1314 "template" => "Default",
1315 "type" => "domain",
1316 "attributes" => array(
1317 "tags" => array(),
1318 "max_num_aliases_for_domain" => 400,
1319 "max_num_mboxes_for_domain" => 10,
1320 "def_quota_for_mbox" => 3072 * 1048576,
1321 "max_quota_for_mbox" => 10240 * 1048576,
1322 "max_quota_for_domain" => 10240 * 1048576,
1323 "rl_frame" => "s",
1324 "rl_value" => "",
1325 "active" => 1,
1326 "gal" => 1,
1327 "backupmx" => 0,
1328 "relay_all_recipients" => 0,
1329 "relay_unknown_only" => 0,
1330 "dkim_selector" => "dkim",
1331 "key_size" => 2048,
1332 "max_quota_for_domain" => 10240 * 1048576,
1333 )
1334 );
1335 $default_mailbox_template = array(
1336 "template" => "Default",
1337 "type" => "mailbox",
1338 "attributes" => array(
1339 "tags" => array(),
1340 "quota" => 0,
1341 "quarantine_notification" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_notification']),
1342 "quarantine_category" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_category']),
1343 "rl_frame" => "s",
1344 "rl_value" => "",
1345 "force_pw_update" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['force_pw_update']),
1346 "sogo_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sogo_access']),
1347 "active" => 1,
1348 "tls_enforce_in" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_in']),
1349 "tls_enforce_out" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_out']),
1350 "imap_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['imap_access']),
1351 "pop3_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['pop3_access']),
1352 "smtp_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['smtp_access']),
1353 "sieve_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sieve_access']),
1354 "acl_spam_alias" => 1,
1355 "acl_tls_policy" => 1,
1356 "acl_spam_score" => 1,
1357 "acl_spam_policy" => 1,
1358 "acl_delimiter_action" => 1,
1359 "acl_syncjobs" => 0,
1360 "acl_eas_reset" => 1,
1361 "acl_sogo_profile_reset" => 0,
1362 "acl_pushover" => 1,
1363 "acl_quarantine" => 1,
1364 "acl_quarantine_attachments" => 1,
1365 "acl_quarantine_notification" => 1,
1366 "acl_quarantine_category" => 1,
1367 "acl_app_passwds" => 1,
1368 )
1369 );
1370 $stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
1371 $stmt->execute(array(
1372 ":type" => "domain",
1373 ":template" => $default_domain_template["template"]
1374 ));
1375 $row = $stmt->fetch(PDO::FETCH_ASSOC);
1376 if (empty($row)){
1377 $stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
1378 VALUES (:type, :template, :attributes)");
1379 $stmt->execute(array(
1380 ":type" => "domain",
1381 ":template" => $default_domain_template["template"],
1382 ":attributes" => json_encode($default_domain_template["attributes"])
1383 ));
1384 }
1385 $stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
1386 $stmt->execute(array(
1387 ":type" => "mailbox",
1388 ":template" => $default_mailbox_template["template"]
1389 ));
1390 $row = $stmt->fetch(PDO::FETCH_ASSOC);
1391 if (empty($row)){
1392 $stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
1393 VALUES (:type, :template, :attributes)");
1394 $stmt->execute(array(
1395 ":type" => "mailbox",
1396 ":template" => $default_mailbox_template["template"],
1397 ":attributes" => json_encode($default_mailbox_template["attributes"])
1398 ));
1399 }
1400
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001401 if (php_sapi_name() == "cli") {
1402 echo "DB initialization completed" . PHP_EOL;
1403 } else {
1404 $_SESSION['return'][] = array(
1405 'type' => 'success',
1406 'log' => array(__FUNCTION__),
1407 'msg' => 'db_init_complete'
1408 );
1409 }
1410 }
1411 catch (PDOException $e) {
1412 if (php_sapi_name() == "cli") {
1413 echo "DB initialization failed: " . print_r($e, true) . PHP_EOL;
1414 } else {
1415 $_SESSION['return'][] = array(
1416 'type' => 'danger',
1417 'log' => array(__FUNCTION__),
1418 'msg' => array('mysql_error', $e)
1419 );
1420 }
1421 }
1422}
1423if (php_sapi_name() == "cli") {
1424 include '/web/inc/vars.inc.php';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001425 include '/web/inc/functions.docker.inc.php';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001426 // $now = new DateTime();
1427 // $mins = $now->getOffset() / 60;
1428 // $sgn = ($mins < 0 ? -1 : 1);
1429 // $mins = abs($mins);
1430 // $hrs = floor($mins / 60);
1431 // $mins -= $hrs * 60;
1432 // $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
1433 $dsn = $database_type . ":unix_socket=" . $database_sock . ";dbname=" . $database_name;
1434 $opt = [
1435 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
1436 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
1437 PDO::ATTR_EMULATE_PREPARES => false,
1438 //PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '" . $offset . "', group_concat_max_len = 3423543543;",
1439 ];
1440 $pdo = new PDO($dsn, $database_user, $database_pass, $opt);
1441 $stmt = $pdo->query("SELECT COUNT('OK') AS OK_C FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'sogo_view' OR TABLE_NAME = '_sogo_static_view';");
1442 $res = $stmt->fetch(PDO::FETCH_ASSOC);
1443 if (intval($res['OK_C']) === 2) {
1444 // Be more precise when replacing into _sogo_static_view, col orders may change
1445 try {
1446 $stmt = $pdo->query("REPLACE INTO _sogo_static_view (`c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings`)
1447 SELECT `c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings` from sogo_view");
1448 $stmt = $pdo->query("DELETE FROM _sogo_static_view WHERE `c_uid` NOT IN (SELECT `username` FROM `mailbox` WHERE `active` = '1');");
1449 echo "Fixed _sogo_static_view" . PHP_EOL;
1450 }
1451 catch ( Exception $e ) {
1452 // Dunno
1453 }
1454 }
1455 try {
1456 $m = new Memcached();
1457 $m->addServer('memcached', 11211);
1458 $m->flush();
1459 echo "Cleaned up memcached". PHP_EOL;
1460 }
1461 catch ( Exception $e ) {
1462 // Dunno
1463 }
1464 init_db_schema();
1465}