IP.Board Tutorials

Getting started nulling Invision Power Suite retail

Submitted by guntherbb, , Thread ID: 3674

Thread Closed
11-05-2015, 04:07 AM
This post was last modified: 11-05-2015, 04:22 AM by guntherbb
#1
As the title says, this is to get people started and not a full blown null. This information is used for a fresh install and has not been tested on an upgrade.

First of all, if you have memory issues when you go to install, and it won't continue, you can get around this. The required memory is 128M, which is set in your php.ini file on your host. If they limit you to say 64M, you can add this line to your init.php file.

ini_set('memory_limit','128M');

You want to add this right after the

namespace IPS;

which is at the top of the init.php file. So it would look like this


<?php
/**
* @brief Initiates IPS Social Suite constants, autoloader and exception handler
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright © 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 18 Feb 2013
* @version SVN_VERSION_NUMBER
*/

namespace IPS;
ini_set('memory_limit','128M');

/**



Now we will handle the license issues for the install. Please note that this does not remove the license but will allow you to install and test the board. Open the file license.php found at /applicatioins/core/modules/setup/install/license.php and look for the following section.


public function manage()

{

$form = new \IPS\Helpers\Form( 'license', 'continue', \IPS\Http\Url::external( ( ( isset( $_SERVER['HTTPS'] ) AND $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?controller=license' ) );

$form->add( new \IPS\Helpers\Form\Text( 'lkey', NULL, TRUE, array( 'size' => 50 ), function( $val )

{

\IPS\IPS::checkLicenseKey( $val, ( ( isset( $_SERVER['HTTPS'] ) AND $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . mb_substr( $_SERVER['SCRIPT_NAME'], 0, -mb_strlen( \IPS\CP_DIRECTORY . '/install/index.php' ) ) );

}, NULL, '<a href="' . \IPS\Http\Url::ips( 'docs/find_lkey' ) . '" target="_blank">' . \IPS\Member::loggedIn()->language()->addToStack('lkey_help') . '</a>' ) );

$form->add( new \IPS\Helpers\Form\Checkbox( 'eula', FALSE, TRUE, array( 'label' => 'eula_suffix' ), function( $val )

{

if ( !$val )

{

throw new \InvalidArgumentException('eula_err');

}

}, "<textarea disabled style='width: 100%; height: 250px'>" . file_get_contents( 'eula.txt' ) . "</textarea><br>" ) );


For the 'size'=>50 above, change the 50 to a 1, and then you can enter a letter, number, I think even a space and that is enough to satisfy the license requirements for right now to continue the install. As for the other area highlighted red, you can remove all that. I believe removing the eula check will prevent an error being thrown if you don't check the box, so when installing, just throw a number in the license and hit continue and it should be good to go.

Next we will deal with the big red box that would show up for a missing or invalid license, that will show up in the admin area. To prevent/disable this, we will edit the theme.xml file located at /applications/core/data/theme.xml. Open this file and search for a section that looks like this, it can be easily found by searching for the word "license":



<template template_group="global" template_name="lkeyWarning" template_data="" template_location="global" template_app="core"><![CDATA[

{{if $lkeyWarning = \IPS\Output::i()->licenseKeyWarning()}}

{{if $lkeyWarning == 'none'}}

<div class="ipsMessage ipsMessage_error" id='elLicenseKey'>

{lang="license_error_none"}

</div>

{{elseif $lkeyWarning == 'expired' && !isset( \IPS\Request::i()->cookie['licenseDismiss'] )}}

<div class="ipsMessage ipsMessage_general" id='elLicenseKey' data-controller='core.global.core.license'>

{lang="license_error_expired"}

<ul class='ipsList_inline'>

<li>

<a href='{url="renew_my_license" ips="true"}' class='ipsButton ipsButton_verySmall ipsButton_veryLight'>{lang="license_renew_now"}</a>

</li>

<li>

<a href='{url="app=core&module=settings&controller=licensekey&do=refresh" base="admin"}' class='ipsButton ipsButton_verySmall ipsButton_veryLight'>{lang="license_check_again"}</a>

</li>

</ul>

<a href='#' data-role='closeMessage' data-ipsTooltip title='{lang="license_dismiss"}'>&times;</a>

</div>

{{endif}}

{{endif}}]]></template>

The first set of <div></div> tags to remove are these, which are for a missing license:



<div class="ipsMessage ipsMessage_error" id='elLicenseKey'>
{lang="license_error_none"}
</div>


And the 2nd set are these ones, which are for an expired license:



<div class="ipsMessage ipsMessage_general" id='elLicenseKey' data-controller='core.global.core.license'>

{lang="license_error_expired"}

<ul class='ipsList_inline'>

<li>

<a href='{url="renew_my_license" ips="true"}' class='ipsButton ipsButton_verySmall ipsButton_veryLight'>{lang="license_renew_now"}</a>

</li>

<li>

<a href='{url="app=core&module=settings&controller=licensekey&do=refresh" base="admin"}' class='ipsButton ipsButton_verySmall ipsButton_veryLight'>{lang="license_check_again"}</a>

</li>

</ul>

<a href='#' data-role='closeMessage' data-ipsTooltip title='{lang="license_dismiss"}'>&times;</a>

</div>

So after we remove these, this section will shrink quite a bit and look like this:



<template template_group="global" template_name="lkeyWarning" template_data="" template_location="global" template_app="core"><![CDATA[

{{if $lkeyWarning = \IPS\Output::i()->licenseKeyWarning()}}

{{if $lkeyWarning == 'none'}}

{{elseif $lkeyWarning == 'expired' && !isset( \IPS\Request::i()->cookie['licenseDismiss'] )}}

{{endif}}

{{endif}}]]></template>



Now the last thing we need to take care of for now is the md5 checks that were introduced in version 4.0.3, which allow IPS to know if you have modified the files. The md5 check takes place in a file support.php located at /applications/core/modules/admin/support/support.php To take care of this, I just replaced the file, with the one from version 4.0.2, which never performed the md5 check. The contents of these is below:


And the 4.0.2 support.php file:

<?php

/**
* @brief Support Wizard
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright © 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 21 May 2014
* @version SVN_VERSION_NUMBER
*/

namespace IPS\core\modules\admin\support;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}

/**
* Support Wizard
*/
class _support extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'get_support' );
parent::execute();
}

/**
* Support Wizard
*
* @return void
*/
protected function manage()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('get_support');
\IPS\Output::i()->output = \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'support' )->support( new \IPS\Helpers\Wizard( array( 'type_of_problem' => array( $this, '_typeOfProblem' ), 'self_service' => array( $this, '_selfService' ), 'contact_support' => array( $this, '_contactSupport' ) ), \IPS\Http\Url::internal('app=core&module=support&controller=support') ) );

\IPS\Output::i()->sidebar['actions']['systemcheck'] = array(
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=support&controller=support&do=systemCheck' ),
'title' => 'requirements_checker',
);
}

/**
* phpinfo
*
* @return void
*/
protected function phpinfo()
{
phpinfo();
exit;
}

/**
* System Check
*
* @return void
*/
protected function systemCheck()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('requirements_checker');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'support' )->healthcheck( \IPS\core\Setup\Upgrade::systemRequirements() );
}

/**
* Step 1: Type of problem
*
* @param mixed $data Wizard data
* @return string|array
*/
public function _typeOfProblem( $data )
{
$form = new \IPS\Helpers\Form( 'form', 'continue' );
$form->class = 'ipsForm_horizontal ipsPad';
$form->add( new \IPS\Helpers\Form\Radio( 'type_of_problem_select', NULL, TRUE, array(
'options' => array( 'advice' => 'type_of_problem_advice', 'issue' => 'type_of_problem_issue' ),
'toggles' => array( 'advice' => array( 'support_advice_search' ) )
) ) );
$form->add( new \IPS\Helpers\Form\Text( 'support_advice_search', NULL, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->type_of_problem_select === 'advice' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'support_advice_search' ) );
if ( $values = $form->values() )
{
return array( 'type' => $values['type_of_problem_select'], 'keyword' => $values['support_advice_search'] );
}
return (string) $form;
}

/**
* Step 2: Self Service
*
* @param mixed $data Wizard data
* @return string|array
*/
public function _selfService( $data )
{
/* Advice */
if ( $data['type'] === 'advice' )
{
if ( isset( \IPS\Request::i()->next ) )
{
return $data;
}

$searchResults = array();
if ( $data['keyword'] )
{
$search = new \IPS\core\extensions\core\LiveSearch\Settings;
$searchResults = $search->getResults( $data['keyword'] );
}

$guides = array();
try
{
$guides = \IPS\Http\Url::ips( 'guides/' . urlencode( $data['keyword'] ) )->request()->get()->decodeJson();
}
catch ( \Exception $e ) { }

if ( count( $searchResults ) or count( $guides ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->advice( $searchResults, $guides );
}
else
{
return $data;
}
}

/* Issue */
else
{
if ( isset( \IPS\Request::i()->serviceDone ) )
{
return $data;
}

$baseUrl = \IPS\Http\Url::internal('app=core&module=support&controller=support&_step=self_service');

$overrideThingToTry = NULL;
if ( isset( \IPS\Request::i()->next ) )
{
$overrideThingToTry = \IPS\Request::i()->next;
$baseUrl = $baseUrl->setQueryString( 'next', $overrideThingToTry );
}

$possibleSolutions = array( '_requirementsChecker', '_databaseChecker', '_clearCaches', '_connectionChecker', '_whitespaceChecker', '_upgradeCheck', '_defaultTheme', '_disableThirdParty', '_knowledgebase' );
$self = $this;

return new \IPS\Helpers\MultipleRedirect(
$baseUrl,
function( $thingToTry ) use ( $self, $possibleSolutions, $overrideThingToTry )
{
if ( !is_null( $overrideThingToTry ) and $overrideThingToTry > $thingToTry )
{
$thingToTry = $overrideThingToTry;
}

if ( isset( $possibleSolutions[ $thingToTry ] ) )
{
$test = call_user_func( array( $self, $possibleSolutions[ $thingToTry ] ), $thingToTry );
if ( is_string( $test ) )
{
return array( $test );
}
else
{
return array( $thingToTry + 1, \IPS\Member::loggedIn()->language()->addToStack( 'looking_for_problems' ) );
}
}
else
{
return NULL;
}
},
function() use ( $baseUrl )
{
\IPS\Output::i()->redirect( $baseUrl->setQueryString( 'serviceDone', 1 ) );
}
);
}
}

/**
* Step 2: Self Service - Clear Caches
*
* @param int $id The current ID
* @return string|NULL
*/
public function _clearCaches( $id )
{
/* Clear JS Maps first */
\IPS\Output::clearJsFiles();

\IPS\Data\Store::i()->clearAll();
\IPS\Data\Cache::i()->clearAll();

return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( ++$id, 'support_caches_cleared' );
}

/**
* Step 2: Self Service - Database Checker
*
* @param int $id The current ID
* @return string|NULL
*/
public function _databaseChecker( $id )
{
$changesToMake = array();
$db = \IPS\Db::i();

/* Loop Apps */
foreach ( \IPS\Application::applications() as $app )
{
/* Loop the tables in the schema */
foreach( json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$app->directory}/data/schema.json" ), TRUE ) as $tableName => $tableDefinition )
{
/* Get our local definition of this table */
try
{
$localDefinition = \IPS\Db::i()->getTableDefinition( $tableName );
$localDefinition = \IPS\Db::i()->normalizeDefinition( $localDefinition );
$compareDefinition = \IPS\Db::i()->normalizeDefinition( $tableDefinition );
$tableDefinition = \IPS\Db::i()->updateDefinitionIndexLengths( $tableDefinition );

if ( $compareDefinition != $localDefinition )
{
/* Normalise it a little to prevent unnecessary conflicts */
foreach ( $tableDefinition['columns'] as $k => $c )
{
foreach ( array( 'length', 'decimals' ) as $i )
{
if ( isset( $c[ $i ] ) )
{
$tableDefinition['columns'][ $k ][ $i ] = intval( $c[ $i ] );
}
else
{
$tableDefinition['columns'][ $k ][ $i ] = NULL;
}
}

if ( !isset( $c['values'] ) )
{
$tableDefinition['columns'][ $k ]['values'] = array();
}

if ( $c['type'] === 'BIT' )
{
$tableDefinition['columns'][ $k ]['default'] = ( is_null($c['default']) ) ? NULL : "b'{$c['default']}'";
}

ksort( $tableDefinition['columns'][ $k ] );
}

/* Loop the columns */
foreach ( $tableDefinition['columns'] as $columnName => $columnData )
{
/* If it doesn't exist in the local database, create it */
if ( !isset( $localDefinition['columns'][ $columnName ] ) )
{
$changesToMake[] = "ALTER TABLE `{$db->prefix}{$db->escape_string( $tableName )}` ADD COLUMN {$db->compileColumnDefinition( $columnData )};";
}
/* Or if it's wrong, change it */
elseif ( $columnData != $localDefinition['columns'][ $columnName ] )
{
$changesToMake[] = "ALTER TABLE `{$db->prefix}{$db->escape_string( $tableName )}` CHANGE COLUMN `{$db->escape_string( $columnName )}` {$db->compileColumnDefinition( $columnData )};";
}
}

/* Loop the index */
foreach ( $compareDefinition['indexes'] as $indexName => $indexData )
{
if ( !isset( $localDefinition['indexes'][ $indexName ] ) )
{
$changesToMake[] = "ALTER TABLE `{$db->prefix}{$db->escape_string( $tableName )}` {$db->buildIndex( $tableName, $tableDefinition['indexes'][ $indexName ] )};";
}
elseif ( $indexData != $localDefinition['indexes'][ $indexName ] )
{
$changesToMake[] = "ALTER IGNORE TABLE `{$db->prefix}{$db->escape_string( $tableName )}` " . ( ( $indexName == 'PRIMARY KEY' ) ? "DROP " . $indexName . ", " : "DROP INDEX `" . $db->escape_string( $indexName ) . "`, " ) . $db->buildIndex( $tableName, $tableDefinition['indexes'][ $indexName ] ) . ';';
}
}
}
}
/* If the table doesn't exist, create it */
catch ( \OutOfRangeException $e )
{
$changesToMake[] = $db->_createTableQuery( $tableDefinition );
}
}
}

/* Display */
if ( $changesToMake )
{
if ( isset( \IPS\Request::i()->run ) )
{
$erroredQueries = array();
$errors = array();
foreach ( $changesToMake as $query )
{
try
{
\IPS\Db::i()->query( $query );
}
catch ( \Exception $e )
{
$erroredQueries[] = $query;
$errors[] = $e->getMessage();
}
}
if ( count( $erroredQueries ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->databaseChecker( $id, ++$id, $erroredQueries, $errors );
}
else
{
return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( ++$id, 'database_changes_made' );
}
}
else
{
return \IPS\Theme::i()->getTemplate( 'support' )->databaseChecker( $id, ++$id, $changesToMake );
}
}
elseif ( isset( \IPS\Request::i()->recheck ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( ++$id, 'database_changes_made' );
}
else
{
return NULL;
}
}

/**
* Step 2: Self Service - Whitespace Checker
*
* @param int $id The current ID
* @return string|NULL
*/
public function _whitespaceChecker( $id )
{
$files = $this->_whitespaceCheckerIterator( \IPS\ROOT_PATH );
if ( count( $files ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->whitespace( $files, $id );
}
return NULL;
}

/**
* Step 2: Whitespace Checker Iterator
*
* @param string $directory Directory to look through
* @return array
*/
public function _whitespaceCheckerIterator( $directory )
{
$return = array();

if ( !in_array( $directory, array( \IPS\ROOT_PATH . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . '3rd_party', \IPS\ROOT_PATH . DIRECTORY_SEPARATOR . 'applications' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'interface' . DIRECTORY_SEPARATOR . 'ckeditor' ) ) )
{
foreach( new \DirectoryIterator( $directory ) as $file )
{
if ( mb_substr( $file, 0, 1 ) === '.' or mb_substr( $file, 0, 1 ) === '_' or $file == 'index.html' )
{
continue;
}

if ( $file->isDir() )
{
$return = array_merge( $return, $this->_whitespaceCheckerIterator( $file->getPathname() ) );
}
elseif ( mb_substr( $file, -4 ) === '.php' )
{
$fullPath = $file->getPathname();

if ( !is_readable( $fullPath ) )
{
continue;
}

$contents = file_get_contents( $fullPath );
if ( ( mb_substr( ltrim( $contents ), 0, 3 ) == '<?php' and mb_substr( $contents, 0, 3 ) != '<?php' ) or ( ( mb_substr( rtrim( $contents ), -2 ) == '?>' AND mb_substr( $contents, -2 ) != '?>' ) and ( mb_substr( rtrim( $contents ), -2 ) == '?>' AND mb_substr( $contents, -3 ) != "?>\n" ) ) )
{
$return[] = $fullPath;
}
}
}
}
return $return;
}

/**
* Step 2: Self Service - Requirements Checker (Includes File Permissions)
*
* @param int $id The current ID
* @return string|NULL
*/
public function _requirementsChecker( $id )
{
$check = \IPS\core\Setup\Upgrade::systemRequirements();
foreach ( $check['requirements'] as $group => $requirements )
{
foreach ( $requirements as $requirement )
{
if ( !$requirement['success'] )
{
return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( $id, $requirement['message'], '', FALSE );
}
}
}

return NULL;
}

/**
* Step 2: Self Service - Connection Checker
*
* @param int $id The current ID
* @return string|NULL
*/
public function _connectionChecker( $id )
{
try
{
\IPS\Http\Url::ips( 'connectionCheck' )->request()->get();
return NULL;
}
catch ( \Exception $e )
{
return \IPS\Theme::i()->getTemplate( 'support' )->connectionChecker( ++$id );
}
}

/**
* Step 2: Self Service - Check for Uprade
*
* @param int $id The current ID
* @return string|NULL
*/
public function _upgradeCheck( $id )
{
try
{
$response = \IPS\Http\Url::ips('updateCheck')->request()->get()->decodeJson();
if ( $response['longversion'] > \IPS\Application::load('core')->long_version )
{
return \IPS\Theme::i()->getTemplate( 'support' )->upgrade( ++$id, $response['updateurl'] );
}
}
catch ( \Exception $e ) { }

return NULL;
}

/**
* Step 2: Self Service - Instruct user to try using default theme
*
* @param int $id The current ID
* @return string|NULL
*/
public function _defaultTheme( $id )
{
if ( isset( \IPS\Request::i()->deleteTheme ) )
{
try
{
\IPS\Theme::load( \IPS\Request::i()->deleteTheme )->delete();
}
catch ( \Exception $e ) {}

return NULL;
}

if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_theme_templates', 'template_set_id>0' )->first() or \IPS\Db::i()->select( 'COUNT(*)', 'core_theme_css', 'css_set_id>0' )->first() )
{
$newTheme = new \IPS\Theme;
$newTheme->permissions = \IPS\Member::loggedIn()->member_group_id;
$newTheme->save();
$newTheme->installThemeSettings();
$newTheme->copyResourcesFromSet();

\IPS\Lang::saveCustom( 'core', "core_theme_set_title_" . $newTheme->id, "IPS Support" );

\IPS\Member::loggedIn()->skin = $newTheme->id;

if( \IPS\Member::loggedIn()->acp_skin !== NULL )
{
\IPS\Member::loggedIn()->acp_skin = $newTheme->id;
}

\IPS\Member::loggedIn()->save();

return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( $id, 'try_default_theme', '&deleteTheme=' . $newTheme->id );
}

return NULL;
}

/**
* Step 2: Self Service - Disable 3rd party apps/plugins
*
* @param int $id The current ID
* @return string|NULL
*/
public function _disableThirdParty( $id )
{
if ( isset( \IPS\Request::i()->enableApps ) or isset( \IPS\Request::i()->enablePlugins ) )
{
foreach ( explode( ',', \IPS\Request::i()->enableApps ) as $app )
{
try
{
$app = \IPS\Application::load( $app );
$app->enabled = TRUE;
$app->save();
}
catch ( \Exception $e ) {}
}

foreach ( explode( ',', \IPS\Request::i()->enablePlugins ) as $plugin )
{
try
{
$plugin = \IPS\Plugin::load( $plugin );
$plugin->enabled = TRUE;
$plugin->save();
}
catch ( \Exception $e ) {}
}

return NULL;
}

$disabledApps = array();
$disabledPlugins = array();

/* Loop Apps */
foreach ( \IPS\Application::applications() as $app )
{
if ( $app->enabled and !in_array( $app->directory, \IPS\Application::$ipsApps ) )
{
$app->enabled = FALSE;
$app->save();

$disabledApps[] = $app->directory;
}
}

/* Look Plugins */
foreach ( \IPS\Plugin::plugins() as $plugin )
{
if ( $plugin->enabled )
{
$plugin->enabled = FALSE;
$plugin->save();

$disabledPlugins[] = $plugin->id;
}
}

/* Do any? */
if ( count( $disabledApps ) or count( $disabledPlugins ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->tryNow( $id, 'third_party_stuff_disabled', '&enableApps=' . implode( ',', $disabledApps ) . '&enablePlugins=' . implode( ',', $disabledPlugins ) );
}
else
{
return NULL;
}
}

/**
* Step 2: Self Service - Knowledgebase
*
* @param int $id The current ID
* @return string|NULL
*/
public function _knowledgebase( $id )
{
$kb = array();
try
{
$kb = \IPS\Http\Url::ips('kb')->request()->get()->decodeJson();
}
catch ( \Exception $e ) { }

if ( count( $kb ) )
{
return \IPS\Theme::i()->getTemplate( 'support' )->knowledgebase( ++$id, $kb );
}
return NULL;
}

/**
* Step 3: Contact Support
*
* @param mixed $data Wizard data
* @return string|array
*/
public function _contactSupport( $data )
{
$licenseData = \IPS\IPS::licenseKey();
if ( !$licenseData or strtotime( $licenseData['expires'] ) < time() )
{
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_no_license', 'warning' );
}

try
{
$supportedVerions = \IPS\Http\Url::ips('support/versions')->request()->get()->decodeJson();

if ( \IPS\Application::load('core')->long_version > $supportedVerions['max'] )
{
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_unsupported_prerelease', 'warning' );
}
if ( \IPS\Application::load('core')->long_version < $supportedVerions['min'] )
{
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_unsupported_obsolete', 'warning' );
}
}
catch ( \Exception $e ) {}

$form = new \IPS\Helpers\Form( 'contact_support', 'contact_support' );
$form->class = 'ipsForm_vertical ipsPad';

$extraOptions = array( 'admin' => 'support_request_admin' );
if ( $this->_supportLog( TRUE ) )
{
$form->hiddenValues['_log'] = '1';
$extraOptions['log'] = 'support_request_log';
}

$form->add( new \IPS\Helpers\Form\Text( 'support_request_title', NULL, TRUE, array( 'maxLength' => 128 ) ) );
$form->add( new \IPS\Helpers\Form\Editor( 'support_request_body', NULL, TRUE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'acp-support-request' ) ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'support_request_extra', array( 'admin', 'log' ), FALSE, array( 'options' => $extraOptions ) ) );
if ( $values = $form->values() )
{
$admin = NULL;
if ( in_array( 'admin', $values['support_request_extra'] ) )
{
$password = '';
$length = rand( 8, 15 );
for ( $i = 0; $i < $length; $i++ )
{
do {
$key = rand( 33, 126 );
} while ( in_array( $key, array( 34, 39, 60, 62, 92 ) ) );
$password .= chr( $key );
}

$supportAccount = \IPS\Member::load( '[email protected]', 'email' );
if ( !$supportAccount->member_id )
{
$name = 'IPS Support';
$_supportAccount = \IPS\Member::load( $name, 'name' );
if ( $_supportAccount->member_id )
{
$number = 2;
while ( $_supportAccount->member_id )
{
$name = "IPS Support {$number}";
$_supportAccount = \IPS\Member::load( $name, 'name' );
}
}

$supportAccount = new \IPS\Member;
$supportAccount->name = $name;
$supportAccount->email = '[email protected]';
$supportAccount->member_group_id = \IPS\Settings::i()->admin_group;
}

$supportAccount->members_pass_salt = $supportAccount->generateSalt();
$supportAccount->members_pass_hash = $supportAccount->encryptedPassword( $password );
$supportAccount->save();

$admin = json_encode( array( 'name' => $supportAccount->name, 'email' => $supportAccount->email, 'password' => $password, 'dir' => \IPS\CP_DIRECTORY ) );
}

$log = NULL;
if ( in_array( 'log', $values['support_request_extra'] ) )
{
$log = $this->_supportLog( FALSE );
}

$key = md5( \IPS\Http\Url::internal('app=core&module=support&controller=support') );
unset( $_SESSION["wizard-{$key}-step"] );
unset( $_SESSION["wizard-{$key}-data"] );

$response = \IPS\Http\Url::ips('support')->request()->login( \IPS\Settings::i()->ipb_reg_number, '' )->post( array(
'title' => $values['support_request_title'],
'message' => $values['support_request_body'],
'admin' => $admin,
'log' => $log,
'_log' => intval( isset( $values['_log'] ) )
) );

switch ( $response->httpResponseCode )
{
case 200:
case 201:
return \IPS\Theme::i()->getTemplate( 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'get_support_done', FALSE, array( 'pluralize' => array( intval( (string) $response ) ) ) ), 'success' );

case 401:
case 403:
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_no_license', 'warning' );

case 429:
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_duplicate', 'error' );

case 502:
default:
return \IPS\Theme::i()->getTemplate( 'global' )->message( 'get_support_error', 'error' );
}
}
return (string) $form;
}

/**
* Get the log that will be sent
*
* @param bool $checkOnly If TRUE, will just check if there is one to send
* @return void
*/
protected function _supportLog( $checkOnly )
{
$log = array();
$oneDayAgo = \IPS\DateTime::create()->sub( new \DateInterval('P1D') );
foreach( \IPS\Log::getUsedMethods() as $method => $levels )
{
if ( $method != 'none' and $logs = \IPS\Log::i( $method )->getLatestTitles( $oneDayAgo ) and !empty( $logs ) )
{
$log[ $method ] = $logs;
}
}

if ( $checkOnly )
{
return !empty( $log );
}

$output = '';
foreach ( $log as $method => $files )
{
foreach ( $files as $file )
{
$output = "/************************/\n" . $file . "\n/************************/\n\n";
$output .= \IPS\Log::i( $method )->getLog( $file );
}
}
return $output;
}

/**
* View the log that will be sent
*
* @return void
*/
public function supportLog()
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('support')->logToSend( $this->_supportLog( FALSE ) );
}
}

Users browsing this thread: 1 Guest(s)