Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Hosting Package
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 29 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -52,14 +52,21 @@ class _Hosting extends \IPS\nexus\Package
|
||||
*/
|
||||
public function getPurchaseNameInfo( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
try
|
||||
$stickyCustomFields = array_filter( parent::getPurchaseNameInfo( $purchase ) );
|
||||
|
||||
if ( !count( $stickyCustomFields ) )
|
||||
{
|
||||
return array_merge( array( \IPS\nexus\Hosting\Account::load( $purchase->id )->domain ), parent::getPurchaseNameInfo( $purchase ) );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return parent::getPurchaseNameInfo( $purchase );
|
||||
try
|
||||
{
|
||||
return array( \IPS\nexus\Hosting\Account::load( $purchase->id )->domain );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return parent::getPurchaseNameInfo( $purchase );
|
||||
}
|
||||
}
|
||||
|
||||
return $stickyCustomFields;
|
||||
}
|
||||
|
||||
/* !ACP Package Form */
|
||||
@@ -144,83 +151,59 @@ class _Hosting extends \IPS\nexus\Package
|
||||
/**
|
||||
* Update existing purchases
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param array $changes The old values
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param array $changes The old values
|
||||
* @param bool $cancelBillingAgreementIfNecessary If making changes to renewal terms, TRUE will cancel associated billing agreements. FALSE will skip that change
|
||||
* @return void
|
||||
*/
|
||||
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes )
|
||||
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes, $cancelBillingAgreementIfNecessary=FALSE )
|
||||
{
|
||||
/* Get current values */
|
||||
try
|
||||
{
|
||||
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
|
||||
|
||||
$current = array(
|
||||
'account_username' => $account->username,
|
||||
'account_domain' => $account->domain,
|
||||
'account_password' => (string) $account->password,
|
||||
'p_quota' => $account->diskspaceAllowance() !== NULL ? $account->diskspaceAllowance() / 1000000 : -1,
|
||||
'p_maxftp' => $account->maxFtpAccounts() !== NULL ? $account->maxFtpAccounts() : -1,
|
||||
'p_maxsql' => $account->maxDatabases() !== NULL ? $account->maxDatabases() : -1,
|
||||
'p_maxpop' => $account->maxEmailAccounts() !== NULL ? $account->maxEmailAccounts() : -1,
|
||||
'p_maxlst' => $account->maxMailingLists() !== NULL ? $account->maxMailingLists() : -1,
|
||||
'p_maxsub' => $account->maxSubdomains() !== NULL ? $account->maxSubdomains() : -1,
|
||||
'p_maxpark' => $account->maxParkedDomains() !== NULL ? $account->maxParkedDomains() : -1,
|
||||
'p_maxaddon' => $account->maxAddonDomains() !== NULL ? $account->maxAddonDomains() : -1,
|
||||
'p_hasshell' => $account->hasSSHAccess(),
|
||||
'p_bwlimit' => $account->monthlyBandwidthAllowance() !== NULL ? $account->monthlyBandwidthAllowance() / 1000000 : -1,
|
||||
);
|
||||
|
||||
$update = array();
|
||||
foreach ( array( 'quota' => 'diskspaceAllowance', 'bwlimit' => 'monthlyBandwidthAllowance', 'maxftp' => 'maxFtpAccounts', 'maxsql' => 'maxDatabases', 'maxpop' => 'maxEmailAccounts', 'maxlst' => 'maxMailingLists', 'maxsub' => 'maxSubdomains', 'maxpark' => 'maxParkedDomains', 'maxaddon' => 'maxAddonDomains', 'hasshell' => 'hasSSHAccess' ) as $k => $method )
|
||||
{
|
||||
if ( isset( $changes[ $k ] ) )
|
||||
{
|
||||
/* What is the current value? */
|
||||
$currentValue = call_user_func( array( $account, $method ) );
|
||||
if ( $currentValue === NULL )
|
||||
{
|
||||
$currentValue = -1;
|
||||
}
|
||||
elseif ( $k == 'quota' or $k == 'bwlimit' )
|
||||
{
|
||||
$currentValue = $currentValue / 1048576 / 1.024;
|
||||
}
|
||||
|
||||
/* If the current value matches the old value (i.e. it hasn't been manually modified), set it to the new value */
|
||||
if ( $currentValue == $changes[ $k ] )
|
||||
{
|
||||
$update[ 'p_' . $k ] = $this->$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty( $update ) )
|
||||
{
|
||||
$account->edit( $update );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
$e->log();
|
||||
return parent::updatePurchase( $purchase, $changes );
|
||||
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return parent::updatePurchase( $purchase, $changes );
|
||||
}
|
||||
|
||||
/* Set new values */
|
||||
$update = array();
|
||||
foreach ( array(
|
||||
'quota',
|
||||
'bwlimit',
|
||||
'hasshell',
|
||||
'maxftp',
|
||||
'maxsql',
|
||||
'maxpop',
|
||||
'maxlst',
|
||||
'maxsub',
|
||||
'maxpark',
|
||||
'maxaddon',
|
||||
) as $k )
|
||||
{
|
||||
if ( array_key_exists( $k, $changes ) )
|
||||
{
|
||||
if ( $current["p_{$k}"] == $changes[ $k ] )
|
||||
{
|
||||
$update["p_{$k}"] = $this->$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Send API call */
|
||||
if ( !empty( $update ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$account->edit( array_merge( $current, $update ) );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
$e->log();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
|
||||
}
|
||||
|
||||
/* Call parent */
|
||||
return parent::updatePurchase( $purchase, $changes );
|
||||
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
|
||||
}
|
||||
|
||||
/* !Store */
|
||||
@@ -239,7 +222,6 @@ class _Hosting extends \IPS\nexus\Package
|
||||
{
|
||||
$queue = \IPS\nexus\Hosting\Queue::load( $this->queue );
|
||||
$server = $queue->activeServer();
|
||||
$form->hiddenValues['server'] = $server->id;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -250,6 +232,23 @@ class _Hosting extends \IPS\nexus\Package
|
||||
\IPS\Output::i()->error( 'hosting_err_public', '4X245/3', 500, 'hosting_err_no_server' );
|
||||
}
|
||||
|
||||
/* Add the options to the form */
|
||||
$this->_domainForm( $form, $memberCurrency, $server, $this->maxpark === -1 or $this->maxpark > 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param string $memberCurrency The currency being used
|
||||
* @param \IPS\nexus\Hosting\Server $server The server the account will be used on
|
||||
* @param bool $canParkDomains If the account can park domains (which controls if CNAME is an option)
|
||||
* @return
|
||||
*/
|
||||
protected function _domainForm( \IPS\Helpers\Form $form, $memberCurrency, \IPS\nexus\Hosting\Server $server, $canParkDomains )
|
||||
{
|
||||
$form->hiddenValues['server'] = $server->id;
|
||||
|
||||
/* What options are available? */
|
||||
$domainTypeOptions = array();
|
||||
$domainTypeToggles = array();
|
||||
@@ -266,14 +265,26 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
if ( \IPS\Settings::i()->nexus_hosting_allow_own_domain )
|
||||
{
|
||||
$domainTypeOptions['own'] = 'ha_domain_own';
|
||||
$domainTypeToggles['own'] = array( 'ha_domain_to_use' );
|
||||
$ownDomainOptions = explode( ',', \IPS\Settings::i()->nexus_hosting_own_domains );
|
||||
if ( in_array( 'nameservers', $ownDomainOptions ) or in_array( 'aname', $ownDomainOptions ) or ( in_array( 'cname', $ownDomainOptions ) and $canParkDomains ) )
|
||||
{
|
||||
$domainTypeOptions['own'] = 'ha_domain_own';
|
||||
$domainTypeToggles['own'] = array( 'ha_domain_to_use' );
|
||||
}
|
||||
}
|
||||
if ( !count( $domainTypeOptions ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'hosting_err_public', '4X245/4', 500, 'hosting_err_no_domains' );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'ha_domain_type', NULL, TRUE, array( 'options' => $domainTypeOptions, 'toggles' => $domainTypeToggles ) ) );
|
||||
if ( count( $domainTypeOptions ) > 1 )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'ha_domain_type', NULL, TRUE, array( 'options' => $domainTypeOptions, 'toggles' => $domainTypeToggles ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$_domainTypeOptions = array_keys( $domainTypeOptions );
|
||||
$form->hiddenValues['ha_domain_type'] = array_pop( $_domainTypeOptions );
|
||||
}
|
||||
|
||||
/* Buy Domain */
|
||||
if ( array_key_exists( 'buy', $domainTypeOptions ) )
|
||||
@@ -316,7 +327,7 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'ha_subdomain_to_use', NULL, NULL, array(
|
||||
'getHtml' => function( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('store')->domainSub( $field );
|
||||
return \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->domainSub( $field );
|
||||
},
|
||||
'validate' => function( $field )
|
||||
{
|
||||
@@ -328,10 +339,24 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Subdomain cannot contain any dots */
|
||||
if ( mb_strpos( $field->value['subdomain'], '.' ) !== FALSE )
|
||||
{
|
||||
throw new \DomainException('subdomain_cannot_contain_dot');
|
||||
}
|
||||
|
||||
/* Subdomain cannot contain any spaces */
|
||||
if ( mb_strpos( $field->value['subdomain'], ' ' ) !== FALSE )
|
||||
{
|
||||
throw new \DomainException('subdomain_cannot_contain_space');
|
||||
}
|
||||
|
||||
/* Subdomain cannot contain any of these characters: ~!$&'()*+,;= */
|
||||
if ( (bool) preg_match( '/([~!\$&\'\"\(\)\*\+,;=]+)/', $field->value['subdomain'] ) )
|
||||
{
|
||||
throw new \DomainException('subdomain_invalid_characters');
|
||||
}
|
||||
|
||||
return static::_validateDomain( $field->value['subdomain'] . '.' . $field->value['domain'] );
|
||||
}
|
||||
}
|
||||
@@ -352,15 +377,134 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
else
|
||||
{
|
||||
return static::_validateDomain( $value );
|
||||
static::_validateDomain( $value );
|
||||
|
||||
try
|
||||
{
|
||||
$domain = new \IPS\nexus\DomainLookup( $value, FALSE );
|
||||
|
||||
$options = explode( ',', \IPS\Settings::i()->nexus_hosting_own_domains );
|
||||
if ( $domain->type === \IPS\nexus\DomainLookup::DOMAIN_TYPE_DOMAIN )
|
||||
{
|
||||
if ( !in_array( 'nameservers', $options ) )
|
||||
{
|
||||
throw new \DomainException('domain_must_be_subdomain');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !in_array( 'aname', $options ) and ( !in_array( 'cname', $options ) or !$this->maxpark ) )
|
||||
{
|
||||
throw new \DomainException('domain_cannot_be_subdomain');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
throw new \DomainException('domain_not_valid');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, 'http://', NULL, 'ha_domain_to_use' ) );
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['ha_domain_to_use_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'ha_domain_to_use_ns', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $server->nameservers() ) ) ) );
|
||||
}, 'http://', NULL, 'ha_domain_to_use' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional Secondary Page to show on checkout
|
||||
*
|
||||
* @param array $values Values from store form
|
||||
* @param string|NULL $cnameTarget If a there is known target for a CNAME, otherwise NULL to assign a domain
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function storeAdditionalPage( array $values, $cname=NULL )
|
||||
{
|
||||
if ( $values['ha_domain_type'] === 'own' )
|
||||
{
|
||||
$domain = new \IPS\nexus\DomainLookup( $values['ha_domain_to_use'] );
|
||||
$options = explode( ',', \IPS\Settings::i()->nexus_hosting_own_domains );
|
||||
|
||||
if ( $domain->type === \IPS\nexus\DomainLookup::DOMAIN_TYPE_DOMAIN )
|
||||
{
|
||||
if ( !in_array( 'nameservers', $options ) )
|
||||
{
|
||||
throw new \DomainException('domain_must_be_subdomain');
|
||||
}
|
||||
|
||||
$nameservers = explode( ',', mb_strtolower( \IPS\Settings::i()->nexus_hosting_nameservers ) );
|
||||
$isValid = FALSE;
|
||||
|
||||
foreach ( $domain->whois as $whoisData )
|
||||
{
|
||||
$whoisData = mb_strtolower( $whoisData );
|
||||
foreach( $nameservers as $nameserver )
|
||||
{
|
||||
if ( mb_strpos( $whoisData, $nameserver ) !== FALSE )
|
||||
{
|
||||
$isValid = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$isValid )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'hosting', 'nexus', 'front' )->ownDomainName( $values, $nameservers );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$aname = NULL;
|
||||
if ( in_array( 'aname', $options ) )
|
||||
{
|
||||
$aname = \IPS\nexus\Hosting\Server::load( $values['server'] )->ip;
|
||||
}
|
||||
|
||||
if ( in_array( 'cname', $options ) and $this->maxpark )
|
||||
{
|
||||
if ( !$cname )
|
||||
{
|
||||
$cname = isset( $values['cname'] ) ? $values['cname'] : str_replace( '.', '', mb_strpos( $domain->sld, '.' ) ? mb_substr( $domain->sld, mb_strpos( $domain->sld, '.' ) ) : $domain->sld );
|
||||
|
||||
while ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_hosting_accounts', array( 'account_domain=? AND account_exists=1', $cname . '.' . \IPS\Settings::i()->nexus_hosting_own_domain_sub ) )->first() )
|
||||
{
|
||||
$cname .= rand( 0, 9 );
|
||||
}
|
||||
|
||||
$values['cname'] = $cname;
|
||||
$cname .= '.' . \IPS\Settings::i()->nexus_hosting_own_domain_sub;
|
||||
}
|
||||
}
|
||||
|
||||
$isValid = FALSE;
|
||||
$records = @dns_get_record( $values['ha_domain_to_use'], 0 + ( $aname ? DNS_A : 0 ) + ( $cname ? DNS_CNAME : 0 ) );
|
||||
if ( is_array( $records ) )
|
||||
{
|
||||
foreach ( $records as $record )
|
||||
{
|
||||
if ( $aname and $record['type'] === 'A' and $record['ip'] === $aname )
|
||||
{
|
||||
$isValid = TRUE;
|
||||
break;
|
||||
}
|
||||
if ( $cname and $record['type'] === 'CNAME' and $record['target'] === $cname )
|
||||
{
|
||||
$isValid = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$isValid )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'hosting', 'nexus', 'front' )->ownDomainName( $values, NULL, $cname, $aname );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add To Cart
|
||||
*
|
||||
@@ -381,7 +525,7 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '3X245/5', 403, '' );
|
||||
\IPS\Output::i()->error( 'generic_error', '3X245/5', 403, 'hosting_no_server' );
|
||||
}
|
||||
$item->extra['server'] = $server->id;
|
||||
|
||||
@@ -414,7 +558,15 @@ class _Hosting extends \IPS\nexus\Package
|
||||
return array();
|
||||
|
||||
case 'own':
|
||||
$item->extra['domain'] = $values['ha_domain_to_use'];
|
||||
if ( isset( \IPS\Request::i()->cname ) )
|
||||
{
|
||||
$item->extra['domain'] = \IPS\Request::i()->cname . '.' . \IPS\Settings::i()->nexus_hosting_own_domain_sub;
|
||||
$item->extra['parkDomain'] = $values['ha_domain_to_use'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$item->extra['domain'] = $values['ha_domain_to_use'];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -430,7 +582,7 @@ class _Hosting extends \IPS\nexus\Package
|
||||
{
|
||||
$domain = mb_strtolower( $domain );
|
||||
$data = @parse_url( 'http://' . $domain );
|
||||
if ( $data === FALSE or $data['host'] != $domain or !preg_match( '/^[a-z][a-z0-9-]*\.[a-z0-9-\.]+$/', $domain ) )
|
||||
if ( $data === FALSE or $data['host'] != $domain or !\IPS\Http\Url::validateComponent( \IPS\Http\Url::COMPONENT_HOST, $domain ) )
|
||||
{
|
||||
throw new \DomainException('domain_not_valid');
|
||||
}
|
||||
@@ -466,7 +618,7 @@ class _Hosting extends \IPS\nexus\Package
|
||||
return $class::_validateDomain( $value );
|
||||
}
|
||||
}, 'http://', NULL, 'ha_domain_to_use' );
|
||||
$field->label = 'ha_domain_to_use';
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'ha_domain_to_use' );
|
||||
$form->add( $field );
|
||||
}
|
||||
|
||||
@@ -486,8 +638,8 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$item->extra['server'] = \IPS\nexus\Hosting\Queue::load( $this->queue )->activeServer()->id;
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '3X245/6', 403, '' );
|
||||
{
|
||||
\IPS\Output::i()->error( 'hosting_no_server', '3X245/6', 403, '' );
|
||||
}
|
||||
$item->extra['domain'] = $values[ 'ha_domain_to_use' . $k ];
|
||||
}
|
||||
@@ -527,6 +679,8 @@ class _Hosting extends \IPS\nexus\Package
|
||||
*/
|
||||
public function acpEdit( \IPS\nexus\Purchase $purchase, \IPS\Helpers\Form $form, $renewals )
|
||||
{
|
||||
parent::acpEdit( $purchase, $form, $renewals );
|
||||
|
||||
try
|
||||
{
|
||||
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
|
||||
@@ -540,15 +694,15 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'account_username', $account->username, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'account_password', $account->password, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'account_domain', $account->domain, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_quota', ( $account->diskspaceAllowance() !== NULL ? $account->diskspaceAllowance() / 1000000 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, 'MB' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_bwlimit', ( $account->monthlyBandwidthAllowance() !== NULL ? $account->monthlyBandwidthAllowance() / 1000000 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, \IPS\Member::loggedIn()->language()->get('mb_per_month') ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxftp', ( $account->maxFtpAccounts() !== NULL ? $account->maxFtpAccounts() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsql', ( $account->maxDatabases() !== NULL ? $account->maxDatabases() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpop', ( $account->maxEmailAccounts() !== NULL ? $account->maxEmailAccounts() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxlst', ( $account->maxMailingLists() !== NULL ? $account->maxMailingLists() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsub', ( $account->maxSubdomains() !== NULL ? $account->maxSubdomains() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpark', ( $account->maxParkedDomains() !== NULL ? $account->maxParkedDomains() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxaddon', ( $account->maxAddonDomains() !== NULL ? $account->maxAddonDomains() : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_quota', ( $account->diskspaceAllowance() !== NULL ? intval( $account->diskspaceAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, 'MB' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_bwlimit', ( $account->monthlyBandwidthAllowance() !== NULL ? intval( $account->monthlyBandwidthAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, \IPS\Member::loggedIn()->language()->get('mb_per_month') ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxftp', ( $account->maxFtpAccounts() !== NULL ? intval( $account->maxFtpAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsql', ( $account->maxDatabases() !== NULL ? intval( $account->maxDatabases() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpop', ( $account->maxEmailAccounts() !== NULL ? intval( $account->maxEmailAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxlst', ( $account->maxMailingLists() !== NULL ? intval( $account->maxMailingLists() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsub', ( $account->maxSubdomains() !== NULL ? intval( $account->maxSubdomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpark', ( $account->maxParkedDomains() !== NULL ? intval( $account->maxParkedDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'p_maxaddon', ( $account->maxAddonDomains() !== NULL ? intval( $account->maxAddonDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'p_hasshell', $account->hasSSHAccess(), FALSE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'do_not_update_server', FALSE, FALSE, array(
|
||||
'rowHtml' => function()
|
||||
@@ -577,36 +731,39 @@ class _Hosting extends \IPS\nexus\Package
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Update server if necessary */
|
||||
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
|
||||
if ( $values['account_server']->id != $account->server->id )
|
||||
if ( $account->exists )
|
||||
{
|
||||
$account->server = $values['account_server'];
|
||||
/* Update server if necessary */
|
||||
if ( $values['account_server']->id != $account->server->id )
|
||||
{
|
||||
$account->server = $values['account_server'];
|
||||
$account->save();
|
||||
}
|
||||
|
||||
/* Send API calls */
|
||||
if ( !$values['do_not_update_server'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$account->edit( $values );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X245/1', 503, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Update local database */
|
||||
$account->username = $values['account_username'];
|
||||
$account->password = $values['account_password'];
|
||||
$account->domain = $values['account_domain'];
|
||||
$account->save();
|
||||
}
|
||||
|
||||
/* Send API calls */
|
||||
if ( $account->exists and !$values['do_not_update_server'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$account->edit( $values );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( '', '3X245/1', 503, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Update local database */
|
||||
$account->username = $values['account_username'];
|
||||
$account->password = $values['account_password'];
|
||||
$account->domain = $values['account_domain'];
|
||||
$account->save();
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
|
||||
parent::save( $purchase, $values );
|
||||
parent::acpEditSave( $purchase, $values );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,7 +833,7 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
|
||||
$item = new \IPS\nexus\extensions\nexus\Item\Bandwidth(
|
||||
sprintf( $purchase->member->language()->get('bandwidth_purchase_name'), \IPS\Output\Plugin\Filesize::humanReadableFilesize( $values['bandwidth_to_buy'] * 1000000, TRUE ) ),
|
||||
sprintf( $purchase->member->language()->get('bandwidth_purchase_name'), \IPS\Output\Plugin\Filesize::humanReadableFilesize( $values['bandwidth_to_buy'] * 1000000, TRUE, FALSE, TRUE ) ),
|
||||
new \IPS\nexus\Money( $bandwidthOptions[ $values['bandwidth_to_buy'] ][ $currency ]['amount'], $currency )
|
||||
);
|
||||
$item->parent = $purchase;
|
||||
@@ -703,6 +860,25 @@ class _Hosting extends \IPS\nexus\Package
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ACP Support View HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function acpSupportView( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
try
|
||||
{
|
||||
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate('purchases')->hostingSupport( $purchase, $account );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/* !Client Area */
|
||||
|
||||
/**
|
||||
@@ -819,6 +995,80 @@ class _Hosting extends \IPS\nexus\Package
|
||||
|
||||
return $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
|
||||
|
||||
case 'changedomain':
|
||||
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
|
||||
$form = new \IPS\Helpers\Form( 'change_domain', 'change_domain' );
|
||||
$currency = $purchase->renewals ? $purchase->renewals->cost->currency : $purchase->defaultCurrency();
|
||||
try
|
||||
{
|
||||
$activeDomainPurchase = \IPS\nexus\Purchase::constructFromData( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_parent=? AND ps_app=? AND ps_type=? AND ps_active=1', $purchase->id, 'nexus', 'domain' ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$activeDomainPurchase = NULL;
|
||||
}
|
||||
$this->_domainForm( $form, $currency, $account->server, $account->maxParkedDomains() === NULL or $this->maxpark === -1 or $this->maxpark > $account->maxParkedDomains() );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $additionalPage = $this->storeAdditionalPage( $_POST, $account->domain ) )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'purchases', 'nexus', 'front' )->hostingChangeDomain( $purchase, $additionalPage, $activeDomainPurchase );
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( $values['ha_domain_type'] )
|
||||
{
|
||||
case 'buy':
|
||||
$domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE );
|
||||
$cost = new \IPS\nexus\Money( $domainPrices[ $values['ha_domain_to_buy']['tld'] ][ $currency ]['amount'], $currency );
|
||||
|
||||
$tax = NULL;
|
||||
if ( \IPS\Settings::i()->nexus_domain_tax )
|
||||
{
|
||||
try
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( \IPS\Settings::i()->nexus_domain_tax );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
$domain = new \IPS\nexus\extensions\nexus\Item\Domain( $values['ha_domain_to_buy']['sld'] . '.' . $values['ha_domain_to_buy']['tld'], $cost );
|
||||
$domain->renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( $cost, new \DateInterval('P1Y'), $tax );
|
||||
$domain->paymentMethodIds = $item->paymentMethodIds;
|
||||
$domain->tax = $tax;
|
||||
$domain->extra = array_merge( $values['ha_domain_to_buy'], array( 'nameservers' => $server->nameservers(), 'registerTo' => $purchase->id ) );
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->currency = $currency;
|
||||
$invoice->member = \IPS\Member::loggedIn();
|
||||
$invoice->addItem( $domain );
|
||||
$invoice->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
|
||||
|
||||
case 'sub':
|
||||
$account->domain = $values['ha_subdomain_to_use']['subdomain'] . '.' . $values['ha_subdomain_to_use']['domain'];
|
||||
$account->save();
|
||||
$account->changeDomain( $account->domain );
|
||||
return array();
|
||||
|
||||
case 'own':
|
||||
if ( isset( \IPS\Request::i()->cname ) )
|
||||
{
|
||||
$account->changeDomain( $values['ha_domain_to_use'], TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
$account->domain = $values['ha_domain_to_use'];
|
||||
$account->save();
|
||||
$account->changeDomain( $account->domain );
|
||||
}
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
return \IPS\Theme::i()->getTemplate( 'purchases', 'nexus', 'front' )->hostingChangeDomain( $purchase, $form, $activeDomainPurchase );
|
||||
|
||||
default:
|
||||
return parent::clientAreaAction( $purchase );
|
||||
}
|
||||
@@ -887,6 +1137,12 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$account->username = $username;
|
||||
$account->create( $this, $invoice->member );
|
||||
$account->save();
|
||||
|
||||
/* Park a domain if necessary */
|
||||
if ( isset( $purchase->extra['parkDomain'] ) )
|
||||
{
|
||||
$account->parkDomain( $purchase->extra['parkDomain'] );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
@@ -969,6 +1225,31 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$e->log();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning to display to admin when cancelling a purchase
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public function onCancelWarning( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
if ( \IPS\Settings::i()->nexus_hosting_terminate )
|
||||
{
|
||||
if ( \IPS\Settings::i()->nexus_hosting_terminate == -1 )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'hosting_cancel_warning_nt' );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'hosting_cancel_warning', FALSE, array( 'pluralize' => array( \IPS\Settings::i()->nexus_hosting_terminate ) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'hosting_cancel_warning_at' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Deleted
|
||||
@@ -1010,13 +1291,24 @@ class _Hosting extends \IPS\nexus\Package
|
||||
$update = array();
|
||||
foreach ( array( 'quota' => 'diskspaceAllowance', 'bwlimit' => 'monthlyBandwidthAllowance', 'maxftp' => 'maxFtpAccounts', 'maxsql' => 'maxDatabases', 'maxpop' => 'maxEmailAccounts', 'maxlst' => 'maxMailingLists', 'maxsub' => 'maxSubdomains', 'maxpark' => 'maxParkedDomains', 'maxaddon' => 'maxAddonDomains', 'hasshell' => 'hasSSHAccess' ) as $k => $method )
|
||||
{
|
||||
$val = call_user_func( array( $account, $method ) );
|
||||
if ( ( $val === NULL and $this->$k == -1 ) or $val == $this->$k )
|
||||
/* What is the current value? */
|
||||
$currentValue = call_user_func( array( $account, $method ) );
|
||||
if ( $currentValue === NULL )
|
||||
{
|
||||
$update[ $k ] = $newPackage->$k;
|
||||
$currentValue = -1;
|
||||
}
|
||||
elseif ( $k == 'quota' or $k == 'bwlimit' )
|
||||
{
|
||||
$currentValue = $currentValue / 1048576 / 1.024;
|
||||
}
|
||||
|
||||
/* If the current value matches the old package (i.e. it hasn't been manually modified), set it to the new package */
|
||||
if ( $currentValue == $this->$k )
|
||||
{
|
||||
$update[ 'p_' . $k ] = $newPackage->$k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !empty( $update ) )
|
||||
{
|
||||
$account->edit( $update );
|
||||
|
||||
Reference in new issue
Block a user