Skip to content

Commit d370706

Browse files
author
mcramer
committed
Update
1 parent a008884 commit d370706

File tree

1 file changed

+130
-3
lines changed

1 file changed

+130
-3
lines changed

interface/web/tools/import_plesk.php

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function id_hash($id,$levels) {
318318

319319
$web_config = $app->getconf->get_server_config($server_id,'web');
320320

321-
$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");
321+
$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");
322322
$dom_ftp_users = array();
323323
$domain_ids = array();
324324
$domain_roots = array();
@@ -548,11 +548,138 @@ function id_hash($id,$levels) {
548548
}
549549
}
550550

551-
// subdomains in plesk are real vhosts, so we have to treat them as vhostsubdomains
552-
$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");
553551
$subdomain_ids = array();
554552
$subdomain_roots = array();
555553
$subdomain_owners = array();
554+
555+
$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");
556+
foreach($subdomains as $entry) {
557+
$res = $exdb->query("SELECT d.dom_id, d.param, d.val FROM dom_param as d WHERE d.dom_id = '" . $entry['id'] . "'");
558+
$options = array();
559+
while($opt = $exdb->nextRecord()) {
560+
$options[$opt['param']] = $opt['val'];
561+
}
562+
563+
$parent_domain = $exdb->queryOneRecord("SELECT d.id, d.cl_id, d.name FROM domains as d WHERE d.id = '" . $entry['parentDomainId'] . "'");
564+
$redir_type = '';
565+
$redir_path = '';
566+
567+
if($entry['htype'] === 'std_fwd') {
568+
// redirection
569+
$redir = $exdb->queryOneRecord("SELECT f.dom_id, f.ip_address_id, f.redirect FROM forwarding as f WHERE f.dom_id = '" . $entry['id'] . "'");
570+
$redir_type = 'R,L';
571+
$redir_path = $redir['redirect'];
572+
} elseif($entry['htype'] === 'vrt_hst') {
573+
// default virtual hosting (vhost)
574+
} else {
575+
/* TODO: unknown type */
576+
}
577+
578+
$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'] . "'");
579+
if($hosting['sys_user_id']) {
580+
$dom_ftp_users[] = array('id' => 0,
581+
'dom_id' => $hosting['dom_id'],
582+
'sys_user_id' => $hosting['sys_user_id'],
583+
'login' => $hosting['login'],
584+
'account_id' => $hosting['account_id'],
585+
'home' => $hosting['home'],
586+
'shell' => $hosting['shell'],
587+
'quota' => $hosting['quota'],
588+
'mapped_to' => $hosting['mapped_to'],
589+
'password' => $hosting['password'],
590+
'pwtype' => $hosting['pwtype']
591+
);
592+
}
593+
594+
$phpmode = 'no';
595+
if(get_option($hosting, 'php', 'false') === 'true') {
596+
$mode = get_option($hosting, 'php_handler_type', 'module');
597+
if($mode === 'module') $phpmode = 'mod';
598+
else $phpmode = 'fast-cgi';
599+
/* TODO: what other options could be in "php_handler_type"? */
600+
}
601+
/* TODO: plesk offers some more options:
602+
* sys_user_id -> owner of files?
603+
* ip_address_id - needed?
604+
* fp - frontpage extensions
605+
* miva - ?
606+
* coldfusion
607+
* asp
608+
* asp_dot_net
609+
* traffic_bandwidth
610+
* max_connections
611+
*/
612+
613+
$params = array(
614+
'server_id' => $server_id,
615+
'ip_address' => '*',
616+
//'ipv6_address' => '',
617+
'domain' => $entry['name'] . '.' . $parent_domain['name'],
618+
'web_folder' => $entry['www_root'],
619+
'type' => 'vhostsubdomain', // can be vhost or alias
620+
'parent_domain_id' => $domain_ids[$entry['dom_id']],
621+
'vhost_type' => 'name', // or ip (-based)
622+
'hd_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'disk_space', -1)),
623+
'traffic_quota' => byte_to_mbyte(get_limit($limits, $entry['dom_id'], 'max_traffic', -1)),
624+
'cgi' => yes_no(get_option($hosting, 'cgi', 'false') === 'true' ? 1 : 0),
625+
'ssi' => yes_no(get_option($hosting, 'ssi', 'false') === 'true' ? 1 : 0),
626+
'suexec' => yes_no(1), // does plesk use this?!
627+
'errordocs' => get_option($options, 'apacheErrorDocs', 'false') === 'true' ? 1 : 0,
628+
'subdomain' => '', // plesk always uses this option
629+
'ssl' => yes_no(get_option($hosting, 'ssl', 'false') === 'true' ? 1 : 0),
630+
'php' => $phpmode,
631+
'fastcgi_php_version' => '', // plesk has no different php versions
632+
'ruby' => yes_no(0), // plesk has no ruby support
633+
'python' => yes_no(get_option($hosting, 'python', 'false') === 'true' ? 1 : 0),
634+
'active' => yes_no(($entry['status'] == 0 && get_option($hosting, 'maintenance_mode', 'false') !== 'true') ? 1 : 0),
635+
'redirect_type' => $redir_type,
636+
'redirect_path' => $redir_path,
637+
'seo_redirect' => '',
638+
'ssl_state' => $entry[''],
639+
'ssl_locality' => $entry[''],
640+
'ssl_organisation' => $entry[''],
641+
'ssl_organisation_unit' => $entry[''],
642+
'ssl_country' => $entry[''],
643+
'ssl_domain' => $entry[''],
644+
'ssl_request' => $entry[''],
645+
'ssl_cert' => $entry[''],
646+
'ssl_bundle' => $entry[''],
647+
'ssl_action' => $entry[''],
648+
'stats_password' => '',
649+
'stats_type' => get_option($hosting, 'webstat', 'webalizer') === 'awstats' ? 'awstats' : 'webalizer',
650+
'backup_interval' => 'none',
651+
'backup_copies' => 1,
652+
'allow_override' => 'All',
653+
'pm_process_idle_timeout' => 10,
654+
'pm_max_requests' => 0
655+
);
656+
657+
$old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '" . $entry['name'] . "'");
658+
if(!$old_domain) $old_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE CONCAT(subdomain, '.', domain) = '" . $entry['name'] . "'");
659+
if($old_domain) {
660+
$new_id = $old_domain['domain_id'];
661+
$params = array_merge($old_domain, $params);
662+
$msg .= "Found domain with id " . $new_id . ", updating it.<br />";
663+
$ok = $importer->sites_web_vhost_subdomain_update($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $new_id, $params);
664+
if($ok === false) $msg .= "&nbsp; Error: " . $importer->getFault() . "<br />";
665+
} else {
666+
$new_id = $importer->sites_web_vhost_subdomain_add($session_id, $plesk_ispc_ids[$parent_domain['cl_id']], $params, true); // read only...
667+
}
668+
669+
$subdomain_ids[$entry['id']] = $new_id;
670+
$subdomain_roots[$entry['id']] = $entry['www_root'];
671+
$subdomain_owners[$entry['id']] = $entry['cl_id'];
672+
if($new_id === false) {
673+
//something went wrong here...
674+
$msg .= "Subdomain " . $entry['id'] . " (" . $entry['name'] . ") could not be inserted.<br />";
675+
$msg .= "&nbsp; Error: " . $importer->getFault() . "<br />";
676+
} else {
677+
$msg .= "Subdomain " . $entry['id'] . " (" . $entry['name'] . ") inserted.<br />";
678+
}
679+
}
680+
681+
// subdomains in plesk are real vhosts, so we have to treat them as vhostsubdomains
682+
$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");
556683
foreach($subdomains as $entry) {
557684
$res = $exdb->query("SELECT d.dom_id, d.param, d.val FROM dom_param as d WHERE d.dom_id = '" . $entry['dom_id'] . "'");
558685
$options = array();

0 commit comments

Comments
 (0)