This repository has been archived by the owner on Aug 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.php
195 lines (185 loc) · 7.47 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
if(is_file('./inc/config.local.inc.php')) {
die('A configuration file does already exist. Please proceed to <a href="index.php">login screen</a>.');
}
ob_start('ob_gzhandler');
include('./inc/config.inc.php');
include('./inc/functions.inc.php');
@include('adodb/adodb.inc.php');
@include('Log.php');
// definition of configuration file's format
$config = <<<EOT
<?php
/* Created by setup.php (%s) on %s */
\$cfg['user_ignore'] = array('%s');
\$cfg['passwd']['strategy'] = '%s';
// repeat these lines for every server or virtual domain
\$cfg['Servers']['verbose'][] = '%s';
\$cfg['Servers']['number'][] = \$i++;
\$cfg['Servers']['DB'][] = array(
'DSN' => '%s',
'PREFIX' => '%s',
);
\$cfg['Servers']['IMAP'][] = array(
'TYPE' => '%s',
'HOST' => '%s',
'PORT' => %d,
'ADMIN' => '%s',
'PASS' => '%s',
'VDOM' => ''
);
?>
EOT;
// now comes processing
include('./templates/setup/header.tpl');
switch($_GET['step']) {
case '3':
$db = false;
if($_POST['dsn'] != '') {
$db = @ADONewConnection($_POST['dsn']);
}
if(!$db) {
$failure = 'Cannot connect to DB. Please correct your DSN';
} else {
$cfg['passwd']['strategy'] = $_POST['hashing_strategy'];
$tables
= array('user' => 'user.adodb.txt',
'domains' => 'domains.adodb.txt',
'virtual' => 'virtual.adodb.txt',
'virtual_regexp'=> 'virtual_regexp.adodb.txt',
'imap_demo' => 'imap_demo.adodb.txt',
);
// create tables
$status = array();
foreach($tables as $name=>$tablefile) {
$definition = file_get_contents('./inc/database/'.$tablefile);
$dict = NewDataDictionary($db);
$sqlarray = $dict->CreateTableSQL($_POST['prefix'].$name, $definition);
$status[$name] = array($_POST['prefix'].$name,
$dict->ExecuteSQLArray($sqlarray),
);
$cfg['tablenames'][$name] = $_POST['prefix'].$name;
}
// add sample data - only if table has been created and did not exist
if($status['imap_demo'][1] == 2) {
$db->Execute('INSERT INTO '.$_POST['prefix'].'imap_demo (mailbox,used,qmax,ACL) VALUES (?,?,?,?)',
array('shared', 0, 0, 'anyone lrswipcda'));
if($_POST['imap_type'] == 'fake-imap') {
$db->Execute('INSERT INTO '.$_POST['prefix'].'imap_demo (mailbox,used,qmax,ACL) VALUES (?,?,?,?)',
array('user.'.$_POST['admin_user'], 0, 0, $_POST['admin_user'].' lrswipcda'));
}
}
if($status['user'][1] == 2 or $status['user'][1] == 1) {
if($_POST['imap_user'] == '') {
$_POST['imap_user'] = '---';
}
$db->Execute('INSERT INTO '.$_POST['prefix'].'user VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
array( array($_POST['admin_user'], 'Admin John Doe', $_POST['admin_user'], $_POST['admin_user'].'@example.com', '', 'all', 1, time(), 0, 10000, 100, 2, 2, 2),
array($_POST['imap_user'], $_POST['imap_user'], $_POST['imap_user'], '[email protected]', '', 'none', 1, time(), 0, 0, 0, 0, 0, 1),
));
User::$db = $db;
User::$tablenames = $cfg['tablenames'];
$tmp = new User($_POST['admin_user']);
$tmp->password->set($_POST['admin_pass']);
$tmp = new User($_POST['imap_user']);
$tmp->password->set($_POST['imap_pass']);
// create superuser
if($_POST['imap_type'] != 'fake-imap') {
$imap = IMAP_get_instance(array('HOST' => $_POST['imap_host'],
'PORT' => $_POST['imap_port'],
'ADMIN' => $_POST['imap_user'],
'PASS' => $_POST['imap_pass'],
), $_POST['imap_type']);
$imap->createmb($imap->format_user($_POST['admin_user']));
if(isset($cfg['folders']['create_default']) && is_array($cfg['folders']['create_default'])) {
foreach($cfg['folders']['create_default'] as $new_folder) {
$imap->createmb($imap->format_user($_POST['admin_user'], $new_folder));
}
}
}
}
if($status['domains'][1] == 2) {
$dict->ExecuteSQLArray($dict->CreateIndexSQL('domain', $_POST['prefix'].'domains', 'domain', array('UNIQUE')));
$dict->ExecuteSQLArray($dict->CreateIndexSQL('owner', $_POST['prefix'].'domains', 'owner'));
$db->Execute('INSERT INTO '.$_POST['prefix'].'domains (ID,domain,categories,owner,a_admin) VALUES (?,?,?,?,?)',
array(1, 'example.com', 'all, samples', $_POST['admin_user'], $_POST['admin_user']));
}
if($status['virtual'][1] == 2) {
$dict->ExecuteSQLArray($dict->CreateIndexSQL('owner', $_POST['prefix'].'virtual', 'owner'));
$db->Execute('INSERT INTO '.$_POST['prefix'].'virtual (address,dest,owner,active,neu) VALUES (?,?,?,?,?)',
array('[email protected]', $_POST['admin_user'], $_POST['admin_user'], 1, 1));
}
if($status['virtual_regexp'][1] == 2) {
$dict->ExecuteSQLArray($dict->CreateIndexSQL('owner', $_POST['prefix'].'virtual_regexp', 'owner'));
$db->Execute('INSERT INTO '.$_POST['prefix'].'virtual_regexp (ID,reg_exp,dest,owner,active,neu) VALUES (?,?,?,?,?,?)',
array(11, '/^(postmaster|abuse|security|root)@example\\.com$/', $_POST['admin_user'], $_POST['admin_user'], 1, 1));
}
$config = sprintf($config, $version, date('r'),
$_POST['imap_user'] != '' ? $_POST['imap_user'] : '---',
$_POST['hashing_strategy'],
'my database', $_POST['dsn'], $_POST['prefix'],
$_POST['imap_type'], $_POST['imap_host'], $_POST['imap_port'], $_POST['imap_user'], $_POST['imap_pass']);
if(!file_exists('./inc/config.local.inc.php')) {
$written = strlen($config) == @file_put_contents('./inc/config.local.inc.php', $config);
} else {
$written = false;
}
}
include('./templates/setup/step3.tpl');
break;
case '2':
$available_db = array();
if(function_exists('mysql_connect')) $available_db[] = array('mysql', 'mysql://user:pwd@host/mydb');
if(function_exists('mysqli_connect')) $available_db[] = array('mysqli', 'mysqli://user:pwd@host/mydb');
if(function_exists('oci_connect')) $available_db[] = array('oci8', 'oci8://user:pwd@host/sid');
if(function_exists('pg_connect')) $available_db[] = array('postgres', 'postgres://user:pwd@host/mydb');
include('./templates/setup/step2.tpl');
break;
default:
case '1':
$expectations
= array('asp_tags' => 0,
'display_errors' => 0,
'log_errors' => 1,
'ignore_repeated_errors' => 1,
'ignore_repeated_source' => 1,
);
$requirements
= array(
'short_open_tag' => 1,
);
$checks
= array(
array('PHP is version 5.1.0 or later?', version_compare(PHP_VERSION, '5.1.0', '>=')),
array('Multibyte String support active?', function_exists('mb_convert_encoding')),
array('Socket or IMAP support available?', function_exists('fsockopen') || function_exists('imap_open')),
array('MySQL or MySQLi, PostgreSQL, Oracle (OCI8)?', function_exists('mysql_connect') || function_exists('mysqli_connect') || function_exists('pg_connect') || function_exists('oci_connect')),
array('Is ADOdb installed?', function_exists('ADONewConnection')),
array('Is PEAR::Log installed?', class_exists('Log')),
array('Is PECL::idn installed?', function_exists('idn_to_ascii') && function_exists('idn_to_utf8')),
);
$reality = array();
foreach($expectations as $value=>$expected) {
$reality[]
= array(
'value' => $value,
'expected' => $expected ? true : false,
'is' => ini_get($value) ? true : false,
'okay' => (ini_get($value) == $expected),
'mandatory' => false,
);
}
foreach($requirements as $value=>$expected) {
$reality[]
= array(
'value' => $value,
'expected' => $expected ? true : false,
'is' => ini_get($value) ? true : false,
'okay' => (ini_get($value) == $expected),
'mandatory' => true,
); }
include('./templates/setup/step1.tpl');
break;
}
include('./templates/setup/footer.tpl');
?>