Skip to content

Commit c8ccbfb

Browse files
author
mcramer
committed
Next step of importer
1 parent e39356a commit c8ccbfb

File tree

1 file changed

+75
-16
lines changed

1 file changed

+75
-16
lines changed

interface/web/tools/import_plesk.php

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ function id_hash($id,$levels) {
548548
}
549549
}
550550

551-
// subdomains in plesk are real vhosts, so we have to treat them like domains
552-
// they have no maildomain entry
551+
// subdomains in plesk are real vhosts, so we have to treat them as vhostsubdomains
553552
$subdomains = $exdb->queryAllRecords("SELECT d.id, d.dom_id, d.name, d.displayName, d.sys_user_id, d.ssi, d.php, d.cgi, d.perl, d.python, d.fastcgi, d.miva, d.coldfusion, d.asp, d.asp_dot_net, d.ssl, d.same_ssl, d.php_handler_type, d.www_root, d.maintenance_mode, d.certificate_id FROM subdomains as d");
554553
$subdomain_ids = array();
555554
$subdomain_roots = array();
@@ -613,7 +612,7 @@ function id_hash($id,$levels) {
613612
//'ipv6_address' => '',
614613
'domain' => $entry['name'] . '.' . $parent_domain['name'],
615614
'type' => 'vhost', // can be vhost or alias
616-
'parent_domain_id' => '', // only if alias
615+
'parent_domain_id' => $domain_ids[$entry['dom_id']],
617616
'vhost_type' => 'name', // or ip (-based)
618617
'hd_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'disk_space', -1)),
619618
'traffic_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'max_traffic', -1)),
@@ -655,10 +654,10 @@ function id_hash($id,$levels) {
655654
$new_id = $old_domain['domain_id'];
656655
$params = array_merge($old_domain, $params);
657656
$msg .= "Found domain with id " . $new_id . ", updating it.<br />";
658-
$ok = $importer->sites_web_domain_update($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $new_id, $params);
657+
$ok = $importer->sites_web_vhost_subdomain_update($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $new_id, $params);
659658
//if(!$ok) $new_id = false;
660659
} else {
661-
$new_id = $importer->sites_web_domain_add($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $params, true); // read only...
660+
$new_id = $importer->sites_web_vhost_subdomain_add($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $params, true); // read only...
662661
}
663662

664663
$subdomain_ids[$entry['id']] = $new_id;
@@ -827,24 +826,43 @@ function id_hash($id,$levels) {
827826
unset($dns_records);
828827

829828

830-
/* web_folder creation is missing in the remoting lib
829+
$folder_ids = array();
830+
/* web_folder creation*/
831831
$protected_dirs = $exdb->queryAllRecords("SELECT id, non_ssl, ssl, cgi_bin, realm, path, dom_id FROM protected_dirs");
832832
foreach($protected_dirs as $entry) {
833-
$params =
833+
$params = array('server_id' => $server_id,
834+
'parent_domain_id' => $domain_ids[$entry['dom_id']],
835+
'path' => $entry['path'],
836+
'active' => 'y');
837+
$folder_id = 0;
838+
$check = $app->db->queryOneRecord('SELECT * FROM `web_folder` WHERE `parent_domain_id` = \'' . $domain_ids[$entry['dom_id']] . '\' AND `path` = \'' . $app->db->quote($entry['path']));
839+
if($check) {
840+
$importer->sites_web_folder_update($session_id, $client_id, $check['web_folder_id'], array_merge($check, $params));
841+
$folder_id = $check['web_folder_id'];
842+
} else {
843+
$folder_id = $importer->sites_web_folder_add($session_id, $client_id, $params);
844+
}
834845

835-
$new_id = $importer->sites
846+
$msg .= 'Created / updated HTTP AUTH folder: ' . $entry['path'] . '<br />';
847+
$folder_ids[$entry['id']] = $folder_id;
836848
}
837849

838-
$pd_users = $exdb->queryAllRecords("SELECT id, login, account_id, pd_id FROM pd_users");
850+
$pd_users = $exdb->queryAllRecords("SELECT u.id, u.login, u.account_id, u.pd_id, a.password FROM pd_users as u INNER JOIN accounts as a ON (a.id = u.account_id)");
839851
foreach($protected_dirs as $entry) {
840-
$params =
852+
$params = array('server_id' => $server_id,
853+
'web_folder_id' => $folder_ids[$entry['id']],
854+
'username' => $entry['login'],
855+
'password' => $entry['password'],
856+
'active' => 'y');
841857

842-
$new_id = $importer->sites
858+
$check = $app->db->queryOneRecord('SELECT * FROM `web_folder_user` WHERE `web_folder_id` = ? AND `username` = ?', $folder_id, $entry['login']);
859+
if($check) {
860+
if($dry_run == false) $importer->sites_web_folder_user_update($session_id, $client_id, $check['web_folder_user_id'], array_merge($check, $params));
861+
} else {
862+
if($dry_run == false) $importer->sites_web_folder_user_add($session_id, $client_id, $params);
863+
}
843864
}
844865

845-
846-
*/
847-
848866
/*$web_users = $exdb->queryAllRecords("SELECT id, dom_id, sys_user_id, ssi, php, cgi, perl, python, fastcgi, asp, asp_dot_net FROM web_users");
849867
foreach($web_users as $entry) {
850868
$params =
@@ -959,7 +977,7 @@ function id_hash($id,$levels) {
959977
'login' => strtolower($entry['mail_name'] . "@" . $parent_domain['name']),
960978
'password' => $entry['password'],
961979
'name' => $entry[''],
962-
'quota' => byte_to_mbyte(($entry['mbox_quota'] == -1 ? 0 : $entry['mbox_quota'])),
980+
'quota' => ($entry['mbox_quota'] == -1 ? 0 : $entry['mbox_quota']), // in bytes!
963981
'cc' => $entry['redir_addr'],
964982
'maildir' => $maildir,
965983
'homedir' => $mail_config["homedir_path"],
@@ -1077,8 +1095,49 @@ function id_hash($id,$levels) {
10771095

10781096
//$client_traffic = $exdb->queryAllRecords("SELECT t.cl_id, t.date, t.http_in, t.http_out, t.ftp_in, t.ftp_out, t.smtp_in, t.smtp_out, t.pop3_imap_in, t.pop3_imap_out FROM ClientsTraffic as t");
10791097

1080-
$databases = $exdb->queryAllRecords("SELECT d.id, d.name, d.type, d.dom_id, d.db_server_id, d.default_user_id FROM databases as d");
1098+
$db_userids = array();
1099+
10811100
$db_users = $exdb->queryAllRecords("SELECT u.id, u.login, u.account_id, u.db_id, a.password, a.type as `pwtype` FROM db_users as u LEFT JOIN accounts as a ON (a.id = u.account_id)");
1101+
foreach($db_users as $db_user) {
1102+
// database user
1103+
$params = array('server_id' => $server_id,
1104+
'database_user' => $db_user['login'],
1105+
'database_password' => $db_user['password']);
1106+
$check = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user` = \'' . $app->db->quote($db_user['login']) . '\'');
1107+
$db_user_id = 0;
1108+
if($check) {
1109+
$importer->sites_database_user_update($session_id, $client_id, $check['database_user_id'], array_merge($check, $params));
1110+
$db_user_id = $check['database_user_id'];
1111+
} else {
1112+
$db_user_id = $api->sites_database_user_add($session_id, $client_id, $params);
1113+
}
1114+
1115+
if(!isset($db_userids[$db_user['db_id']])) $db_userids[$db_user['db_id']] = $db_user_id;
1116+
print 'Created / updated database user: ' . $db_user['login'] . NL;
1117+
}
1118+
1119+
$databases = $exdb->queryAllRecords("SELECT d.id, d.name, d.type, d.dom_id, d.db_server_id, d.default_user_id FROM databases as d");
1120+
foreach($databases as $database) {
1121+
$params = array('server_id' => $server_id,
1122+
'parent_domain_id' => $domain_ids[$database['dom_id']],
1123+
'type' => 'mysql',
1124+
'database_name' => $database['name'],
1125+
'database_user_id' => $db_userids[$database['id']],
1126+
'database_ro_user_id' => 0,
1127+
'database_charset' => 'utf8',
1128+
'remote_access' => 'n',
1129+
'active' => 'y',
1130+
'remote_ips' => '');
1131+
1132+
$check = $app->db->queryOneRecord('SELECT * FROM `web_database` WHERE `database_name` = \'' . $app->db->quote($database['name']) . '\'');
1133+
if($check) {
1134+
$importer->sites_database_update($session_id, $client_id, $check['database_id'], array_merge($check, $params));
1135+
} else {
1136+
$importer->sites_database_add($session_id, $client_id, $params);
1137+
}
1138+
1139+
print 'Created / updated database: ' . $database['name'] . NL;
1140+
}
10821141

10831142
// do we need table disk_usage for import? i think we don't
10841143

0 commit comments

Comments
 (0)