Alternc  latest
Alternc logiel libre pour l'hébergement
mysql.sql
Go to the documentation of this file.
1 --
2 -- ----------------------------------------------------------------------
3 -- AlternC - Web Hosting System
4 -- Copyright (C) 2000-2017 by the AlternC Development Team.
5 -- https://alternc.org/
6 -- ----------------------------------------------------------------------
7 -- LICENSE
8 --
9 -- This program is free software; you can redistribute it and/or
10 -- modify it under the terms of the GNU General Public License (GPL)
11 -- as published by the Free Software Foundation; either version 2
12 -- of the License, or (at your option) any later version.
13 --
14 -- This program is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 -- GNU General Public License for more details.
18 --
19 -- To read the license please visit http://www.gnu.org/copyleft/gpl.html
20 -- ----------------------------------------------------------------------
21 -- Purpose of file: Create the basic structure for the mysql system db
22 -- ----------------------------------------------------------------------
23 --
24 
25 -- ----------------------------------------------------------------------
26 -- AlternC's table structure
27 --
28 -- WARNING: when you change anything here,
29 -- the upgrades/<version>.sql file must be edited or created
30 -- so that already running alternc instances can be upgraded.
31 -- <version> must be higher than previous version
32 -- See upgrades/README for more information.
33 -- ----------------------------------------------------------------------
34 
35 CREATE TABLE IF NOT EXISTS `slaveip` (
36 `ip` VARCHAR( 40 ) NOT NULL ,
37 `class` TINYINT NOT NULL ,
38 PRIMARY KEY ( `ip` , `class` )
39 ) ENGINE=InnoDB COMMENT = 'Allowed ip for slave dns managment';
40 
41 CREATE TABLE IF NOT EXISTS `slaveaccount` (
42 `login` VARCHAR( 64 ) NOT NULL ,
43 `pass` VARCHAR( 64 ) NOT NULL ,
44 PRIMARY KEY ( `login` )
45 ) ENGINE=InnoDB COMMENT = 'Allowed account for slave dns managment';
46 
47 
48 --
49 -- Structure de la table `browser`
50 --
51 -- Cette table contient les préférences des utilisateurs dans le gestionnaire de fichiers
52 
53 
54 CREATE TABLE IF NOT EXISTS browser (
55  uid int(10) unsigned NOT NULL default '0', -- Numéro de l`utilisateur
56  editsizex int(10) unsigned NOT NULL default '0', -- Largeur de la zone d`edition du brouteur
57  editsizey int(10) unsigned NOT NULL default '0', -- Hauteur de la zone d`edition du brouteur
58  listmode tinyint(3) unsigned NOT NULL default '0', -- Mode de listing (1 colonne, 2 colonne, 3 colonne)
59  showicons tinyint(4) NOT NULL default '0', -- Faut-il afficher les icones (1/0)
60  downfmt tinyint(4) NOT NULL default '0', -- Format de téléchargement (zip/bz2/tgz/tar.Z)
61  createfile tinyint(4) NOT NULL default '0', -- Que fait-on après création d`un fichier (1/0)
62  showtype tinyint(4) NOT NULL default '0', -- Affiche-t-on le type mime ?
63  editor_font varchar(64) NOT NULL default '', -- Nom de la police dans l`éditeur de fichiers
64  editor_size varchar(8) NOT NULL default '', -- Taille de la police dans l`éditeur de fichiers
65  crff tinyint(4) NOT NULL default '0', -- mémorise le dernier fichier/dossier créé (pour le bouton radio)
66  golastdir tinyint(4) NOT NULL default '0', -- Faut-il aller au dernier dossier ou au dossier racine dans le brouteur ?
67  lastdir varchar(255) NOT NULL default '', -- Dernier dossier visité.
68  PRIMARY KEY (uid)
69 ) ENGINE=InnoDB COMMENT='Préférences du gestionnaire de fichiers';
70 
71 
72 --
73 -- Structure de la table `chgmail`
74 --
75 -- Cette table contient les demandes de changements de mail pour les membres
76 
77 CREATE TABLE IF NOT EXISTS chgmail (
78  uid int(10) unsigned NOT NULL default '0', -- Numéro de l`utilisateur
79  cookie varchar(20) NOT NULL default '', -- Cookie du mail
80  ckey varchar(6) NOT NULL default '', -- Clé de vérif
81  mail varchar(128) NOT NULL default '', -- Nouvel Email
82  ts bigint(20) unsigned NOT NULL default '0', -- Timestamp de la demande
83  PRIMARY KEY (uid)
84 ) ENGINE=InnoDB COMMENT='Demandes de changements de mail en cours';
85 
86 --
87 -- Structure de la table `db`
88 --
89 -- Contient les bases mysql des membres, + login / pass en clair
90 
91 CREATE TABLE IF NOT EXISTS db (
92  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
93  uid int(10) unsigned NOT NULL default '0', -- Numéro de l`utilisateur
94  login varchar(16) NOT NULL default '', -- Nom d`utilisateur mysql
95  pass varchar(16) NOT NULL default '', -- Mot de passe mysql
96  db varchar(64) NOT NULL default '', -- Base de données concernée
97  bck_mode tinyint(3) unsigned NOT NULL default '0', -- Mode de backup (0/non 1/Daily 2/Weekly)
98  bck_history tinyint(3) unsigned NOT NULL default '0', -- Nombre de backup à conserver ?
99  bck_gzip tinyint(3) unsigned NOT NULL default '0', -- Faut-il compresser les backups ?
100  bck_dir varchar(255) NOT NULL default '', -- Où stocke-t-on les backups sql ?
101  PRIMARY KEY id (id)
102 ) ENGINE=InnoDB COMMENT='Bases MySQL des membres';
103 
104 --
105 -- Structure de la table `domaines`
106 --
107 -- Liste des domaines hébergés
108 
109 CREATE TABLE IF NOT EXISTS domaines (
110  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
111  compte int(10) unsigned NOT NULL default '0',
112  domaine varchar(64) NOT NULL default '',
113  gesdns int(1) NOT NULL default '1',
114  gesmx int(1) NOT NULL default '1',
115  noerase tinyint(4) NOT NULL default '0',
116  dns_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE',
117  dns_result varchar(255) not null default '',
118  zonettl int(10) unsigned NOT NULL default '3600',
119  PRIMARY KEY (id),
120  UNIQUE KEY (domaine)
121 ) ENGINE=InnoDB;
122 
123 --
124 -- Structure de la table `ftpusers`
125 --
126 -- Comptes ftp des membres
127 
128 CREATE TABLE IF NOT EXISTS ftpusers (
129  id int(10) unsigned NOT NULL auto_increment,
130  name varchar(64) NOT NULL default '',
131  password varchar(32) NOT NULL default '',
132  encrypted_password VARCHAR(255) default NULL,
133  homedir varchar(128) NOT NULL default '',
134  uid int(10) unsigned NOT NULL default '0',
135  enabled boolean NOT NULL DEFAULT TRUE,
136  PRIMARY KEY (id),
137  UNIQUE KEY name (name),
138  KEY homedir (homedir),
139  KEY mid (uid)
140 ) ENGINE=InnoDB;
141 
142 --
143 -- Structure de la table `local`
144 --
145 -- Champs utilisables par l`hébergeur pour associer des données locales aux membres.
146 
147 CREATE TABLE IF NOT EXISTS local (
148  uid int(10) unsigned NOT NULL default '0',
149  nom varchar(128) NOT NULL default '',
150  prenom varchar(128) NOT NULL default '',
151  PRIMARY KEY (uid)
152 ) ENGINE=InnoDB COMMENT='Parametres Locaux des membres';
153 
154 --
155 -- Structure de la table `membres`
156 --
157 -- Liste des membres
158 
159 CREATE TABLE IF NOT EXISTS membres (
160  uid int(10) unsigned NOT NULL auto_increment, -- Numéro du membre (GID)
161  login varchar(128) NOT NULL default '', -- Nom d`utilisateur
162  pass varchar(255) NOT NULL default '', -- Mot de passe
163  enabled tinyint(4) NOT NULL default '1', -- Le compte est-il actif ?
164  su tinyint(4) NOT NULL default '0', -- Le compte est-il super-admin ?
165  mail varchar(128) NOT NULL default '', -- Adresse email du possesseur
166  lastaskpass bigint(20) unsigned default '0', -- Date de dernière demande du pass par mail
167  show_help tinyint(4) NOT NULL default '1', -- Faut-il afficher l`aide dans le bureau
168  lastlogin datetime NOT NULL default '0000-00-00 00:00:00', -- Date du dernier login
169  lastfail tinyint(4) NOT NULL default '0', -- Nombre d`échecs depuis le dernier login
170  lastip varchar(255) NOT NULL default '', -- Nom DNS du client au dernier login
171  creator int(10) unsigned default '0', -- Qui a créé le compte (quel uid admin)
172  canpass tinyint(4) default '1', -- L`utilisateur peut-il changer son pass.
173  warnlogin tinyint(4) default '0', -- TODO L`utilisateur veut-il recevoir un mail quand on se loggue sur son compte ?
174  warnfailed tinyint(4) default '0', -- TODO L`utilisateur veut-il recevoir un mail quand on tente de se logguer sur son compte ?
175  admlist tinyint(4) default '0', -- Mode d`affichage de la liste des membres pour les super admins
176  type varchar(128) default 'default',
177  db_server_id int(10) DEFAULT NULL,
178  notes TEXT NOT NULL,
179  created datetime default NULL,
180  renewed datetime default NULL,
181  duration int(4) default NULL,
182  PRIMARY KEY (uid),
183  UNIQUE KEY k_login (login)
184 ) ENGINE=InnoDB COMMENT='Liste des membres du serveur';
185 
186 --
187 -- Structure de la table `quotas`
188 --
189 -- Listes des quotas des membres
190 
191 CREATE TABLE IF NOT EXISTS quotas (
192  uid int(10) unsigned NOT NULL default '0', -- Numéro GID du membre concerné
193  name varchar(64) NOT NULL default '', -- Nom du quota
194  total bigint(20) unsigned NOT NULL default '0', -- Quota total (maximum autorisé)
195  PRIMARY KEY (uid,name)
196 ) ENGINE=InnoDB COMMENT='Quotas des Membres';
197 
198 --
199 -- Structure de la table `sessions`
200 --
201 -- Sessions actives sur le bureau
202 
203 CREATE TABLE IF NOT EXISTS sessions (
204  sid varchar(32) NOT NULL default '', -- Cookie de session (md5)
205  uid int(10) unsigned NOT NULL default '0', -- UID du membre concerné
206  ip varchar(40) NOT NULL default '', -- Adresse IP de la connexion
207  ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
208 ) ENGINE=InnoDB COMMENT='Session actives sur le bureau';
209 
210 --
211 -- Structure de la table `sub_domaines`
212 --
213 -- Sous-domaines des membres
214 
215 CREATE TABLE IF NOT EXISTS sub_domaines (
216  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
217  compte int(10) unsigned NOT NULL default '0',
218  domaine varchar(255) NOT NULL default '',
219  sub varchar(255) NOT NULL default '',
220  valeur varchar(255) default NULL,
221  type varchar(30) NOT NULL default 'LOCAL',
222  web_action enum ('OK','UPDATE','DELETE') NOT NULL default 'UPDATE',
223  web_result varchar(255) not null default '',
224  enable enum ('ENABLED', 'ENABLE', 'DISABLED', 'DISABLE') NOT NULL DEFAULT 'ENABLED',
225  `certificate_id` INT UNSIGNED NOT NULL DEFAULT '0',
226  `provider` VARCHAR(16) NOT NULL DEFAULT '',
227  `https` VARCHAR(6) NOT NULL, -- SET(http,https,both) (also the suffix of the template name in /etc/alternc/templates/apache2/)
228  PRIMARY KEY (id)
229 -- ,FOREIGN KEY (type) REFERENCES (domaines_type)
230 ) ENGINE=InnoDB;
231 
232 --
233 -- Main address table.
234 --
235 -- Addresses for domain.
236 
237 CREATE TABLE IF NOT EXISTS `address` (
238  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, -- Technical id.
239  `domain_id` bigint(20) unsigned NOT NULL REFERENCES `domaines`(`id`), -- FK to domaines.
240  `address` varchar(255) NOT NULL, -- The address.
241  `type` char(8) NOT NULL, -- standard emails are '', other may be 'mailman' or 'sympa' ...
242  `password` varchar(255) DEFAULT NULL, -- The password associated to the address.
243  `enabled` int(1) unsigned NOT NULL DEFAULT '1', -- Enabled flag.
244  `expire_date` datetime DEFAULT NULL, -- Expiration date, used for temporary addresses.
245  `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Update date, for technical usage only.
246  `mail_action` enum('OK','DELETE','DELETING') NOT NULL default 'OK', -- mail_action is DELETE or DELETING when deleting a mailbox by cron
247  PRIMARY KEY (`id`),
248  UNIQUE INDEX `fk_domain_id` (`domain_id`,`address`(190))
249 ) ENGINE=InnoDB COMMENT = 'This is the main address table. It represents an address as in RFC2822';
250 
251 --
252 -- Mailbox table.
253 --
254 -- Local delivered mailboxes.
255 
256 CREATE TABLE IF NOT EXISTS `mailbox` (
257  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, -- Technical id.
258  `address_id` bigint(20) unsigned NOT NULL REFERENCES `address`(`id`), -- Reference to address.
259  `path` varchar(255) NOT NULL, -- Relative path to the mailbox.
260  `quota` bigint(20) unsigned DEFAULT NULL, -- Quota for this mailbox.
261  `delivery` varchar(255) NOT NULL, -- Delivery transport.
262  `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Update date, for technical usage only.
263  `bytes` bigint(20) NOT NULL DEFAULT '0', -- number of bytes in the mailbox, filled by dovecot
264  `messages` int(11) NOT NULL DEFAULT '0', -- number of messages in the mailbox, filled by dovecot
265  `lastlogin` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', -- Last login, filled by dovecot
266  `lastloginsasl` DATETIME NOT NULL DEFAULT 0, -- last login on SASL / SMTP, not filled yet ;)
267  `mail_action` enum('OK','DELETE','DELETING') NOT NULL default 'OK', -- mail_action is DELETE or DELETING when deleting a mailbox by cron
268  PRIMARY KEY (`id`),
269  UNIQUE KEY `address_id` (`address_id`)
270 ) ENGINE=InnoDB COMMENT = 'Table containing local deliverd mailboxes.';
271 
272 --
273 -- Other recipients.
274 --
275 -- Other recipients for an address (aliases)
276 
277 CREATE TABLE IF NOT EXISTS `recipient` (
278  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, -- Technical id.
279  `address_id` bigint(20) unsigned NOT NULL REFERENCES `address`(`id`), -- Reference to address
280  `recipients` text NOT NULL, -- Recipients
281  `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Update date, for technical usage only.
282  PRIMARY KEY (`id`),
283  UNIQUE KEY `key_id` (`id`,`address_id`)
284 ) ENGINE=InnoDB COMMENT = 'Table containing other recipients (aliases) for an address.';
285 
286 
287 --
288 -- Structure de la table `defquotas`
289 --
290 -- Quotas par défaut pour les services
291 
292 CREATE TABLE IF NOT EXISTS defquotas (
293  quota varchar(128), -- Nom du quota
294  value bigint(20) unsigned default '0', -- Valeur du quota
295  type varchar(128) default 'default', -- Type de compte associée à ce quota
296  PRIMARY KEY (quota,type)
297 ) ENGINE=InnoDB;
298 
299 --
300 -- Quotas par defaut pour les nouveaux membres
301 --
302 -- Ces quotas par defaut sont redefinissables dans l`interface web
303 
304 INSERT IGNORE INTO defquotas (quota,value) VALUES ('dom',1);
305 INSERT IGNORE INTO defquotas (quota,value) VALUES ('web',51200);
306 INSERT IGNORE INTO defquotas (quota,value) VALUES ('mail',10);
307 INSERT IGNORE INTO defquotas (quota,value) VALUES ('ftp',2);
308 INSERT IGNORE INTO defquotas (quota,value) VALUES ('stats',1);
309 INSERT IGNORE INTO defquotas (quota,value) VALUES ('mysql',1);
310 
311 
312 --
313 -- Structure de la table `forbidden_domains`
314 --
315 -- Liste des domaines explicitement interdits sur le serveur :
316 
317 CREATE TABLE IF NOT EXISTS forbidden_domains (
318  domain varchar(255) NOT NULL default '',
319  PRIMARY KEY (domain(190))
320 ) ENGINE=InnoDB COMMENT='forbidden domains to install';
321 
322 --
323 -- Contenu de la table `forbidden_domains`
324 --
325 
326 -- Registries :
327 INSERT IGNORE INTO forbidden_domains VALUES ('afilias.net');
328 INSERT IGNORE INTO forbidden_domains VALUES ('afnic.fr');
329 INSERT IGNORE INTO forbidden_domains VALUES ('dns.be');
330 INSERT IGNORE INTO forbidden_domains VALUES ('internic.net');
331 INSERT IGNORE INTO forbidden_domains VALUES ('netsol.com');
332 INSERT IGNORE INTO forbidden_domains VALUES ('nic.biz');
333 INSERT IGNORE INTO forbidden_domains VALUES ('nic.cx');
334 INSERT IGNORE INTO forbidden_domains VALUES ('nic.fr');
335 INSERT IGNORE INTO forbidden_domains VALUES ('verisign.com');
336 INSERT IGNORE INTO forbidden_domains VALUES ('octopuce.com');
337 INSERT IGNORE INTO forbidden_domains VALUES ('pir.org');
338 INSERT IGNORE INTO forbidden_domains VALUES ('cira.ca');
339 -- big isp :
340 INSERT IGNORE INTO forbidden_domains VALUES ('aol.com');
341 INSERT IGNORE INTO forbidden_domains VALUES ('hotmail.com');
342 INSERT IGNORE INTO forbidden_domains VALUES ('microsoft.com');
343 INSERT IGNORE INTO forbidden_domains VALUES ('sympatico.ca');
344 INSERT IGNORE INTO forbidden_domains VALUES ('tiscali.fr');
345 INSERT IGNORE INTO forbidden_domains VALUES ('voila.fr');
346 INSERT IGNORE INTO forbidden_domains VALUES ('wanadoo.fr');
347 INSERT IGNORE INTO forbidden_domains VALUES ('yahoo.com');
348 INSERT IGNORE INTO forbidden_domains VALUES ('yahoo.fr');
349 INSERT IGNORE INTO forbidden_domains VALUES ('gmail.com');
350 INSERT IGNORE INTO forbidden_domains VALUES ('orange.fr');
351 INSERT IGNORE INTO forbidden_domains VALUES ('sfr.fr');
352 INSERT IGNORE INTO forbidden_domains VALUES ('free.fr');
353 
354 --
355 -- Structure de la table `tld`
356 --
357 -- Liste des tld autorisés sur ce serveur :
358 
359 CREATE TABLE IF NOT EXISTS tld (
360  tld varchar(128) NOT NULL default '', -- lettres du tld (sans le .)
361  mode tinyint(4) NOT NULL default '0', -- Comment est-il autorisé ?
362  PRIMARY KEY (tld),
363  KEY mode (mode)
364 ) ENGINE=InnoDB COMMENT='TLD autorises et comment sont-ils autorises ? ';
365 
366 --
367 -- Contenu de la table `tld`
368 --
369 
370 INSERT IGNORE INTO tld VALUES ('fr', 4);
371 INSERT IGNORE INTO tld VALUES ('com', 1);
372 INSERT IGNORE INTO tld VALUES ('org', 1);
373 INSERT IGNORE INTO tld VALUES ('net', 1);
374 INSERT IGNORE INTO tld VALUES ('biz', 1);
375 INSERT IGNORE INTO tld VALUES ('info', 1);
376 INSERT IGNORE INTO tld VALUES ('name', 1);
377 INSERT IGNORE INTO tld VALUES ('ca', 1);
378 INSERT IGNORE INTO tld VALUES ('it', 1);
379 INSERT IGNORE INTO tld VALUES ('ws', 1);
380 INSERT IGNORE INTO tld VALUES ('be', 1);
381 INSERT IGNORE INTO tld VALUES ('eu.org', 4);
382 INSERT IGNORE INTO tld VALUES ('cjb.net', 4);
383 INSERT IGNORE INTO tld VALUES ('asso.fr', 4);
384 INSERT IGNORE INTO tld VALUES ('eu', 1);
385 INSERT IGNORE INTO tld VALUES ('coop', 1);
386 INSERT IGNORE INTO tld VALUES ('asia', 1);
387 
388 --
389 -- Table structure for table 'variable'
390 --
391 -- if comment is null, then the variable is internal and will not show
392 -- up in the generic configuration panel
393 CREATE TABLE IF NOT EXISTS `variable` (
394  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
395  `name` varchar(48) NOT NULL DEFAULT '',
396  `value` longtext NOT NULL,
397  `comment` mediumtext,
398  `type` text,
399  PRIMARY KEY (`id`),
400  UNIQUE KEY `name` (`name`)
401 ) ENGINE=InnoDB COMMENT='Stores AlternC system variable used by panel and scripts, configurable through the panel';
402 
403 --
404 -- Table structure for table `dbusers`
405 --
406 
407 CREATE TABLE IF NOT EXISTS `dbusers` (
408  `id` int(10) unsigned NOT NULL auto_increment,
409  `uid` int(10) unsigned NOT NULL default '0',
410  `name` varchar(16) NOT NULL default '',
411  `password` varchar( 64 ),
412  `enable` enum ('ACTIVATED', 'HIDDEN', 'ADMIN') NOT NULL DEFAULT 'ACTIVATED',
413  KEY `id` (`id`)
414 ) ENGINE=InnoDB COMMENT='Utilisateurs MySQL des membres';
415 
416 
417 CREATE TABLE IF NOT EXISTS `mxaccount` (
418 `login` VARCHAR( 64 ) NOT NULL ,
419 `pass` VARCHAR( 64 ) NOT NULL ,
420 PRIMARY KEY ( `login` )
421 ) ENGINE=InnoDB COMMENT = 'Allowed account for secondary mx managment';
422 
423 
424 -- --------------------------------------------------------
425 CREATE TABLE IF NOT EXISTS `size_web` (
426  `uid` int(10) unsigned NOT NULL default '0',
427  `size` int(10) unsigned NOT NULL default '0',
428  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
429  PRIMARY KEY (`uid`),
430  KEY `ts` (`ts`)
431 ) ENGINE=InnoDB COMMENT='Web space used by accounts.';
432 
433 -- --------------------------------------------------------
434 CREATE TABLE IF NOT EXISTS `size_db` (
435  `db` varchar(128) NOT NULL default '',
436  `size` int(10) unsigned NOT NULL default '0',
437  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
438  PRIMARY KEY (`db`),
439  KEY `ts` (`ts`)
440 ) ENGINE=InnoDB COMMENT='MySQL Database used space';
441 
442 -- --------------------------------------------------------
443 CREATE TABLE IF NOT EXISTS `size_mailman` (
444  `list` varchar(255) NOT NULL default '',
445  `uid` int(11) NOT NULL default '0',
446  `size` int(10) unsigned NOT NULL default '0',
447  `ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
448  PRIMARY KEY (`list`(190)),
449  KEY `ts` (`ts`),
450  KEY `uid` (`uid`)
451 ) ENGINE=InnoDB COMMENT='Mailman Lists used space';
452 
453 -- --------------------------------------------------------
454 
455 
456 CREATE TABLE IF NOT EXISTS `policy` (
457  `name` varchar(64) NOT NULL,
458  `minsize` tinyint(3) unsigned NOT NULL,
459  `maxsize` tinyint(3) unsigned NOT NULL,
460  `classcount` tinyint(3) unsigned NOT NULL,
461  `allowlogin` tinyint(3) unsigned NOT NULL,
462  PRIMARY KEY (`name`)
463 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='The password policies for services';
464 
465 -- Domains type
466 CREATE TABLE IF NOT EXISTS `domaines_type` (
467  `name` VARCHAR (30) NOT NULL, -- Uniq name
468  `description` TEXT, -- Human description
469  `target` enum ('NONE', 'URL', 'DIRECTORY', 'IP', 'IPV6', 'DOMAIN', 'TXT') NOT NULL DEFAULT 'NONE', -- Target type
470  `entry` TEXT DEFAULT '', -- BIND entry
471  `compatibility` VARCHAR (255) DEFAULT '', -- Which type can be on the same subdomains
472  `enable` enum ('ALL', 'NONE', 'ADMIN') NOT NULL DEFAULT 'ALL', -- Show this option to who ?
473  `only_dns` BOOLEAN DEFAULT FALSE, -- Update_domains modify just the dns, no web configuration
474  `need_dns` BOOLEAN DEFAULT TRUE, -- The server need to be the DNS to allow this service
475  `advanced` BOOLEAN DEFAULT TRUE, -- It's an advanced option
476  `create_tmpdir` BOOLEAN NOT NULL DEFAULT FALSE, -- do we create tmp dir ?
477  `create_targetdir` BOOLEAN NOT NULL DEFAULT FALSE, -- do we create target dir ?
478  `has_https_option` BOOLEAN NOT NULL DEFAULT FALSE, -- shall we show the http/https/both dropdown ?
479  PRIMARY KEY ( `name` )
480 ) ENGINE=InnoDB COMMENT = 'Type of domains allowed';
481 
482 INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, only_dns, need_dns, advanced, enable,has_https_option) VALUES
483 ('dkim', 'DKIM Key', 'TXT', '%SUB% IN TXT "%TARGET%"', 'txt,defmx,defmx2,mx,mx2,url,ip,ipv6', true, true, true, 'ADMIN', false),
484 ('autodiscover', 'Email autoconfiguration', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2,mx,mx2', false, true, true, 'ADMIN', false),
485 -- Default vhost type to maintains compatibility across versions.
486 -- This is overloaded depending on the value of the https column in sub_domaines
487 ('vhost', 'Locally hosted', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2,mx,mx2', false, false, false, 'ALL', true),
488 -- The following 3 types (vhost-http, vhost-https, vhost-both) are overloads for vhost
489 -- and are "disabled" to not be available from the interface, but still be valid domaine types
490 -- when checking in m_ssl::updateDomain.
491 ('vhost-http','Locally hosted with http->https', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2,mx,mx2', false, false, false, 'NONE', false),
492 ('vhost-https','Locally hosted with http->https', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2,mx,mx2', false, false, false, 'NONE', false),
493 ('vhost-both', 'Locally hosted with http and https', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2,mx,mx2', false, false, false, 'NONE', false),
494 ('url', 'URL redirection', 'URL', '%SUB% IN A @@PUBLIC_IP@@', 'txt,defmx,defmx2', false, false, false, 'ALL', false),
495 ('ip', 'IPv4 redirect', 'IP', '%SUB% IN A %TARGET%', 'url,ip,ipv6,txt,mx,mx2,defmx,defmx2', true, true, false, 'ALL', false),
496 ('ipv6', 'IPv6 redirect', 'IPV6', '%SUB% IN AAAA %TARGET%', 'ip,ipv6,txt,mx,mx2,defmx,defmx2', true, true, true, 'ALL', false),
497 ('cname', 'CNAME DNS entry', 'DOMAIN', '%SUB% CNAME %TARGET%', '', true, true, true, 'ALL', false),
498 ('txt', 'TXT DNS entry', 'TXT', '%SUB% IN TXT "%TARGET%"', 'vhost,url,ip,ipv6,txt,mx,mx2,defmx,defmx2', true, true, true, 'ALL', false),
499 ('mx', 'MX DNS entry', 'DOMAIN', '%SUB% IN MX 5 %TARGET%', 'vhost,url,ip,ipv6,txt,mx,mx2', true, true, true, 'ALL', false),
500 ('mx2', 'secondary MX DNS entry', 'DOMAIN', '%SUB% IN MX 10 %TARGET%', 'vhost,url,ip,ipv6,txt,mx,mx2', true, true, true, 'ALL', false),
501 ('defmx', 'Default mail server', 'NONE', '%SUB% IN MX 5 @@DEFAULT_MX@@.', 'vhost,url,ip,ipv6,txt,defmx2', true, true, true, 'ADMIN', false),
502 ('defmx2', 'Default backup mail server', 'NONE', '%SUB% IN MX 10 @@DEFAULT_SECONDARY_MX@@.', 'vhost,url,ip,ipv6,txt,defmx', true, true, true, 'ADMIN', false),
503 ('panel', 'AlternC panel access', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,ip,ipv6,txt,mx,mx2,defmx,defmx2', false, false, true, 'ALL', false)
504 ;
505 UPDATE domaines_type SET create_tmpdir=true, create_targetdir=true WHERE target='DIRECTORY';
506 
507 -- Add function who are not in mysql 5 to be able ton convert ipv6 to decimal (and reverse it)
508 DELIMITER //
509 DROP FUNCTION IF EXISTS INET_ATON6;//
510 CREATE FUNCTION INET_ATON6(n CHAR(39))
511 RETURNS DECIMAL(39) UNSIGNED
512 DETERMINISTIC
513 BEGIN
514  RETURN CAST(CONV(SUBSTRING(n FROM 1 FOR 4), 16, 10) AS DECIMAL(39))
515  * 5192296858534827628530496329220096 -- 65536 ^ 7
516  + CAST(CONV(SUBSTRING(n FROM 6 FOR 4), 16, 10) AS DECIMAL(39))
517  * 79228162514264337593543950336 -- 65536 ^ 6
518  + CAST(CONV(SUBSTRING(n FROM 11 FOR 4), 16, 10) AS DECIMAL(39))
519  * 1208925819614629174706176 -- 65536 ^ 5
520  + CAST(CONV(SUBSTRING(n FROM 16 FOR 4), 16, 10) AS DECIMAL(39))
521  * 18446744073709551616 -- 65536 ^ 4
522  + CAST(CONV(SUBSTRING(n FROM 21 FOR 4), 16, 10) AS DECIMAL(39))
523  * 281474976710656 -- 65536 ^ 3
524  + CAST(CONV(SUBSTRING(n FROM 26 FOR 4), 16, 10) AS DECIMAL(39))
525  * 4294967296 -- 65536 ^ 2
526  + CAST(CONV(SUBSTRING(n FROM 31 FOR 4), 16, 10) AS DECIMAL(39))
527  * 65536 -- 65536 ^ 1
528  + CAST(CONV(SUBSTRING(n FROM 36 FOR 4), 16, 10) AS DECIMAL(39))
529  ;
530 END;
531 //
532 DELIMITER ;
533 DELIMITER //
534 DROP FUNCTION IF EXISTS INET_NTOA6;//
535 CREATE FUNCTION INET_NTOA6(n DECIMAL(39) UNSIGNED)
536 RETURNS CHAR(39)
537 DETERMINISTIC
538 BEGIN
539  DECLARE a CHAR(39) DEFAULT '';
540  DECLARE i INT DEFAULT 7;
541  DECLARE q DECIMAL(39) UNSIGNED DEFAULT 0;
542  DECLARE r INT DEFAULT 0;
543  WHILE i DO
544  -- DIV doesn't work with nubers > bigint
545  SET q := FLOOR(n / 65536);
546  SET r := n MOD 65536;
547  SET n := q;
548  SET a := CONCAT_WS(':', LPAD(CONV(r, 10, 16), 4, '0'), a);
549 
550  SET i := i - 1;
551  END WHILE;
552 
553  SET a := TRIM(TRAILING ':' FROM CONCAT_WS(':',
554  LPAD(CONV(n, 10, 16), 4, '0'),
555  a));
556 
557  RETURN a;
558 
559 END;
560 //
561 DELIMITER ;
562 
563 -- New table for the authorised IP
564 CREATE TABLE IF NOT EXISTS `authorised_ip` (
565  `id` int(10) unsigned NOT NULL auto_increment,
566  `uid` int(11) unsigned NOT NULL default '0',
567  `ip` varchar(40) not null,
568  `subnet` integer(3) not null default 32,
569  `infos` varchar(255) not null default '',
570  PRIMARY KEY (`id`),
571  KEY `uid` (`uid`)
572 ) ENGINE=InnoDB COMMENT='Table with list of authorised ip and subnet';
573 
574 -- Who have authorised IP ?
575 CREATE TABLE IF NOT EXISTS `authorised_ip_affected` (
576  `id` int(10) unsigned NOT NULL auto_increment,
577  `authorised_ip_id` int(10) unsigned not null,
578  `protocol` varchar(15) not null,
579  `parameters` varchar(30) default '',
580  PRIMARY KEY (`id`)
581 ) ENGINE=InnoDB COMMENT='Table with list of protocol <-> authorised ip and subnet';
582 
583 --
584 -- Structure de la table `cron`
585 --
586 
587 CREATE TABLE IF NOT EXISTS `cron` (
588  `id` int(11) NOT NULL AUTO_INCREMENT,
589  `uid` int(11) NOT NULL,
590  `url` varchar(2100) NOT NULL,
591  `user` varchar(64) NOT NULL,
592  `password` varchar(64) NOT NULL,
593  `schedule` int(11) NOT NULL,
594  `email` varchar(255) NOT NULL,
595  `next_execution` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
596  PRIMARY KEY (`id`),
597  KEY `uid` (`uid`)
598 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
599 
600 
601 --
602 -- Structure de la table `dovecot_quota`
603 --
604 
605 CREATE TABLE IF NOT EXISTS `dovecot_quota` (
606  `user` varchar(320) NOT NULL,
607  `quota_dovecot` bigint(20) NOT NULL DEFAULT '0',
608  `nb_messages` int(11) NOT NULL DEFAULT '0',
609  PRIMARY KEY (`user`)
610 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
611 
612 
613 --
614 -- Structure de la vue `dovecot_view`
615 --
616 
617 CREATE OR REPLACE VIEW `dovecot_view` AS
618 SELECT concat(`address`.`address`,'@',`domaines`.`domaine`) AS `user`,
619 concat('*:storage=',cast(`mailbox`.`quota` as char charset latin1),'M') AS `userdb_quota_rule`,
620 `address`.`password` AS `password`,
621 `mailbox`.`path` AS `userdb_home`,
622 `domaines`.`compte` AS `userdb_uid`,
623 `domaines`.`compte` AS `userdb_gid`,
624 `mailbox`.`bytes` AS `quota_dovecot`,
625 `mailbox`.`messages` AS `nb_messages`
626 from ((`mailbox`
627 join `address` on((`address`.`id` = `mailbox`.`address_id`)))
628 join `domaines` on((`domaines`.`id` = `address`.`domain_id`)))
629 where `address`.`enabled` = 1
630 ;
631 
632 --
633 -- Structure de la vue `alias_view`
634 --
635 
636 CREATE OR REPLACE VIEW `alias_view` AS
637 
638 -- Generate all the alias configured by the users
639 select
640  concat(`address`.`address`,'@',`domaines`.`domaine`) AS `mail`,
641  concat(if(isnull(`mailbox`.`id`),
642  '',
643  concat(concat(`address`.`address`,'@',`domaines`.`domaine`),'\n')),
644  `recipient`.`recipients`) AS `alias`
645 from
646  (
647  ((`recipient` join `address` on((`address`.`id` = `recipient`.`address_id`)))
648  left join `mailbox` on((`mailbox`.`address_id` = `address`.`id`))
649  )
650  join `domaines` on((`domaines`.`id` = `address`.`domain_id`))
651  )
652 where
653  `address`.`enabled` = 1
654 
655 UNION
656 
657 -- Generate the alias for all the account
658 -- Example : account gaylord will have gaylord@FQDN
659 -- as an alias to his email account. FQDN can be
660 -- changed in variable mailname_bounce
661 select
662  distinct concat(`m`.`login`,'@',`v`.`value`) AS `mail`,
663  `m`.`mail` AS `alias`
664 from
665  `membres` `m`,
666  `variable` `v`
667 where
668  `v`.`name` = 'mailname_bounce'
669 
670 UNION
671 
672 -- Generate an alias alterncpanel@FQDN to admin mail
673 select
674  distinct concat('alterncpanel','@',`v`.`value`) AS `mail`,
675  `m`.`mail` AS `alias`
676 from
677  `membres` `m`,
678  `variable` `v`
679 where
680  (`v`.`name` = 'mailname_bounce' AND `m`.`uid`=2000)
681 
682 ;
683 
684 --
685 -- Structure de la table `piwik_users`
686 --
687 
688 CREATE TABLE IF NOT EXISTS `piwik_users` (
689  `id` int(11) NOT NULL AUTO_INCREMENT,
690  `uid` int(11) NOT NULL,
691  `passwd` varchar(255) NOT NULL,
692  `login` varchar(255) NOT NULL,
693  `created_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
694  PRIMARY KEY (`id`),
695  UNIQUE KEY `uniq_user` (`login`)
696 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
697 
698 --
699 -- Structure de la table `piwik_sites`
700 --
701 
702 CREATE TABLE IF NOT EXISTS `piwik_sites` (
703  `id` int(11) NOT NULL AUTO_INCREMENT,
704  `uid` int(11) NOT NULL,
705  `piwik_id` int(11) NOT NULL,
706  PRIMARY KEY (`id`),
707  UNIQUE KEY `unique_site_per_user` (`uid`,`piwik_id`)
708 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
709 
710 -- Defaults subdomains to create when a domain is added
711 CREATE TABLE IF NOT EXISTS `default_subdomains` (
712  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
713  `sub` varchar(255) NOT NULL,
714  `domain_type` varchar(30) NOT NULL,
715  `domain_type_parameter` varchar(255) NOT NULL,
716  `concerned` enum('BOTH','MAIN','SLAVE') NOT NULL DEFAULT 'MAIN',
717  `enabled` boolean not null default true,
718  PRIMARY KEY (`id`),
719  UNIQUE KEY `unique_row` (`sub`(60),`domain_type`,`domain_type_parameter`(60),`concerned`)
720 ) ENGINE=InnoDB COMMENT='Contains the defaults subdomains created on domains creation';
721 
722 INSERT IGNORE INTO `default_subdomains` (`sub`, `domain_type`, `domain_type_parameter`, `concerned`) VALUES
723 ('www', 'VHOST', '%%DOMAINDIR%%', 'MAIN'),
724 ('', 'URL', 'http://www.%%DOMAIN%%', 'MAIN'),
725 ('www', 'URL', 'http://www.%%TARGETDOM%%', 'SLAVE'),
726 ('', 'URL', 'http://%%TARGETDOM%%', 'SLAVE');
727 
728 
729 -- Table for the MySQL servers
730 CREATE TABLE IF NOT EXISTS `db_servers` (
731  `id` int(10) unsigned NOT NULL auto_increment,
732  `name` varchar(255) NOT NULL,
733  `host` varchar(255) NOT NULL,
734  `login` varchar(255) NOT NULL,
735  `password` varchar(255) NOT NULL,
736  `client` varchar(255) NOT NULL,
737  PRIMARY KEY (`id`)
738 ) ENGINE=InnoDB COMMENT='List of the databases servers';
739 
740 -- Table for VM requests
741 CREATE TABLE IF NOT EXISTS `vm_history` (
742  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
743  `ip` varchar(256) NOT NULL,
744  `date_start` datetime NOT NULL,
745  `date_end` datetime DEFAULT NULL,
746  `uid` int(10) unsigned NOT NULL,
747  `serialized_object` TEXT NOT NULL,
748  PRIMARY KEY (`id`),
749  KEY `date_end` (`date_end`),
750  KEY `uid` (`uid`)
751 ) ENGINE=InnoDB COMMENT='VM Allocation requests';
752 
753 
754 CREATE TABLE IF NOT EXISTS `actions` (
755  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
756  type enum ('CREATE_FILE','FIX_USER','CREATE_DIR','DELETE','MOVE','FIX_DIR','FIX_FILE','CHMOD'),
757  parameters longtext default NULL,
758  creation timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
759  begin timestamp,
760  end timestamp,
761  user varchar(255) default NULL,
762  status int(8) unsigned default NULL,
763  PRIMARY KEY ( `id` )
764 ) ENGINE=InnoDB COMMENT = 'generic actions';
765 
766 -- version control now in MySQL
767 CREATE TABLE IF NOT EXISTS `alternc_status` (
768  `name` varchar(48) NOT NULL DEFAULT '',
769  `value` longtext NOT NULL,
770  PRIMARY KEY (`name`)
771 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT = 'stores current AlternC schema version number';
772 
773 
774 -- csrf token table
775 CREATE TABLE IF NOT EXISTS `csrf` (
776  `cookie` char(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
777  `token` char(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
778  `created` datetime NOT NULL,
779  `used` tinyint(3) unsigned NOT NULL DEFAULT '0',
780  PRIMARY KEY (`cookie`,`token`),
781  KEY `created` (`created`)
782 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='csrf tokens for AlternC forms';
783 
784 
785 -- SSL managment
786 CREATE TABLE IF NOT EXISTS `certificates` (
787  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
788  `uid` int(10) unsigned NOT NULL,
789  `status` tinyint(3) unsigned NOT NULL,
790  `fqdn` varchar(255) NOT NULL,
791  `altnames` text NOT NULL,
792  `validstart` datetime NOT NULL,
793  `validend` datetime NOT NULL,
794  `sslcsr` text NOT NULL,
795  `sslkey` text NOT NULL,
796  `sslcrt` text NOT NULL,
797  `sslchain` text NOT NULL,
798  `provider` VARCHAR(16) NOT NULL DEFAULT '',
799  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
800  PRIMARY KEY (`id`),
801  KEY `uid` (`uid`)
802 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
803 
804 
805 
806 -- make it re-exec-proof -- BUT don't overwrite existing value !
807 INSERT IGNORE INTO alternc_status SET name='alternc_version',value='3.5.0.2.php';
808