enhance domain-importer, fixes #1512
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -24,7 +24,8 @@
|
|||||||
* @author Michael Kaufmann (d00p) <d00p@froxlor.org>
|
* @author Michael Kaufmann (d00p) <d00p@froxlor.org>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DomainBulkAction {
|
class DomainBulkAction
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* complete path including filename of file to be imported
|
* complete path including filename of file to be imported
|
||||||
@@ -74,19 +75,25 @@ class DomainBulkAction {
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_required_fields = array (
|
private $_required_fields = array (
|
||||||
'domain',
|
/* 1 */ 'domain',
|
||||||
'documentroot',
|
/* 2 */ 'documentroot',
|
||||||
'isbinddomain',
|
/* 3 */ 'aliasdomain',
|
||||||
'isemaildomain',
|
/* 4 */ 'isbinddomain',
|
||||||
'email_only',
|
/* 5 */ 'isemaildomain',
|
||||||
'iswildcarddomain',
|
/* 6 */ 'email_only',
|
||||||
'subcanemaildomain',
|
/* 7 */ 'iswildcarddomain',
|
||||||
'caneditdomain',
|
/* 8 */ 'subcanemaildomain',
|
||||||
'wwwserveralias',
|
/* 9 */ 'caneditdomain',
|
||||||
'specialsettings',
|
/* 10 */ 'zonefile',
|
||||||
'ssl_redirect',
|
/* 11 */ 'wwwserveralias',
|
||||||
'registration_date',
|
/* 12 */ 'openbasedir',
|
||||||
'ips',
|
/* 13 */ 'speciallogfile',
|
||||||
|
/* 14 */ 'specialsettings',
|
||||||
|
/* 15 */ 'ssl_redirect',
|
||||||
|
/* 16 */ 'use_ssl',
|
||||||
|
/* 17 */ 'registration_date',
|
||||||
|
/* 18 */ 'ips',
|
||||||
|
/* automatically added */
|
||||||
'adminid',
|
'adminid',
|
||||||
'customerid',
|
'customerid',
|
||||||
'add_date'
|
'add_date'
|
||||||
@@ -98,6 +105,7 @@ class DomainBulkAction {
|
|||||||
* @var PDOStatement
|
* @var PDOStatement
|
||||||
*/
|
*/
|
||||||
private $_ins_stmt = null;
|
private $_ins_stmt = null;
|
||||||
|
|
||||||
private $_ipp_ins_stmt = null;
|
private $_ipp_ins_stmt = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,13 +116,12 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return object DomainBulkAction instance
|
* @return object DomainBulkAction instance
|
||||||
*/
|
*/
|
||||||
public function __construct($import_file = null, $customer_id = 0) {
|
public function __construct($import_file = null, $customer_id = 0)
|
||||||
|
{
|
||||||
if (! empty($import_file)) {
|
if (! empty($import_file)) {
|
||||||
$this->_impFile = makeCorrectFile($import_file);
|
$this->_impFile = makeCorrectFile($import_file);
|
||||||
}
|
}
|
||||||
$this->_custId = $customer_id;
|
$this->_custId = $customer_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +133,8 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return array 'all' => amount of records processed, 'imported' => number of imported records
|
* @return array 'all' => amount of records processed, 'imported' => number of imported records
|
||||||
*/
|
*/
|
||||||
public function doImport($separator = ";", $offset = 0) {
|
public function doImport($separator = ";", $offset = 0)
|
||||||
|
{
|
||||||
|
|
||||||
// get the admins userinfo to check for domains_used, etc.
|
// get the admins userinfo to check for domains_used, etc.
|
||||||
global $userinfo;
|
global $userinfo;
|
||||||
@@ -178,13 +186,17 @@ class DomainBulkAction {
|
|||||||
`adminid` = :adminid,
|
`adminid` = :adminid,
|
||||||
`customerid` = :customerid,
|
`customerid` = :customerid,
|
||||||
`documentroot` = :documentroot,
|
`documentroot` = :documentroot,
|
||||||
|
`aliasdomain` = :aliasdomain,
|
||||||
`isbinddomain` = :isbinddomain,
|
`isbinddomain` = :isbinddomain,
|
||||||
`isemaildomain` = :isemaildomain,
|
`isemaildomain` = :isemaildomain,
|
||||||
`email_only` = :email_only,
|
`email_only` = :email_only,
|
||||||
`iswildcarddomain` = :iswildcarddomain,
|
`iswildcarddomain` = :iswildcarddomain,
|
||||||
`subcanemaildomain` = :subcanemaildomain,
|
`subcanemaildomain` = :subcanemaildomain,
|
||||||
`caneditdomain` = :caneditdomain,
|
`caneditdomain` = :caneditdomain,
|
||||||
|
`zonefile` = :zonefile,
|
||||||
`wwwserveralias` = :wwwserveralias,
|
`wwwserveralias` = :wwwserveralias,
|
||||||
|
`openbasedir` = :openbasedir,
|
||||||
|
`speciallogfile` = :speciallogfile,
|
||||||
`specialsettings` = :specialsettings,
|
`specialsettings` = :specialsettings,
|
||||||
`ssl_redirect` = :ssl_redirect,
|
`ssl_redirect` = :ssl_redirect,
|
||||||
`registration_date` = :registration_date,
|
`registration_date` = :registration_date,
|
||||||
@@ -222,7 +234,6 @@ class DomainBulkAction {
|
|||||||
'imported' => $import_counter,
|
'imported' => $import_counter,
|
||||||
'notice' => $note
|
'notice' => $note
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -232,10 +243,9 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setImportFile($import_file = null) {
|
public function setImportFile($import_file = null)
|
||||||
|
{
|
||||||
$this->_impFile = makeCorrectFile($import_file);
|
$this->_impFile = makeCorrectFile($import_file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,10 +255,9 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setCustomer($customer_id = 0) {
|
public function setCustomer($customer_id = 0)
|
||||||
|
{
|
||||||
$this->_custId = $customer_id;
|
$this->_custId = $customer_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,7 +267,8 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return int last-inserted id or false on error
|
* @return int last-inserted id or false on error
|
||||||
*/
|
*/
|
||||||
private function _addSingleDomainToDatabase($domain_data = array()) {
|
private function _addSingleDomainToDatabase($domain_data = array())
|
||||||
|
{
|
||||||
|
|
||||||
// format domain
|
// format domain
|
||||||
$idna_convert = new idna_convert_wrapper();
|
$idna_convert = new idna_convert_wrapper();
|
||||||
@@ -277,11 +287,54 @@ class DomainBulkAction {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no existing domains
|
// no existing domains can be imported
|
||||||
if (in_array($domain_data['domain'], $this->_knownDomains)) {
|
if (in_array($domain_data['domain'], $this->_knownDomains)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for alias-domain
|
||||||
|
if (! empty($domain_data['aliasdomain'])) {
|
||||||
|
// format
|
||||||
|
$domain_data['aliasdomain'] = $idna_convert->encode(preg_replace(array(
|
||||||
|
'/\:(\d)+$/',
|
||||||
|
'/^https?\:\/\//'
|
||||||
|
), '', $domain_data['aliasdomain']));
|
||||||
|
// validate alias-domain
|
||||||
|
if (! validateDomain($domain_data['aliasdomain'])) {
|
||||||
|
// invalid-domain lol - skip to be sure we dont add anything weird
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// does the domain we want to be an alias of exists?
|
||||||
|
if (! in_array($domain_data['aliasdomain'], $this->_knownDomains)) {
|
||||||
|
// it does not - User should respect the order of import so if the domain
|
||||||
|
// he wants to alias is also part of the import is ABOVE this one
|
||||||
|
// - we'd better skip
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for use_ssl and ssl_redirect
|
||||||
|
if (!isset($domain_data['use_ssl']) || $domain_data['use_ssl'] == 1) {
|
||||||
|
// if not set: default is whatever the system says
|
||||||
|
// if set to 1: set to 0 if system has no ssl enabled
|
||||||
|
$domain_data['use_ssl'] = (Settings::get('system.use_ssl') == 1 ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// use_ssl flag
|
||||||
|
if ($domain_data['use_ssl'] != 1) {
|
||||||
|
$domain_data['use_ssl'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ssl_redirect flag
|
||||||
|
if ($domain_data['ssl_redirect'] != 1) {
|
||||||
|
$domain_data['ssl_redirect'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if use_ssl is 0 ssl_redirect must be too (no ssl-ip => no ssl-redirect)
|
||||||
|
if ($domain_data['use_ssl'] == 0 && $domain_data['ssl_redirect'] == 1) {
|
||||||
|
$domain_data['ssl_redirect'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// add to known domains
|
// add to known domains
|
||||||
$this->_knownDomains[] = $domain_data['domain'];
|
$this->_knownDomains[] = $domain_data['domain'];
|
||||||
|
|
||||||
@@ -297,15 +350,40 @@ class DomainBulkAction {
|
|||||||
$domain_data['isbinddomain'] = 0;
|
$domain_data['isbinddomain'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// zonefile
|
||||||
|
if (!isset($domain_data['zonefile'])) {
|
||||||
|
$domain_data['zonefile'] = "";
|
||||||
|
} else {
|
||||||
|
if (!empty($domain_data['zonefile']) && Settings::Get('system.bind_enable') == '1') {
|
||||||
|
$domain_data['zonefile'] = makeCorrectFile($domain_data['zonefile']);
|
||||||
|
} else {
|
||||||
|
$domain_data['zonefile'] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// openbasedir flag
|
||||||
|
if (! isset($domain_data['openbasedir'])) {
|
||||||
|
$domain_data['openbasedir'] = 1;
|
||||||
|
} elseif ($domain_data['openbasedir'] != 1) {
|
||||||
|
$domain_data['openbasedir'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// speciallogfile flag
|
||||||
|
if (! isset($domain_data['speciallogfile'])) {
|
||||||
|
$domain_data['speciallogfile'] = 0;
|
||||||
|
} elseif ($domain_data['speciallogfile'] != 1) {
|
||||||
|
$domain_data['speciallogfile'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* automatically set values (not from the file)
|
* automatically set values (not from the file)
|
||||||
*/
|
*/
|
||||||
// add date
|
// add date
|
||||||
$domain_data['add_date'] = time();
|
$domain_data['add_date'] = time();
|
||||||
// set adminid
|
// set adminid
|
||||||
$domain_data['adminid'] = $this->_custData['adminid'];
|
$domain_data['adminid'] = (int)$this->_custData['adminid'];
|
||||||
// set customerid
|
// set customerid
|
||||||
$domain_data['customerid'] = $this->_custId;
|
$domain_data['customerid'] = (int)$this->_custId;
|
||||||
|
|
||||||
// check for required fields
|
// check for required fields
|
||||||
foreach ($this->_required_fields as $rfld) {
|
foreach ($this->_required_fields as $rfld) {
|
||||||
@@ -334,6 +412,11 @@ class DomainBulkAction {
|
|||||||
// dont need that for the domain-insert-statement
|
// dont need that for the domain-insert-statement
|
||||||
unset($domain_data['ips']);
|
unset($domain_data['ips']);
|
||||||
|
|
||||||
|
// remember use_ssl value
|
||||||
|
$use_ssl = (bool)$domain_data['use_ssl'];
|
||||||
|
// dont need that for the domain-insert-statement
|
||||||
|
unset($domain_data['use_ssl']);
|
||||||
|
|
||||||
// finally ADD the domain to panel_domains
|
// finally ADD the domain to panel_domains
|
||||||
Database::pexecute($this->_ins_stmt, $domain_data);
|
Database::pexecute($this->_ins_stmt, $domain_data);
|
||||||
|
|
||||||
@@ -351,6 +434,10 @@ class DomainBulkAction {
|
|||||||
// if we know the ip, at all variants (different ports, ssl and non-ssl) of it!
|
// if we know the ip, at all variants (different ports, ssl and non-ssl) of it!
|
||||||
if (isset($this->_knownIpPort[$ip])) {
|
if (isset($this->_knownIpPort[$ip])) {
|
||||||
foreach ($this->_knownIpPort[$ip] as $ipdata) {
|
foreach ($this->_knownIpPort[$ip] as $ipdata) {
|
||||||
|
// no ssl ip/ports should be used for this domain
|
||||||
|
if ($use_ssl == false && $ipdata['ssl'] == 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// add domain->ip reference
|
// add domain->ip reference
|
||||||
Database::pexecute($this->_ipp_ins_stmt, array(
|
Database::pexecute($this->_ipp_ins_stmt, array(
|
||||||
'domid' => $domain_id,
|
'domid' => $domain_id,
|
||||||
@@ -361,7 +448,6 @@ class DomainBulkAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $domain_id;
|
return $domain_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -372,8 +458,8 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function _parseImportFile($separator = ";") {
|
private function _parseImportFile($separator = ";")
|
||||||
|
{
|
||||||
if (empty($this->_impFile)) {
|
if (empty($this->_impFile)) {
|
||||||
throw new Exception("No file was given for import");
|
throw new Exception("No file was given for import");
|
||||||
}
|
}
|
||||||
@@ -394,8 +480,8 @@ class DomainBulkAction {
|
|||||||
$tmp_arr = explode($separator, $line);
|
$tmp_arr = explode($separator, $line);
|
||||||
$data_arr = array();
|
$data_arr = array();
|
||||||
foreach ($tmp_arr as $idx => $data) {
|
foreach ($tmp_arr as $idx => $data) {
|
||||||
// dont include more fields that the 13 we use
|
// dont include more fields that the ones we use
|
||||||
if ($idx > 12)
|
if ($idx > (count($this->_required_fields) - 4)) // off-by-one + 3 auto-values
|
||||||
break;
|
break;
|
||||||
$data_arr[$this->_required_fields[$idx]] = $data;
|
$data_arr[$this->_required_fields[$idx]] = $data;
|
||||||
}
|
}
|
||||||
@@ -407,7 +493,6 @@ class DomainBulkAction {
|
|||||||
fclose($fh);
|
fclose($fh);
|
||||||
|
|
||||||
return $file_data;
|
return $file_data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -415,8 +500,8 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function _readCustomerData() {
|
private function _readCustomerData()
|
||||||
|
{
|
||||||
$cust_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :cid");
|
$cust_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :cid");
|
||||||
$this->_custData = Database::pexecute_first($cust_stmt, array(
|
$this->_custData = Database::pexecute_first($cust_stmt, array(
|
||||||
'cid' => $this->_custId
|
'cid' => $this->_custId
|
||||||
@@ -426,7 +511,6 @@ class DomainBulkAction {
|
|||||||
}
|
}
|
||||||
$this->_custData = null;
|
$this->_custData = null;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,15 +518,14 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function _readDomainData() {
|
private function _readDomainData()
|
||||||
|
{
|
||||||
$knowndom_stmt = Database::prepare("SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` ORDER BY `domain` ASC");
|
$knowndom_stmt = Database::prepare("SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "` ORDER BY `domain` ASC");
|
||||||
Database::pexecute($knowndom_stmt);
|
Database::pexecute($knowndom_stmt);
|
||||||
$this->_knownDomains = array();
|
$this->_knownDomains = array();
|
||||||
while ($dom = $knowndom_stmt->fetch()) {
|
while ($dom = $knowndom_stmt->fetch()) {
|
||||||
$this->_knownDomains[] = $dom['domain'];
|
$this->_knownDomains[] = $dom['domain'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -450,8 +533,8 @@ class DomainBulkAction {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function _readIpPortData() {
|
private function _readIpPortData()
|
||||||
|
{
|
||||||
$knownip_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "`");
|
$knownip_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "`");
|
||||||
Database::pexecute($knownip_stmt);
|
Database::pexecute($knownip_stmt);
|
||||||
$this->_knownIpPort = array();
|
$this->_knownIpPort = array();
|
||||||
@@ -459,7 +542,5 @@ class DomainBulkAction {
|
|||||||
$this->_knownIpPort[$ipp['ip']][] = $ipp;
|
$this->_knownIpPort[$ipp['ip']][] = $ipp;
|
||||||
$this->_knownIpPortChk[] = $ipp['ip'];
|
$this->_knownIpPortChk[] = $ipp['ip'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user