From cab7ea5faaa2f3510c8488e7d19d083fc05ac6ca Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Wed, 18 Sep 2013 04:17:27 -0400
Subject: [PATCH] - Fixed missing global $app in new _decode function
---
interface/web/tools/import_plesk.php | 354 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 290 insertions(+), 64 deletions(-)
diff --git a/interface/web/tools/import_plesk.php b/interface/web/tools/import_plesk.php
index 2ec9bec..de8fe7a 100644
--- a/interface/web/tools/import_plesk.php
+++ b/interface/web/tools/import_plesk.php
@@ -122,6 +122,21 @@
return $hash;
}
+$COMMANDS = 'unset HISTFILE
+MYSERVER="192.168.1.10"
+MYSQL_EXPORT_USER="root"
+MYSQL_EXPORT_PASS=""
+MYSQL_IMPORT_USER="root"
+MYSQL_IMPORT_PASS=""
+';
+
+function add_command($cmd) {
+ global $COMMANDS;
+
+ $COMMANDS .= $cmd . "\n";
+}
+
+
/* TODO: document root rewrite on ftp account and other home directories */
//* Check permissions for module
@@ -130,7 +145,7 @@
//* This is only allowed for administrators
if(!$app->auth->is_admin()) die('only allowed for administrators.');
-$app->uses('tpl');
+$app->uses('tpl,getconf');
$app->load('importer');
$app->tpl->newTemplate('form.tpl.htm');
@@ -176,7 +191,6 @@
$session_id = 'ISPC3'; // set dummy session id for remoting lib
$msg .= 'importer object created...<br />';
-
// import on server
$server_id = 1;
@@ -218,11 +232,10 @@
$msg .= $entry['login'] . ' existed, updating id ' . $old_client['client_id'] . '<br />';
}
}
-
$params = array(
'company_name' => $entry['cname'],
'contact_name' => $entry['pname'],
- //'customer_no' => '',
+ 'customer_no' => 'Plesk' . $entry['id'],
'username' => $entry['login'],
'password' => $entry['password'],
'language' => substr($entry['locale'], 0, 2), // plesk stores as de-DE or en-US
@@ -265,7 +278,7 @@
'limit_spamfilter_policy' => 0,
//'default_webserver' => '',
'limit_web_domain' => get_limit($limits, $entry['id'], 'max_site', -1),
- 'limit_web_quota' => get_limit($limits, $entry['id'], 'disk_space', -1),
+ 'limit_web_quota' => intval(get_limit($limits, $entry['id'], 'disk_space', -1)),
'web_php_options' => implode(',', $phpopts),
'limit_web_aliasdomain' => get_limit($limits, $entry['id'], 'max_dom_aliases', -1),
'limit_web_subdomain' => get_limit($limits, $entry['id'], 'max_subdom', -1),
@@ -283,7 +296,7 @@
'limit_cron' => 0,
'limit_cron_type' => 'url',
'limit_cron_frequency' => '5',
- 'limit_traffic_quota' => get_limit($limits, $entry['id'], 'max_traffic', -1),
+ 'limit_traffic_quota' => intval(get_limit($limits, $entry['id'], 'max_traffic', -1)),
'limit_openvz_vm' => 0,
'limit_openvz_vm_template_id' => ''
);
@@ -296,7 +309,7 @@
if($old_client) {
$new_id = $old_client['client_id'];
- $ok = $importer->client_update($session_id, $old_client['client_id'], $reseller_id, $params);
+ $ok = $importer->client_update($session_id, $old_client['client_id'], $reseller_id, array_merge($old_client, $params));
if($ok === false) {
}
@@ -320,7 +333,7 @@
$web_config = $app->getconf->get_server_config($server_id,'web');
- $domains = $exdb->queryAllRecords("SELECT d.id, d.cr_date, d.name, d.displayName, d.dns_zone_id, d.status, d.htype, d.real_size, d.cl_id, d.limits_id, d.params_id, d.guid, d.overuse, d.gl_filter, d.vendor_id, d.webspace_id, d.webspace_status, d.permissions_id, d.external_id FROM domains as d");
+ $domains = $exdb->queryAllRecords("SELECT d.id, d.cr_date, d.name, d.displayName, d.dns_zone_id, d.status, d.htype, d.real_size, d.cl_id, d.limits_id, d.params_id, d.guid, d.overuse, d.gl_filter, d.vendor_id, d.webspace_id, d.webspace_status, d.permissions_id, d.external_id FROM domains as d WHERE d.parentDomainId = 0");
$dom_ftp_users = array();
$domain_ids = array();
$domain_roots = array();
@@ -356,7 +369,7 @@
/* TODO: unknown type */
}
- $hosting = $exdb->queryOneRecord("SELECT h.dom_id, h.sys_user_id, h.ip_address_id, h.real_traffic, h.fp, h.fp_ssl, h.fp_enable, h.fp_adm, h.fp_pass, h.ssi, h.php, h.php_safe_mode, h.cgi, h.perl, h.python, h.fastcgi, h.miva, h.coldfusion, h.asp, h.asp_dot_net, h.ssl, h.webstat, h.same_ssl, h.traffic_bandwidth, h.max_connection, h.php_handler_type, h.www_root, h.maintenance_mode, h.certificate_id, s.login, s.account_id, s.home, s.shell, s.quota, s.mapped_to, a.password, a.type as `pwtype` FROM hosting as h LEFT JOIN sys_users as s ON (s.id = h.sys_user_id) LEFT JOIN accounts as a ON (s.account_id = a.id) WHERE h.dom_id = '" . $entry['id'] . "'");
+ $hosting = $exdb->queryOneRecord("SELECT h.dom_id, h.sys_user_id, h.ip_address_id, h.real_traffic, h.fp, h.fp_ssl, h.fp_enable, h.fp_adm, h.fp_pass, h.ssi, h.php, h.cgi, h.perl, h.python, h.fastcgi, h.miva, h.coldfusion, h.asp, h.asp_dot_net, h.ssl, h.webstat, h.same_ssl, h.traffic_bandwidth, h.max_connection, h.php_handler_type, h.www_root, h.maintenance_mode, h.certificate_id, s.login, s.account_id, s.home, s.shell, s.quota, s.mapped_to, a.password, a.type as `pwtype` FROM hosting as h LEFT JOIN sys_users as s ON (s.id = h.sys_user_id) LEFT JOIN accounts as a ON (s.account_id = a.id) WHERE h.dom_id = '" . $entry['id'] . "'");
if($hosting['sys_user_id']) {
$dom_ftp_users[] = array('id' => 0,
'dom_id' => $hosting['dom_id'],
@@ -391,7 +404,6 @@
* traffic_bandwidth
* max_connections
*/
-
$params = array(
'server_id' => $server_id,
'ip_address' => '*',
@@ -437,12 +449,13 @@
// find already inserted domain
$old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '" . $entry['name'] . "'");
+ if(!$old_domain) $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE CONCAT(subdomain, '.', domain) = '" . $entry['name'] . "'");
if($old_domain) {
$new_id = $old_domain['domain_id'];
$msg .= "Found domain with id " . $new_id . ", updating it.<br />";
$params = array_merge($old_domain, $params);
$ok = $importer->sites_web_domain_update($session_id, $plesk_ispc_ids[$entry['cl_id']], $new_id, $params);
- //if(!$ok) $new_id = false;
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->sites_web_domain_add($session_id, $plesk_ispc_ids[$entry['cl_id']], $params, true); // read only...
}
@@ -457,7 +470,17 @@
$msg .= "Domain " . $entry['id'] . " (" . $entry['name'] . ") could not be inserted.<br />";
$msg .= " Error: " . $importer->getFault() . "<br />";
} else {
- $msg .= "Domain" . $entry['id'] . " (" . $entry['name'] . ") inserted.<br />";
+ $msg .= "Domain " . $entry['id'] . " (" . $entry['name'] . ") inserted -> " . $new_id . ".<br />";
+
+ $cmd_data = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = '" . $new_id . "'");
+ $path = $cmd_data['document_root'];
+ add_command('chattr -i ' . escapeshellarg($path));
+ add_command('if [[ -f ' . $path . '/web/index.html ]] ; then rm ' . $path . '/web/index.html ; fi');
+ add_command('rsync -av --modify-window 10 --progress -e ssh root@${MYSERVER}:' . $hosting['www_root'] . '/ ' . $path . '/web/');
+ add_command('chown -R ' . $cmd_data['system_user'] . ':' . $cmd_data['system_group'] . ' ' . escapeshellarg($path));
+ add_command('grep ' . escapeshellarg($hosting['www_root']) . ' ' . $path . '/web -r -l | xargs replace ' . escapeshellarg($hosting['www_root']) . ' ' . escapeshellarg($path . '/web') . ' --');
+ add_command('chown -R root:root ' . escapeshellarg($path . '/log') . ' ' . escapeshellarg($path . '/ssl') . ' ' . escapeshellarg($path . '/web/stats'));
+ add_command('chattr +i ' . escapeshellarg($path));
}
// add domain to mail domains too
@@ -472,18 +495,19 @@
$params = array_merge($old_domain, $params);
$msg .= "Found maildomain with id " . $new_id . ", updating it.<br />";
$ok = $importer->mail_domain_update($session_id, $plesk_ispc_ids[$entry['cl_id']], $new_id, $params);
- //if(!$ok) $new_id = false;
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
+ $msg .= "Inserting new maildomain " . $entry['name'] . ".<br />";
$new_id = $importer->mail_domain_add($session_id, $plesk_ispc_ids[$entry['cl_id']], $params);
}
$maildomain_ids[$entry['id']] = $new_id;
if($new_id === false) {
//something went wrong here...
- $msg .= "Maildomain " . $entry['id'] . " (" . $entry['name'] . ") could not be inserted.<br />";
+ $msg .= "Maildomain (" . $entry['name'] . ") could not be inserted.<br />";
$msg .= " Error: " . $importer->getFault() . "<br />";
} else {
- $msg .= "Maildomain " . $entry['id'] . " (" . $entry['name'] . ") inserted.<br />";
+ $msg .= "Maildomain " . $new_id . " (" . $entry['name'] . ") inserted.<br />";
}
}
@@ -502,12 +526,13 @@
);
$old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '" . $entry['name'] . "'");
+ if(!$old_domain) $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE CONCAT(subdomain, '.', domain) = '" . $entry['name'] . "'");
if($old_domain) {
$new_id = $old_domain['domain_id'];
$params = array_merge($old_domain, $params);
$msg .= "Found domain with id " . $new_id . ", updating it.<br />";
$ok = $importer->sites_web_aliasdomain_update($session_id, $plesk_ispc_ids[$domain_owners[$entry['dom_id']]], $new_id, $params);
- //if(!$ok) $new_id = false;
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->sites_web_aliasdomain_add($session_id, $plesk_ispc_ids[$domain_owners[$entry['dom_id']]], $params);
}
@@ -532,8 +557,8 @@
$new_id = $old_domain['domain_id'];
$params = array_merge($old_domain, $params);
$msg .= "Found mail domain with id " . $new_id . ", updating it.<br />";
- $ok = $importer->sites_web_aliasdomain_update($session_id, $plesk_ispc_ids[$domain_owners[$entry['dom_id']]], $new_id, $params);
- //if(!$ok) $new_id = false;
+ $ok = $importer->mail_domain_update($session_id, $plesk_ispc_ids[$domain_owners[$entry['dom_id']]], $new_id, $params);
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->mail_domain_add($session_id, $plesk_ispc_ids[$domain_owners[$entry['dom_id']]], $params);
}
@@ -548,11 +573,155 @@
}
}
- // subdomains in plesk are real vhosts, so we have to treat them as vhostsubdomains
- $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");
$subdomain_ids = array();
$subdomain_roots = array();
$subdomain_owners = array();
+
+ $subdomains = $exdb->queryAllRecords("SELECT d.id, d.cr_date, d.name, d.displayName, d.dns_zone_id, d.status, d.htype, d.real_size, d.cl_id, d.limits_id, d.params_id, d.guid, d.overuse, d.gl_filter, d.vendor_id, d.webspace_id, d.webspace_status, d.permissions_id, d.external_id, d.parentDomainId FROM domains as d WHERE d.parentDomainId != 0");
+ foreach($subdomains as $entry) {
+ $res = $exdb->query("SELECT d.dom_id, d.param, d.val FROM dom_param as d WHERE d.dom_id = '" . $entry['id'] . "'");
+ $options = array();
+ while($opt = $exdb->nextRecord()) {
+ $options[$opt['param']] = $opt['val'];
+ }
+
+ $parent_domain = $exdb->queryOneRecord("SELECT d.id, d.cl_id, d.name FROM domains as d WHERE d.id = '" . $entry['parentDomainId'] . "'");
+ $redir_type = '';
+ $redir_path = '';
+
+ if($entry['htype'] === 'std_fwd') {
+ // redirection
+ $redir = $exdb->queryOneRecord("SELECT f.dom_id, f.ip_address_id, f.redirect FROM forwarding as f WHERE f.dom_id = '" . $entry['id'] . "'");
+ $redir_type = 'R,L';
+ $redir_path = $redir['redirect'];
+ } elseif($entry['htype'] === 'vrt_hst') {
+ // default virtual hosting (vhost)
+ } else {
+ /* TODO: unknown type */
+ }
+
+ $hosting = $exdb->queryOneRecord("SELECT h.dom_id, h.sys_user_id, h.ip_address_id, h.real_traffic, h.fp, h.fp_ssl, h.fp_enable, h.fp_adm, h.fp_pass, h.ssi, h.php, h.cgi, h.perl, h.python, h.fastcgi, h.miva, h.coldfusion, h.asp, h.asp_dot_net, h.ssl, h.webstat, h.same_ssl, h.traffic_bandwidth, h.max_connection, h.php_handler_type, h.www_root, h.maintenance_mode, h.certificate_id, s.login, s.account_id, s.home, s.shell, s.quota, s.mapped_to, a.password, a.type as `pwtype` FROM hosting as h LEFT JOIN sys_users as s ON (s.id = h.sys_user_id) LEFT JOIN accounts as a ON (s.account_id = a.id) WHERE h.dom_id = '" . $entry['id'] . "'");
+ if($hosting['sys_user_id']) {
+ $dom_ftp_users[] = array('id' => 0,
+ 'dom_id' => $hosting['dom_id'],
+ 'sys_user_id' => $hosting['sys_user_id'],
+ 'login' => $hosting['login'],
+ 'account_id' => $hosting['account_id'],
+ 'home' => $hosting['home'],
+ 'shell' => $hosting['shell'],
+ 'quota' => $hosting['quota'],
+ 'mapped_to' => $hosting['mapped_to'],
+ 'password' => $hosting['password'],
+ 'pwtype' => $hosting['pwtype']
+ );
+ }
+
+ $phpmode = 'no';
+ if(get_option($hosting, 'php', 'false') === 'true') {
+ $mode = get_option($hosting, 'php_handler_type', 'module');
+ if($mode === 'module') $phpmode = 'mod';
+ else $phpmode = 'fast-cgi';
+ /* TODO: what other options could be in "php_handler_type"? */
+ }
+ /* TODO: plesk offers some more options:
+ * sys_user_id -> owner of files?
+ * ip_address_id - needed?
+ * fp - frontpage extensions
+ * miva - ?
+ * coldfusion
+ * asp
+ * asp_dot_net
+ * traffic_bandwidth
+ * max_connections
+ */
+
+ $web_folder = $hosting['www_root'];
+ $web_folder = preg_replace('/^\/(var|srv)\/www\/(vhosts\/)?[^\/]+\/(.*)\/httpdocs.*/', '$3', $web_folder);
+
+ //if(substr($web_folder, 0, 1) === '/') $web_folder = substr($web_folder, 1);
+ //if(substr($web_folder, -1, 1) === '/') $web_folder = substr($web_folder, 0, -1);
+ $params = array(
+ 'server_id' => $server_id,
+ 'ip_address' => '*',
+ //'ipv6_address' => '',
+ 'domain' => $entry['name'],
+ 'web_folder' => $web_folder,
+ 'type' => 'vhostsubdomain', // can be vhost or alias
+ 'parent_domain_id' => $domain_ids[$entry['parentDomainId']],
+ 'vhost_type' => 'name', // or ip (-based)
+ 'hd_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'disk_space', -1)),
+ 'traffic_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'max_traffic', -1)),
+ 'cgi' => yes_no(get_option($hosting, 'cgi', 'false') === 'true' ? 1 : 0),
+ 'ssi' => yes_no(get_option($hosting, 'ssi', 'false') === 'true' ? 1 : 0),
+ 'suexec' => yes_no(1), // does plesk use this?!
+ 'errordocs' => get_option($options, 'apacheErrorDocs', 'false') === 'true' ? 1 : 0,
+ 'subdomain' => '', // plesk always uses this option
+ 'ssl' => yes_no(get_option($hosting, 'ssl', 'false') === 'true' ? 1 : 0),
+ 'php' => $phpmode,
+ 'fastcgi_php_version' => '', // plesk has no different php versions
+ 'ruby' => yes_no(0), // plesk has no ruby support
+ 'python' => yes_no(get_option($hosting, 'python', 'false') === 'true' ? 1 : 0),
+ 'active' => yes_no(($entry['status'] == 0 && get_option($hosting, 'maintenance_mode', 'false') !== 'true') ? 1 : 0),
+ 'redirect_type' => $redir_type,
+ 'redirect_path' => $redir_path,
+ 'seo_redirect' => '',
+ 'ssl_state' => $entry[''],
+ 'ssl_locality' => $entry[''],
+ 'ssl_organisation' => $entry[''],
+ 'ssl_organisation_unit' => $entry[''],
+ 'ssl_country' => $entry[''],
+ 'ssl_domain' => $entry[''],
+ 'ssl_request' => $entry[''],
+ 'ssl_cert' => $entry[''],
+ 'ssl_bundle' => $entry[''],
+ 'ssl_action' => $entry[''],
+ 'stats_password' => '',
+ 'stats_type' => get_option($hosting, 'webstat', 'webalizer') === 'awstats' ? 'awstats' : 'webalizer',
+ 'backup_interval' => 'none',
+ 'backup_copies' => 1,
+ 'allow_override' => 'All',
+ 'pm_process_idle_timeout' => 10,
+ 'pm_max_requests' => 0
+ );
+
+ $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '" . $entry['name'] . "'");
+ if(!$old_domain) $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE CONCAT(subdomain, '.', domain) = '" . $entry['name'] . "'");
+ if($old_domain) {
+ $new_id = $old_domain['domain_id'];
+ $params = array_merge($old_domain, $params);
+ $msg .= "Found domain " . $entry['name'] . " with id " . $new_id . ", updating it.<br />";
+ $ok = $importer->sites_web_vhost_subdomain_update($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $new_id, $params);
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
+ } else {
+ $new_id = $importer->sites_web_vhost_subdomain_add($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $params, true); // read only...
+ }
+
+ $subdomain_ids[$entry['id']] = $new_id;
+ $subdomain_roots[$entry['id']] = $hosting['www_root'];
+ $subdomain_owners[$entry['id']] = $entry['cl_id'];
+ if($new_id === false) {
+ //something went wrong here...
+ $msg .= "Subdomain " . $entry['id'] . " (" . $entry['name'] . ") with folder \"" . $web_folder . "\" could not be inserted.<br />";
+ $msg .= " Error: " . $importer->getFault() . "<br />";
+ } else {
+ $msg .= "Subdomain " . $entry['id'] . " (" . $entry['name'] . ") inserted.<br />";
+
+ $cmd_data = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = '" . $new_id . "'");
+ $path = $cmd_data['document_root'];
+ add_command('chattr -i ' . escapeshellarg($path));
+ add_command('if [[ -f ' . $path . '/' . $web_folder . '/index.html ]] ; then rm ' . $path . '/' . $web_folder . '/index.html ; fi');
+ add_command('rsync -av --modify-window 10 --progress -e ssh root@${MYSERVER}:' . $hosting['www_root'] . '/ ' . $path . '/' . $web_folder . '/');
+ add_command('chown -R ' . $cmd_data['system_user'] . ':' . $cmd_data['system_group'] . ' ' . escapeshellarg($path));
+ add_command('grep ' . escapeshellarg($hosting['www_root']) . ' ' . $path . '/web -r -l | xargs replace ' . escapeshellarg($hosting['www_root']) . ' ' . escapeshellarg($path . '/web') . ' --');
+ add_command('chown -R root:root ' . escapeshellarg($path . '/log') . ' ' . escapeshellarg($path . '/ssl') . ' ' . escapeshellarg($path . '/web/stats'));
+ add_command('chattr +i ' . escapeshellarg($path));
+
+ }
+ $domain_ids[$entry['id']] = $new_id;
+ }
+
+ // subdomains in plesk are real vhosts, so we have to treat them as vhostsubdomains
+ $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");
foreach($subdomains as $entry) {
$res = $exdb->query("SELECT d.dom_id, d.param, d.val FROM dom_param as d WHERE d.dom_id = '" . $entry['dom_id'] . "'");
$options = array();
@@ -584,7 +753,7 @@
/* TODO: unknown type */
}
- $hosting = $exdb->queryOneRecord("SELECT h.dom_id, h.sys_user_id, h.ip_address_id, h.real_traffic, h.fp, h.fp_ssl, h.fp_enable, h.fp_adm, h.fp_pass, h.ssi, h.php, h.php_safe_mode, h.cgi, h.perl, h.python, h.fastcgi, h.miva, h.coldfusion, h.asp, h.asp_dot_net, h.ssl, h.webstat, h.same_ssl, h.traffic_bandwidth, h.max_connection, h.php_handler_type, h.www_root, h.maintenance_mode, h.certificate_id FROM hosting as h WHERE h.dom_id = '" . $entry['dom_id'] . "'");
+ $hosting = $exdb->queryOneRecord("SELECT h.dom_id, h.sys_user_id, h.ip_address_id, h.real_traffic, h.fp, h.fp_ssl, h.fp_enable, h.fp_adm, h.fp_pass, h.ssi, h.php, h.cgi, h.perl, h.python, h.fastcgi, h.miva, h.coldfusion, h.asp, h.asp_dot_net, h.ssl, h.webstat, h.same_ssl, h.traffic_bandwidth, h.max_connection, h.php_handler_type, h.www_root, h.maintenance_mode, h.certificate_id FROM hosting as h WHERE h.dom_id = '" . $entry['dom_id'] . "'");
$hosting = array_merge($hosting, $entry); //settings from subdomain override parent settings
$phpmode = 'no';
@@ -606,12 +775,16 @@
* max_connections
*/
+ $web_folder = $entry['www_root'];
+ $web_folder = preg_replace('/^\/(var|srv)\/www\/(vhosts\/)?[^\/]+\/(.*)\/httpdocs.*/', '$3', $web_folder);
+
$params = array(
'server_id' => $server_id,
'ip_address' => '*',
//'ipv6_address' => '',
'domain' => $entry['name'] . '.' . $parent_domain['name'],
- 'type' => 'vhost', // can be vhost or alias
+ 'web_folder' => $web_folder,
+ 'type' => 'vhostsubdomain', // can be vhost or alias
'parent_domain_id' => $domain_ids[$entry['dom_id']],
'vhost_type' => 'name', // or ip (-based)
'hd_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'disk_space', -1)),
@@ -620,7 +793,7 @@
'ssi' => yes_no(get_option($hosting, 'ssi', 'false') === 'true' ? 1 : 0),
'suexec' => yes_no(1), // does plesk use this?!
'errordocs' => get_option($options, 'apacheErrorDocs', 'false') === 'true' ? 1 : 0,
- 'subdomain' => 'www', // plesk always uses this option
+ 'subdomain' => '', // plesk always uses this option
'ssl' => yes_no(get_option($hosting, 'ssl', 'false') === 'true' ? 1 : 0),
'php' => $phpmode,
'fastcgi_php_version' => '', // plesk has no different php versions
@@ -650,12 +823,13 @@
);
$old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '" . $entry['name'] . '.' . $parent_domain['name'] . "'");
+ if(!$old_domain) $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE CONCAT(subdomain, '.', domain) = '" . $entry['name'] . "'");
if($old_domain) {
$new_id = $old_domain['domain_id'];
$params = array_merge($old_domain, $params);
$msg .= "Found domain with id " . $new_id . ", updating it.<br />";
$ok = $importer->sites_web_vhost_subdomain_update($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $new_id, $params);
- //if(!$ok) $new_id = false;
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->sites_web_vhost_subdomain_add($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $params, true); // read only...
}
@@ -669,11 +843,20 @@
$msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$msg .= "Subdomain " . $entry['id'] . " (" . $entry['name'] . ") inserted.<br />";
+
+ $cmd_data = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = '" . $new_id . "'");
+ $path = $cmd_data['document_root'];
+ add_command('chattr -i ' . escapeshellarg($path));
+ add_command('if [[ -f ' . $path . '/' . $web_folder . '/index.html ]] ; then rm ' . $path . '/' . $web_folder . '/index.html ; fi');
+ add_command('rsync -av --modify-window 10 --progress -e ssh root@${MYSERVER}:' . $entry['www_root'] . '/ ' . $path . '/' . $web_folder . '/');
+ add_command('chown -R ' . $cmd_data['system_user'] . ':' . $cmd_data['system_group'] . ' ' . escapeshellarg($path));
+ add_command('chown -R root:root ' . escapeshellarg($path . '/log') . ' ' . escapeshellarg($path . '/ssl') . ' ' . escapeshellarg($path . '/web/stats'));
+ add_command('chattr +i ' . escapeshellarg($path));
}
}
// dns have to be done AFTER domains due to missing client info
-
+ /*
$dns_zone_ids = array();
$dns_zone_serials = array();
$dns_zones = $exdb->queryAllRecords("SELECT d.id, d.name, d.displayName, d.status, d.email, d.type, d.ttl, d.ttl_unit, d.refresh, d.refresh_unit, d.retry, d.retry_unit, d.expire, d.expire_unit, d.minimum, d.minimum_unit, d.serial_format, d.serial FROM dns_zone as d");
@@ -707,7 +890,7 @@
if($old_id) {
$new_id = $old_id;
$ok = $importer->dns_zone_update($session_id, $client_id, $old_id, $params);
- //if(!$ok) {
+ /if($ok === false) {
// $msg .= "DNS " . $entry['id'] . " (" . $entry['name'] . ") could not be updated.<br />";
// $msg .= " Error: " . $importer->getFault() . "<br />";
//} else {
@@ -727,10 +910,10 @@
$dns_zone_serials[$entry['id']] = $entry['serial'];
}
unset($dns_zones);
-
+ */
/* types:
* PTR, NS, A, CNAME, MX, TXT, AAAA
- */
+ *//*
$dns_records = $exdb->queryAllRecords("SELECT d.id, d.dns_zone_id, d.type, d.displayHost, d.host, d.displayVal, d.val, d.opt, d.time_stamp FROM dns_recs as d");
foreach($dns_records as $entry) {
$dns_id = (array_key_exists($entry['dns_zone_id'], $dns_zone_ids) ? $dns_zone_ids[$entry['dns_zone_id']] : 0);
@@ -767,49 +950,49 @@
$params['aux'] = $entry['opt'];
if($old_id) {
$ok = $importer->dns_mx_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_mx_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'PTR') {
if($old_id) {
$ok = $importer->dns_ptr_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_ptr_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'A') {
if($old_id) {
$ok = $importer->dns_a_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_a_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'AAAA') {
if($old_id) {
$ok = $importer->dns_aaaa_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_aaaa_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'TXT') {
if($old_id) {
$ok = $importer->dns_txt_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_txt_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'CNAME') {
if($old_id) {
$ok = $importer->dns_cname_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_cname_add($session_id, $client_id, $params);
}
} elseif($entry['type'] === 'NS') {
if($old_id) {
$ok = $importer->dns_ns_update($session_id, $client_id, $old_id, $params);
- if($ok) $new_id = $old_id;
+ if($ok !== false) $new_id = $old_id;
} else {
$new_id = $importer->dns_ns_add($session_id, $client_id, $params);
}
@@ -817,49 +1000,66 @@
if($new_id === false) {
//something went wrong here...
$msg .= "DNS " . $entry['id'] . " (" . $entry['name'] . ") could not be inserted/updated.<br />";
- $msg .= " Error: " . $importer->getFault() . "<br />";
+ $msg .= " Error: " . $importer->getFault() . "<br />" . var_export($params, true) . '<br />';
} else {
$msg .= "DNS " . $entry['id'] . " (" . $entry['name'] . ") inserted/updated.<br />";
}
}
unset($dns_records);
-
+ */
$folder_ids = array();
/* web_folder creation*/
- $protected_dirs = $exdb->queryAllRecords("SELECT id, non_ssl, ssl, cgi_bin, realm, path, dom_id FROM protected_dirs");
+ $protected_dirs = $exdb->queryAllRecords("SELECT `id`, `non_ssl`, `ssl`, `cgi_bin`, `realm`, `path`, `dom_id` FROM protected_dirs");
foreach($protected_dirs as $entry) {
+ if($entry['path'] == 'plesk-stat') continue;
+
$params = array('server_id' => $server_id,
'parent_domain_id' => $domain_ids[$entry['dom_id']],
'path' => $entry['path'],
'active' => 'y');
+
+ $client_id = $plesk_ispc_ids[$domain_owners[$entry['dom_id']]];
+
$folder_id = 0;
- $check = $app->db->queryOneRecord('SELECT * FROM `web_folder` WHERE `parent_domain_id` = \'' . $domain_ids[$entry['dom_id']] . '\' AND `path` = \'' . $app->db->quote($entry['path']));
+ $check = $app->db->queryOneRecord('SELECT * FROM `web_folder` WHERE `parent_domain_id` = \'' . $domain_ids[$entry['dom_id']] . '\' AND `path` = \'' . $app->db->quote($entry['path']) . '\'');
if($check) {
- $importer->sites_web_folder_update($session_id, $client_id, $check['web_folder_id'], array_merge($check, $params));
+ $ok = $importer->sites_web_folder_update($session_id, $client_id, $check['web_folder_id'], array_merge($check, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
$folder_id = $check['web_folder_id'];
+ $msg .= 'Updated HTTP AUTH folder (' . $folder_id . '): ' . $entry['path'] . '<br />';
} else {
$folder_id = $importer->sites_web_folder_add($session_id, $client_id, $params);
+ $msg .= 'Created HTTP AUTH folder (' . $folder_id . '): ' . $entry['path'] . '<br />';
+ if(!$folder_id) $msg .= " Error: " . $importer->getFault() . "<br />" . var_export($params, true) . '<br />';
}
- $msg .= 'Created / updated HTTP AUTH folder: ' . $entry['path'] . '<br />';
$folder_ids[$entry['id']] = $folder_id;
}
- $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)");
- foreach($protected_dirs as $entry) {
+ $pd_users = $exdb->queryAllRecords("SELECT u.id, u.login, u.account_id, u.pd_id, a.password, d.dom_id FROM pd_users as u INNER JOIN protected_dirs as d ON (d.id = u.pd_id) INNER JOIN accounts as a ON (a.id = u.account_id)");
+ foreach($pd_users as $entry) {
$params = array('server_id' => $server_id,
- 'web_folder_id' => $folder_ids[$entry['id']],
+ 'web_folder_id' => $folder_ids[$entry['pd_id']],
'username' => $entry['login'],
'password' => $entry['password'],
'active' => 'y');
+ if($entry['login'] == '' || !isset($folder_ids[$entry['pd_id']])) {
+ $msg .= 'Skipping Folder user because of missing data.<br />';
+ continue;
+ }
+ $client_id = $plesk_ispc_ids[$domain_owners[$entry['dom_id']]];
- $check = $app->db->queryOneRecord('SELECT * FROM `web_folder_user` WHERE `web_folder_id` = ? AND `username` = ?', $folder_id, $entry['login']);
+ $check = $app->db->queryOneRecord('SELECT * FROM `web_folder_user` WHERE `web_folder_id` = ' . intval($folder_ids[$entry['pd_id']]) . ' AND `username` = \'' . $entry['login'] . '\'');
if($check) {
- if($dry_run == false) $importer->sites_web_folder_user_update($session_id, $client_id, $check['web_folder_user_id'], array_merge($check, $params));
+ $ok = $importer->sites_web_folder_user_update($session_id, $client_id, $check['web_folder_user_id'], array_merge($check, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
+ $msg .= 'Updated HTTP AUTH folder user (' . $fu_id . '): ' . $entry['login'] . '<br />';
} else {
- if($dry_run == false) $importer->sites_web_folder_user_add($session_id, $client_id, $params);
+ $fu_id = $importer->sites_web_folder_user_add($session_id, $client_id, $params);
+ $msg .= 'Created HTTP AUTH folder user (' . $fu_id . '): ' . $entry['login'] . '<br />';
+ if(!$fu_id) $msg .= " Error: " . $importer->getFault() . "<br />" . var_export($params, true) . '<br />';
}
}
@@ -874,7 +1074,7 @@
$ftp_users = array_merge($ftp_users, $dom_ftp_users);
foreach($ftp_users as $entry) {
$parent_domain = $exdb->queryOneRecord("SELECT d.id, d.cl_id, d.name FROM domains as d WHERE d.id = '" . $entry['dom_id'] . "'");
-
+ if(!$entry['id']) continue;
$ispc_dom_id = $domain_ids[$entry['dom_id']];
$client_id = $plesk_ispc_ids[$domain_owners[$entry['dom_id']]];
if(!$client_id) $client_id = 0;
@@ -912,7 +1112,7 @@
'active' => yes_no(1),
'uid' => $uid,
'gid' => $gid,
- 'dir' => $document_root,
+ 'dir' => $document_root . (substr($document_root, -1) !== '/' ? '/' : ''),
'sys_groupid' => $sys_groupid
//'quota_files' => $entry[''],
//'ul_ratio' => $entry[''],
@@ -927,8 +1127,8 @@
$msg .= "FTP Account conflicts with other domain!<br />";
} else {
$new_id = $old_ftp['ftp_user_id'];
- $ok = $importer->sites_ftp_user_update($session_id, $client_id, $new_id, $params);
- //if(!$ok) $new_id = false;
+ $ok = $importer->sites_ftp_user_update($session_id, $client_id, $new_id, array_merge($old_ftp, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
}
} else {
$new_id = $importer->sites_ftp_user_add($session_id, $client_id, $params);
@@ -1000,8 +1200,8 @@
$old_mail = $app->db->queryOneRecord("SELECT mailuser_id FROM mail_user WHERE email = '" . $entry['mail_name'] . "@" . $parent_domain['name'] . "'");
if($old_mail) {
$new_id = $old_mail['mailuser_id'];
- $ok = $importer->mail_user_update($session_id, $client_id, $new_id, $params);
- //if(!$ok) $new_id = false;
+ $ok = $importer->mail_user_update($session_id, $client_id, $new_id, array_merge($old_mail, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->mail_user_add($session_id, $client_id, $params);
}
@@ -1012,6 +1212,13 @@
$msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$msg .= "Mail " . $entry['id'] . " (" . $entry['mail_name'] . "@" . $parent_domain['name'] . ") inserted/updated.<br />";
+
+ add_command('rsync -av --delete-after --modify-window 10 --progress -e ssh root@${MYSERVER}:/var/qmail/mailnames/' . $parent_domain['name'] . '/' . strtolower($entry['mail_name']) . '/Maildir/ ' . $maildir . '/Maildir/');
+ add_command('chown -R vmail:vmail ' . $maildir);
+ add_command('chmod 744 ' . $maildir . '/Maildir/subscriptions');
+ add_command('chmod 600 ' . $maildir . '/Maildir/dovecot-*');
+ add_command('chmod 700 ' . $maildir . '/Maildir/cur ' . $maildir . '/Maildir/new ' . $maildir . '/Maildir/tmp');
+ add_command('chmod 600 ' . $maildir . '/Maildir/cur/* ' . $maildir . '/Maildir/new/* ' . $maildir . '/Maildir/tmp/*');
}
$mail_ids[$entry['id']] = $new_id;
}
@@ -1030,8 +1237,8 @@
$old_mail = $app->db->queryOneRecord("SELECT forwarding_id FROM mail_forwarding WHERE source = '" . $entry['mail_name'] . "@" . $parent_domain['name'] . "' AND destination = '" . $redir['address'] . "'");
if($old_mail) {
$new_id = $old_mail['forwarding_id'];
- $ok = $importer->mail_forward_update($session_id, $client_id, $new_id, $params);
- //if(!$ok) $new_id = false;
+ $ok = $importer->mail_forward_update($session_id, $client_id, $new_id, array_merge($old_mail, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->mail_forward_add($session_id, $client_id, $params);
}
@@ -1069,8 +1276,8 @@
$old_mail = $app->db->queryOneRecord("SELECT forwarding_id FROM mail_forwarding WHERE source = '" . $entry['alias'] . "@" . $parent_domain['name'] . "' AND destination = '" . $entry['mail_name'] . "@" . $parent_domain['name'] . "'");
if($old_mail) {
$new_id = $old_mail['forwarding_id'];
- $ok = $importer->mail_alias_update($session_id, $client_id, $new_id, $params);
- //if(!$ok) $new_id = false;
+ $ok = $importer->mail_alias_update($session_id, $client_id, $new_id, array_merge($old_mail, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$new_id = $importer->mail_alias_add($session_id, $client_id, $params);
}
@@ -1097,26 +1304,32 @@
$db_userids = array();
- $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)");
+ $db_users = $exdb->queryAllRecords("SELECT u.id, u.login, u.account_id, u.db_id, a.password, a.type as `pwtype`, d.dom_id FROM db_users as u INNER JOIN data_bases as d ON (d.id = u.db_id) LEFT JOIN accounts as a ON (a.id = u.account_id)");
foreach($db_users as $db_user) {
// database user
$params = array('server_id' => $server_id,
'database_user' => $db_user['login'],
'database_password' => $db_user['password']);
+
+ $client_id = $plesk_ispc_ids[$domain_owners[$db_user['dom_id']]];
+
$check = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user` = \'' . $app->db->quote($db_user['login']) . '\'');
$db_user_id = 0;
if($check) {
- $importer->sites_database_user_update($session_id, $client_id, $check['database_user_id'], array_merge($check, $params));
+ $ok = $importer->sites_database_user_update($session_id, $client_id, $check['database_user_id'], array_merge($check, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
$db_user_id = $check['database_user_id'];
} else {
- $db_user_id = $api->sites_database_user_add($session_id, $client_id, $params);
+ $db_user_id = $importer->sites_database_user_add($session_id, $client_id, $params);
}
if(!isset($db_userids[$db_user['db_id']])) $db_userids[$db_user['db_id']] = $db_user_id;
- print 'Created / updated database user: ' . $db_user['login'] . NL;
+ $msg .= 'Created / updated database user: ' . $db_user['login'] . '<br />';
}
+
+ add_command('# DATABASES');
- $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");
+ $databases = $exdb->queryAllRecords("SELECT d.id, d.name, d.type, d.dom_id, d.db_server_id, d.default_user_id FROM `data_bases` as d");
foreach($databases as $database) {
$params = array('server_id' => $server_id,
'parent_domain_id' => $domain_ids[$database['dom_id']],
@@ -1129,14 +1342,20 @@
'active' => 'y',
'remote_ips' => '');
+ $client_id = $plesk_ispc_ids[$domain_owners[$database['dom_id']]];
+
$check = $app->db->queryOneRecord('SELECT * FROM `web_database` WHERE `database_name` = \'' . $app->db->quote($database['name']) . '\'');
if($check) {
- $importer->sites_database_update($session_id, $client_id, $check['database_id'], array_merge($check, $params));
+ $ok = $importer->sites_database_update($session_id, $client_id, $check['database_id'], array_merge($check, $params));
+ if($ok === false) $msg .= " Error: " . $importer->getFault() . "<br />";
} else {
$importer->sites_database_add($session_id, $client_id, $params);
}
- print 'Created / updated database: ' . $database['name'] . NL;
+ add_command('for T in `mysql -u ${MYSQL_IMPORT_USER} -p${MYSQL_IMPORT_PASS} ' . $database['name'] . ' -e \'show tables\' | awk \'{ print $1}\' | grep -v \'^Tables\'` ; do echo "DROP TABLE \\`$T\\`" ; mysql -u ${MYSQL_IMPORT_USER} -p${MYSQL_IMPORT_PASS} ' . $database['name'] . ' -e "DROP TABLE \\`$T\\`" ; done');
+ add_command('mysqldump -cCQ --quote-names --hex-blob -h ${MYSERVER} -u ${MYSQL_EXPORT_USER} -p${MYSQL_EXPORT_PASS} ' . $database['name'] . ' | mysql -D ' . $database['name'] . ' -u ${MYSQL_IMPORT_USER} -p${MYSQL_IMPORT_PASS}');
+
+ $msg .= 'Created / updated database: ' . $database['name'] . '<br />';
}
// do we need table disk_usage for import? i think we don't
@@ -1174,6 +1393,13 @@
id, login, account_id, home, shell, quota, mapped_to
*/
+ add_command('unset MYSERVER');
+ add_command('unset MYSQL_EXPORT_USER');
+ add_command('unset MYSQL_EXPORT_PASS');
+ add_command('unset MYSQL_IMPORT_USER');
+ add_command('unset MYSQL_IMPORT_PASS');
+ add_command('# END');
+ file_put_contents('/tmp/plesk_import_commands.sh', $COMMANDS);
} else {
$msg .= 'Connecting to external database failed!<br />';
$msg .= $exdb->connect_error;
--
Gitblit v1.9.1