Newer
Older
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
196
197
198
199
200
<?php
/*
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
Plesk(r) Importer (c) 2012, Marius Cramer, pixcept KG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
global $app, $conf;
require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');
/**
*
* @param db $exdb
* @return array
*/
function read_limit_data($exdb) {
$limits = array();
// Limits
$limit_data = $exdb->queryAllRecords("SELECT l.id, l.limit_name, l.value FROM Limits as l");
foreach($limit_data as $entry) {
if(array_key_exists($entry['id'], $limits) == false) $limits[$entry['id']] = array();
$limits[$entry['id']][$entry['limit_name']] = $entry['value'];
// limits that are there:
/*
disk_space
disk_space_soft
expiration
max_box
max_db
max_dom_aliases
max_maillists
max_mn
max_site
max_site_builder
max_subdom
max_subftp_users
max_traffic
max_traffic_soft
max_unity_mobile_sites
max_webapps
max_wu
mbox_quota
*/
}
return $limits;
}
/**
*
* @param array $limits
* @param int $id
* @param string $limit
* @param mixed $default
* @return mixed
*/
function get_limit($limits, $id, $limit, $default = false) {
$ret = $default;
if(isset($limits[$id][$limit])) $ret = $limits[$id][$limit];
return $ret;
}
function get_option($options, $option, $default = false) {
$ret = $default;
if(isset($options[$option])) $ret = $options[$option];
return $ret;
}
function add_dot($string) {
if(strlen($string) > 0 && substr($string, -1, 1) !== '.') $string .= '.';
return $string;
}
function byte_to_mbyte($byte) {
if($byte <= 0) return $byte; // limit = -1 -> unlimited
return round($byte / (1024*1024));
}
function yes_no($num, $reverse = false) {
return (($num == 1 && !$reverse) || ($num != 1 && $reverse) ? 'y' : 'n');
}
// taken from the web_domain_edit.php
function id_hash($id,$levels) {
$hash = "" . $id % 10 ;
$id /= 10 ;
$levels -- ;
while ( $levels > 0 ) {
$hash .= "/" . $id % 10 ;
$id /= 10 ;
$levels-- ;
}
return $hash;
}
/* TODO: document root rewrite on ftp account and other home directories */
//* Check permissions for module
$app->auth->check_module_permissions('admin');
//* This is only allowed for administrators
if(!$app->auth->is_admin()) die('only allowed for administrators.');
$app->uses('tpl');
$app->load('importer');
$app->tpl->newTemplate('form.tpl.htm');
$app->tpl->setInclude('content_tpl', 'templates/import_plesk.htm');
$msg = '';
$error = '';
// Start migrating plesk data
if(isset($_POST['start']) && $_POST['start'] == 1) {
//* Set variable sin template
$app->tpl->setVar('dbhost',$_POST['dbhost']);
$app->tpl->setVar('dbname',$_POST['dbname']);
$app->tpl->setVar('dbuser',$_POST['dbuser']);
$app->tpl->setVar('dbpassword',$_POST['dbpassword']);
$app->tpl->setVar('webcontent',$_POST['webcontent']);
$app->tpl->setVar('mailcontent',$_POST['mailcontent']);
//* Establish connection to external database
$msg .= 'Connecting to external database...<br />';
//* Backup DB login details
/*$conf_bak['db_host'] = $conf['db_host'];
$conf_bak['db_database'] = $conf['db_database'];
$conf_bak['db_user'] = $conf['db_user'];
$conf_bak['db_password'] = $conf['db_password'];*/
//* Set external Login details
$conf['imp_db_host'] = $_POST['dbhost'];
$conf['imp_db_database'] = $_POST['dbname'];
$conf['imp_db_user'] = $_POST['dbuser'];
$conf['imp_db_password'] = $_POST['dbpassword'];
$conf['imp_db_charset'] = $conf['db_charset'];
$conf['imp_db_new_link'] = $conf['db_new_link'];
$conf['imp_db_client_flags'] = $conf['db_client_flags'];
//* create new db object
$exdb = new db('imp');
$msg .= 'db object created...<br />';
$importer = new importer();
$session_id = 'ISPC3'; // set dummy session id for remoting lib
$msg .= 'importer object created...<br />';
// import on server
$server_id = 1;
//* Connect to DB
if($exdb !== false) {
$msg .= 'Connecting to external database done...<br />';
$limits = read_limit_data($exdb);
$msg .= 'read all limit data...<br />';
// param_id -> cl_params table - not needed for import
// tpye = admin, reseller, client
$admins = $exdb->queryAllRecords("SELECT c.id, c.parent_id, c.type, c.cr_date, c.cname, c.pname, c.login, c.account_id, a.password, a.type as `pwtype`, c.status, c.phone, c.fax, c.email, c.address, c.city, c.state, c.pcode, c.country, c.locale, c.limits_id, c.params_id, c.perm_id, c.pool_id, c.logo_id, c.tmpl_id, c.guid, c.overuse, c.vendor_id, c.external_id FROM clients as c LEFT JOIN accounts as a ON (a.id = c.account_id) WHERE c.type = 'admin' ORDER BY c.parent_id, c.id");
$resellers = $exdb->queryAllRecords("SELECT c.id, c.parent_id, c.type, c.cr_date, c.cname, c.pname, c.login, c.account_id, a.password, a.type as `pwtype`, c.status, c.phone, c.fax, c.email, c.address, c.city, c.state, c.pcode, c.country, c.locale, c.limits_id, c.params_id, c.perm_id, c.pool_id, c.logo_id, c.tmpl_id, c.guid, c.overuse, c.vendor_id, c.external_id FROM clients as c LEFT JOIN accounts as a ON (a.id = c.account_id) WHERE c.type = 'reseller' ORDER BY c.parent_id, c.id");
$clients = $exdb->queryAllRecords("SELECT c.id, c.parent_id, c.type, c.cr_date, c.cname, c.pname, c.login, c.account_id, a.password, a.type as `pwtype`, c.status, c.phone, c.fax, c.email, c.address, c.city, c.state, c.pcode, c.country, c.locale, c.limits_id, c.params_id, c.perm_id, c.pool_id, c.logo_id, c.tmpl_id, c.guid, c.overuse, c.vendor_id, c.external_id FROM clients as c LEFT JOIN accounts as a ON (a.id = c.account_id) WHERE c.type = 'client' ORDER BY c.parent_id, c.id");
$users = array_merge($admins, $resellers, $clients);
$msg .= 'read all users (' . count($users) . ')...<br />';
Loading full blame...