Skip to content
import_plesk.php 59 KiB
Newer Older
            // select all redirs for this address
            $mail_redir = $exdb->queryAllRecords("SELECT id, mn_id, address FROM mail_redir WHERE mn_id = '" . $entry['id'] . "'");
            foreach($mail_redir as $redir) {
                $params = array(
                                'server_id' => $server_id,
                                'source' => $entry['mail_name'] . "@" . $parent_domain['name'],
                                'destination' => $redir['address'],
                                'type' => 'forward', // or forward
                                'active' => yes_no(1)
                                );
                
                $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;
                } else {
                    $new_id = $importer->mail_forward_add($session_id, $client_id, $params);
                }

                if($new_id === false) {
                    //something went wrong here...
                    $msg .= "Mail redirect " . $entry['id'] . " (" . $entry['mail_name'] . "@" . $parent_domain['name'] . " to " . $redir['address'] . ") could not be inserted/updated.<br />";
                    $msg .= "&nbsp; Error: " . $importer->getFault() . "<br />";
                } else {
                    $msg .= "Mail redirect " . $entry['id'] . " (" . $entry['mail_name'] . "@" . $parent_domain['name'] . " to " . $redir['address'] . ") inserted/updated.<br />";
                }
            }
            unset($mail_redir);
        }
        unset($mail_addresses);
        
        $mail_aliases = $exdb->queryAllRecords("SELECT a.id, a.mn_id, a.alias, m.dom_id, m.mail_name FROM mail_aliases as a INNER JOIN mail as m ON (m.id = a.mn_id)");
        foreach($mail_aliases 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(!$parent_domain) {
                $msg .= "Could not insert/update mail alias " . $entry['alias'] . " as domain is missing.<br />";
                continue;
            }
            
            $params = array(
                            'server_id' => $server_id,
                            'source' => $entry['alias'] . "@" . $parent_domain['name'],
                            'destination' => $entry['mail_name'] . "@" . $parent_domain['name'],
                            'type' => 'alias', // or forward
                            'active' => yes_no(1)
                            );
            $client_id = $plesk_ispc_ids[$domain_owners[$entry['dom_id']]];
        
            $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;
            } else {
                $new_id = $importer->mail_alias_add($session_id, $client_id, $params);
            }
            
            if($new_id === false) {
                //something went wrong here...
                $msg .= "Mail alias " . $entry['id'] . " (" . $entry['alias'] . "@" . $parent_domain['name'] . ") could not be inserted/updated.<br />";
                $msg .= "&nbsp; Error: " . $importer->getFault() . "<br />";
            } else {
                $msg .= "Mail alias " . $entry['id'] . " (" . $entry['alias'] . "@" . $parent_domain['name'] . ") inserted/updated.<br />";
            }
        }
        unset($mail_aliases);
        
        //spamfilter // preferences = true/false, username = email address, can be *@*
        //id, username, preferences
        
        //spamfilter_preferences
        //prefid, spamfilter_id, preference, value
        
        
        
        //$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");
        
        $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");
        $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)");
        
        // do we need table disk_usage for import? i think we don't
        
        // name is domain name, displayName is including "Umlaute"
        //$anon_ftp = $exdb->queryAllRecords("SELECT f.id, f.dom_id, f.max_conn, f.bandwidth, f.incoming, f.incoming_readable, f.incoming_subdirs, f.status, f.quota, f.display_login, f.login_text FROM anon_ftp as f");
        
        
        //DomainServices
        //id, dom_id, type, status, parameters_id, ipCollectionId
        
        //DomainsTraffic
        //dom_id, date, http_in, http_out, ftp_in, ftp_out, smtp_in, smtp_out, pop3_imap_in, pop3_imap_out
        
        
        //IP_Adresses
        //id, ip_address, mask, iface, ssl_certificate_id, default_domain_id, ftps, main, status
        
        //ip_pool
        //id, ip_address_id, type

        /* TODO:
                */
        //misc // needed? global settings
        //param, val
        
        //Permissions
        //id, permission, value
        
        //smb_users // pass is base64 encoded plaintext
        //id, login, password, contactName, email, companyName, phone, fax, address, city, state, zip, country, creationDate, isBuiltIn, roleId, uuid, isLocked, authCookie, sessionId, externalId, ownerId, isDomainAdmin, additionalInfo, imNumber, imType, isLegacyUser
        
        /* TODO: 
        sys_users // mapped_to = parent_id
        id, login, account_id, home, shell, quota, mapped_to
        
         */
	} else {
        $msg .= 'Connecting to external database failed!<br />';
        $msg .= $exdb->connect_error;
        $msg .= substr($exdb->errorMessage, 0, 25);
	
		$error .= $exdb->errorMessage;
	}
	
	//* restore db login details
	/*$conf['db_host'] = $conf_bak['db_host'];
	$conf['db_database'] = $conf_bak['db_database'];
	$conf['db_user'] = $conf_bak['db_user'];
	$conf['db_password'] = $conf_bak['db_password'];*/
	
}

$app->tpl->setVar('msg',$msg);
$app->tpl->setVar('error',$error);


$app->tpl_defaults();
$app->tpl->pparse();


?>