Version 4.1.19.4

This commit is contained in:
Neo committed 2025-12-19 05:42:01 -08:00
1 parent 2bd5025018
commit 0dc2aee5ed
312 files changed
+53730 -32118

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,449 @@
<?php
namespace IPS\convert\modules\admin\manage;
/* 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;
}
/**
* convert
*/
class _convert extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Output::i()->responsive = FALSE;
\IPS\Dispatcher::i()->checkAcpPermission( 'convert_manage' );
parent::execute();
}
/**
* Show the conversion menu
*
* @return void
*/
protected function manage()
{
if ( ! isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/1' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V101/2', 404 );
}
$softwareClass = $app->getSource();
$libraryClass = $softwareClass->getLibrary();
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'converting_x_to_x', FALSE, array( 'sprintf' => array( $softwareClass::softwareName(), \IPS\Application::load( $app->sw )->_title ) ) );
/* Build our table. If I can do this using only the Table helper, I'll be impressed */
try
{
$menuRows = $libraryClass->menuRows();
}
catch( \IPS\convert\Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '1V101/3' );
}
$table = new \IPS\Helpers\Table\Custom( $menuRows, \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert" ) );
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'table' ), 'convertMenuRow' );
$table->extra = array( 'sessionData' => $app->_session, 'appClass' => $app, 'softwareClass' => $softwareClass, 'libraryClass' => $libraryClass, 'menuRows' => $menuRows );
$table->mainColumn = 'step_title';
$table->showAdvancedSearch = FALSE;
$table->noSort = array( 'step_title', 'ips_rows', 'source_rows', 'per_cycle', 'empty_local_data', 'step_method' );
$table->include = array( 'step_title', 'ips_rows', 'source_rows', 'per_cycle', 'empty_local_data', 'step_method' );
$table->parsers = array(
'step_title' => function( $row )
{
return \IPS\Member::loggedIn()->language()->addToStack( $row );
},
);
\IPS\Output::i()->output = '';
if ( $softwareClass::canConvertSettings() !== FALSE )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'table' )->settingsMessage( $app );
}
\IPS\Output::i()->output .= $table;
if ( $libraryClass->getPostConversionInformation() != NULL )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'table' )->postConversionInformation( $libraryClass->getPostConversionInformation() );
}
}
/**
* Remove Converted Data
*
* @return void
*/
protected function emptyData()
{
if ( ! isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/4' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V101/5' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'removing_data' );
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=emptyData&id={$app->app_id}&method=" . \IPS\Request::i()->method ),
function( $data ) use ( $app )
{
try
{
return $app->getSource()->getLibrary()->emptyData( $data, \IPS\Request::i()->method );
}
catch( \IPS\convert\Exception $e )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=error&id={$app->app_id}" ) );
}
},
function() use ( $app )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$app->app_id}" ) );
} );
}
/**
* Run a conversion step
*
* @return void
*/
protected function runStep()
{
if ( ! isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/6' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V101/7', 404 );
}
/* Do we need more information? */
$softwareClass = $app->getSource();
if ( ! isset( $app->_session['more_info'][ \IPS\Request::i()->method ] ) OR ( isset( \IPS\Request::i()->reconfigure ) AND \IPS\Request::i()->reconfigure == 1 ) )
{
if ( in_array( \IPS\Request::i()->method, $softwareClass::checkConf() ) )
{
$getMoreInfo = $softwareClass->getMoreInfo( \IPS\Request::i()->method );
if ( is_array( $getMoreInfo ) AND count( $getMoreInfo ) )
{
$form = new \IPS\Helpers\Form( \IPS\Request::i()->method . '_more_info', 'continue' );
$form->hiddenValues['per_cycle'] = \IPS\Request::i()->per_cycle;
if ( isset( \IPS\Request::i()->empty_local_data ) AND \IPS\Request::i()->empty_local_data == 1 )
{
$form->hiddenValues['empty_local_data'] = 1;
}
if ( isset( \IPS\Request::i()->reconfigure ) )
{
$form->hiddenValues['reconfigure'] = 1;
}
$hints = array();
foreach( $getMoreInfo as $key => $input )
{
$fieldClass = $input['field_class'];
$form->add( new $fieldClass( $key, $input['field_default'], $input['field_required'], $input['field_extra'], isset( $input['field_validation'] ) ? $input['field_validation'] : NULL ) );
if ( $input['field_hint'] !== NULL )
{
$form->addMessage( $input['field_hint'], 'ipsMessage ipsMessage_info' );
}
}
if ( $values = $form->values() )
{
$per_cycle = $values['per_cycle'];
unset( $values['per_cycle'] );
$app->saveMoreInfo( \IPS\Request::i()->method, $values );
$extra = '';
if ( isset( \IPS\Request::i()->empty_local_data ) AND \IPS\Request::i()->empty_local_data == 1 )
{
$extra .= "&empty_local_data=1";
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=runStep&id={$app->app_id}&per_cycle={$per_cycle}&method=" . \IPS\Request::i()->method . $extra ) );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'more_info_needed' );
\IPS\Output::i()->output = $form;
return;
}
}
}
/* If we decided to truncate, do so now */
if ( isset( \IPS\Request::i()->empty_local_data ) AND \IPS\Request::i()->empty_local_data == 1 )
{
$app->getSource()->getLibrary()->emptyLocalData( \IPS\Request::i()->method );
}
/* Are we continuing? We need to tell the library that, but we need to use sessions to do it so it only does it on the first cycle. */
if ( isset( \IPS\Request::i()->continue ) )
{
/* Is it set? If not, just go ahead. */
if ( !isset( $_SESSION['convertContinue'] ) )
{
$_SESSION['convertContinue'] = TRUE;
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'converting' );
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=runStep&id={$app->app_id}&per_cycle=" . \IPS\Request::i()->per_cycle . "&method=" . \IPS\Request::i()->method ),
function( $data ) use ( $app )
{
try
{
return $app->getSource()->getLibrary()->process( $data, \IPS\Request::i()->method, \IPS\Request::i()->per_cycle );
}
catch( \IPS\convert\Exception $e )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=error&id={$app->app_id}" ) );
}
},
function() use ( $app )
{
/* Do we have more steps to process? If so, go to those first. */
$canConvert = $app->getSource()->getLibrary()->getConvertableItems();
if ( isset( $canConvert[ \IPS\Request::i()->method ]['extra_steps'] ) )
{
/* See which one we need to run next. */
$next = NULL;
foreach( $canConvert[ \IPS\Request::i()->method ]['extra_steps'] as $next )
{
if ( in_array( $next, $app->_session['completed'] ) )
{
$next = NULL;
continue;
}
}
/* Found one? */
if ( !is_null( $next ) )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=runStep&id={$app->app_id}&per_cycle=" . \IPS\Request::i()->per_cycle . "&method={$next}" ) );
}
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$app->app_id}" ) );
} );
}
/**
* Show an error
*
* @return void
*/
public function error()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/8' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V101/9', 404 );
}
/* Load the last actual error logged */
$error = \IPS\Db::i()->select( '*', 'convert_logs', array( 'log_app=?', $app->app_id ), 'log_id DESC', 1 )->first();
/* Just use generic error wrapper */
\IPS\Output::i()->error( $error['log_method'] . ': ' . $error['log_message'], '2V101/A' );
}
/**
* Convert Settings
*
* @return void
*/
public function settings()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/B' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V101/C', 404 );
}
$softwareClass = $app->getSource();
if ( $softwareClass::canConvertSettings() === FALSE )
{
\IPS\Output::i()->error( 'settings_conversion_not_supported', '2V101/D' );
}
$form = new \IPS\Helpers\Form;
foreach( $softwareClass->settingsMapList() as $key => $setting )
{
$value = $setting['value'];
if ( is_bool( ( $setting['value'] ) ) )
{
$value = $setting['value'] === TRUE ? 'On' : 'Off';
}
$form->add( new \IPS\Helpers\Form\Checkbox( $setting['our_key'], TRUE, FALSE, array( 'label' => $value ) ) );
}
if ( $values = $form->values() )
{
$softwareClass->convertSettings( $values );
unset( \IPS\Data\Store::i()->settings );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$app->app_id}" ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'converting_settings' );
\IPS\Output::i()->output = $form;
}
/**
* Finish
*
* @return void
*/
public function finish()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V101/E' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\output::i()->error( 'conversion_app_not_found', '2V101/F', 404 );
}
/* Make sure the user confirmed they want to finish */
\IPS\Request::i()->confirmedDelete( 'convert_finish_confirm_title', 'convert_finish_confirm', 'finish' );
$softwareClass = $app->getSource();
$messages = array();
/* If we have a parent, run them. */
try
{
if ( $app->parent )
{
$parent = \IPS\convert\App::load( $app->parent );
if ( method_exists( $parent->getSource(), 'finish' ) )
{
$return = $parent->getSource()->finish();
$parent->app->log( 'app_finished', __METHOD__, \IPS\convert\App::LOG_NOTICE );
if ( is_array( $return ) )
{
$messages = array_merge( $messages, $return );
}
}
/* Run siblings if need be */
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'convert_apps', array( "parent=? AND app_id!=?", $parent->app_id, $app->app_id ) ), 'IPS\convert\App' ) AS $sibling )
{
if ( method_exists( $sibling->getSource(), 'finish' ) )
{
$return = $sibling->getSource()->finish();
$sibling->app->log( 'app_finished', __METHOD__, \IPS\convert\App::LOG_NOTICE );
if ( is_array( $return ) )
{
$messages = array_merge( $messages, $return );
}
}
}
}
else
{
/* No parent - bubble up to the exception */
throw new \OutOfRangeException;
}
}
catch( \OutOfRangeException $e )
{
/* This is a parent - run it's children */
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'convert_apps', array( "parent=?", $app->app_id ) ), 'IPS\convert\App' ) AS $child )
{
$childSoftwareClass = $child->getSource();
if ( method_exists( $childSoftwareClass, 'finish' ) )
{
$return = $childSoftwareClass->finish();
$childSoftwareClass->app->log( 'app_finished', __METHOD__, \IPS\convert\App::LOG_NOTICE );
if ( is_array( $return ) )
{
$messages = array_merge( $messages, $return );
}
}
}
}
/* And finally, run this one */
if ( method_exists( $softwareClass, 'finish' ) )
{
$return = $softwareClass->finish();
$softwareClass->app->log( 'app_finished', __METHOD__, \IPS\convert\App::LOG_NOTICE );
if ( is_array( $return ) )
{
$messages = array_merge( $messages, $return );
}
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), implode( ', ', array_map( function( $key ) {
return \IPS\Member::loggedIn()->language()->addToStack( $key );
}, $messages ) ) );
}
}
@@ -0,0 +1,348 @@
<?php
namespace IPS\convert\modules\admin\manage;
/* 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;
}
/**
* create
*/
class _create extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Output::i()->responsive = FALSE;
\IPS\Dispatcher::i()->checkAcpPermission( 'create_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* We only use the Wizard helper for starting a conversion, so we need to make sure it is always starting new and not using old session data */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'convert_start' );
/* Let's call on the wizard to make some magic */
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
'convert_start_application' => array( $this, '_stepOne' ),
'convert_start_source_software' => array( $this, '_stepTwo' ),
'convert_start_database_details' => array( $this, '_stepThree' ),
), \IPS\Http\Url::internal( 'app=convert&module=manage&controller=create' ) );
}
/**
* First step of conversion
*
* @return void
*/
public function _stepOne( $data )
{
foreach( \IPS\Application::applications() AS $app )
{
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( "{$app->directory}_node_select" ) )
{
\IPS\member::loggedIn()->language()->words["__app_{$app->directory}"] = \IPS\Member::loggedIn()->language()->addToStack( "{$app->directory}_node_select" );
}
}
/* Have we done any conversions yet? */
$appCount = \IPS\Db::i()->select( 'COUNT(*)', 'convert_apps', array( "parent=?", 0 ) )->first();
$form = new \IPS\Helpers\Form( 'convert_application', 'select_source' );
$form->add( new \IPS\Helpers\Form\Node( 'convert_start_application', NULL, TRUE, array( 'class' => 'IPS\\Application', 'subnodes' => FALSE, 'permissionCheck' => function( $node ) use ( $appCount )
{
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Library' ) AS $file )
{
if ( ucwords( $node->directory ) === str_replace( '.php', '', $file->getFilename() ) )
{
if ( $node->directory === 'core' OR $appCount > 0 )
{
return TRUE;
}
}
}
return NULL;
} ) ) );
if ( $values = $form->values() )
{
return array( 'convert_start_application' => $values['convert_start_application']->directory );
}
return $form;
}
/**
* Second step of conversion
*
* @return void
*/
public function _stepTwo( $data )
{
$options = array();
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' . ucwords( $data['convert_start_application'] ) ) AS $file )
{
$classname = 'IPS\\convert\\Software\\' . ucwords( $data['convert_start_application'] ) . '\\' . ucwords( str_replace( '.php', '', $file->getFilename() ) );
if ( class_exists( $classname ) AND $classname::canConvert() !== NULL )
{
$options[ $classname::softwareKey() ] = $classname::softwareName();
}
}
$form = new \IPS\Helpers\Form( 'convert_source_software', 'enter_database_details' );
$form->add( new \IPS\Helpers\Form\Select( 'convert_start_source_software', NULL, TRUE, array( 'options' => $options ) ) );
if ( $values = $form->values() )
{
return $values;
}
return $form;
}
/**
* Third step of conversion
*
* @return void
*/
public function _stepThree( $data )
{
$form = new \IPS\Helpers\Form( 'convert_database_details', 'start_conversion' );
$classname = 'IPS\\convert\\Software\\' . ucwords( $data['convert_start_application'] ) . '\\' . ucwords( $data['convert_start_source_software'] );
if ( !is_null( $classname::parents() ) AND is_array( $classname::parents() ) )
{
/* Do we have any available parents? */
$where = array();
$options = array();
foreach( $classname::parents() AS $app => $sw )
{
foreach( $sw AS $key )
{
$where[] = array( 'sw=? AND app_key=?', $app, $key );
}
}
try
{
foreach( \IPS\Db::i()->select( '*', 'convert_apps', $where ) AS $row )
{
$name = explode( '_', $row['name'] );
$parentClassname = 'IPS\\convert\\Software\\' . ucwords( $name[0] ) . '\\' . ucwords( $name[1] );
$options[$row['app_id']] = $parentClassname::softwareName();
}
}
catch( \Exception $e ) {}
/* If we have any possible parents, lets add a select menu */
if ( count( $options ) > 0 )
{
$form->addHeader( 'convert_start_select_parent' );
$form->add( new \IPS\Helpers\Form\Select( 'convert_start_parent', NULL, FALSE, array( 'options' => $options ) ) );
$form->addHeader( 'convert_start_or_database' );
}
/* This software class requires a parent, but we don't have any that have been converted */
elseif( $classname::requiresParent() )
{
\IPS\Output::i()->error( 'convert_no_applicable_parent', '4V346/1' );
}
}
if ( $classname::getPreConversionInformation() !== NULL )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $classname::getPreConversionInformation() ), '', FALSE );
}
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_host', NULL, FALSE ) );
$form->add( new \IPS\Helpers\Form\Number( 'convert_start_database_port', 3306, FALSE, array( 'max' => 65535, 'min' => 1 ) ) );
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_name', NULL, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_user', NULL, FALSE ) );
$form->add( new \IPS\Helpers\Form\Password( 'convert_start_database_pass', NULL, FALSE ) );
/* If the source software doesn't use a prefix, then we should not ask for one to avoid confusion. */
if ( $classname::usesPrefix() )
{
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_prefix', NULL, FALSE ) );
}
$form->add( new \IPS\Helpers\Form\Text( 'convert_start_database_charset', NULL, FALSE, array( 'placeholder' => 'utf8' ) ) );
if ( $values = $form->values() )
{
/* Did we select a parent but no DB details? */
if (
isset( $values['convert_start_parent'] ) AND
( !isset( $values['convert_start_database_host'] ) || empty($values['convert_start_database_host']) ) AND
( !isset( $values['convert_start_database_name'] ) || empty($values['convert_start_database_name']) ) AND
( !isset( $values['convert_start_database_user'] ) || empty($values['convert_start_database_user']) ) AND
( !isset( $values['convert_start_database_pass'] ) || empty($values['convert_start_database_pass']) ) AND
( !isset( $values['convert_start_database_prefix'] ) || empty($values['convert_start_database_prefix']) ) AND
( !isset( $values['convert_start_database_charset'] ) || empty($values['convert_start_database_charset']) )
)
{
/* We did - load the parent app and store the DB details for that */
$parentApp = \IPS\convert\App::load( $values['convert_start_parent'] );
$values['convert_start_database_host'] = $parentApp->db_host;
$values['convert_start_database_port'] = $parentApp->db_port;
$values['convert_start_database_name'] = $parentApp->db_db;
$values['convert_start_database_user'] = $parentApp->db_user;
$values['convert_start_database_pass'] = $parentApp->db_pass;
$values['convert_start_database_prefix'] = $parentApp->db_prefix;
$values['convert_start_database_charset'] = $parentApp->db_charset;
}
/* Start the app object */
$app = new \IPS\convert\App;
$app->sw = $data['convert_start_application'];
$app->app_key = $data['convert_start_source_software'];
try
{
/* Test the connection */
$connectionSettings = array(
'sql_host' => $values['convert_start_database_host'],
'sql_port' => $values['convert_start_database_port'],
'sql_user' => $values['convert_start_database_user'],
'sql_pass' => $values['convert_start_database_pass'],
'sql_database' => $values['convert_start_database_name'],
'sql_tbl_prefix' => $values['convert_start_database_prefix'],
);
if ( $values['convert_start_database_charset'] === 'utf8mb4' )
{
$connectionSettings['sql_utf8mb4'] = TRUE;
}
$db = \IPS\Db::i( 'convertertest', $connectionSettings );
/* Now test the charset */
if ( $values['convert_start_database_charset'] AND !in_array( $values['convert_start_database_charset'], array( 'utf8', 'utf8mb4' ) ) )
{
/* Get all db charsets and make sure the one we entered is valid */
$charsets = \IPS\convert\Software::getDatabaseCharsets( $db );
if ( !in_array( mb_strtolower( $values['convert_start_database_charset'] ), $charsets ) )
{
throw new \InvalidArgumentException( 'invalid_charset' );
}
$db->set_charset( $values['convert_start_database_charset'] );
}
/* Try to verify that the db prefix is correct */
$appClassName = $app->getSource( FALSE, FALSE );
$canConvert = $appClassName::canConvert();
$appClass = new $appClassName( $app, FALSE );
$appClass->db = $db;
$testAgainst = array_shift( $canConvert );
/* We specifically use CountRows to test this, canConvert() may contain references to tables that do not exist..
* ..This is for the row count look up.
*/
try
{
$appClass->countRows( $testAgainst['table'] );
}
catch( \UnderflowException $e )
{
throw new \InvalidArgumentException( 'invalid_prefix' );
}
}
catch( \InvalidArgumentException $e )
{
if( $e->getMessage() == 'invalid_charset' )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db_charset');
return $form;
}
else if( $e->getMessage() == 'invalid_prefix' )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db_prefix');
return $form;
}
else
{
throw $e;
}
}
catch( \Exception $e )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db');
return $form;
}
try
{
$appExists = \IPS\convert\App::load( $data['convert_start_application'] . '_' . $data['convert_start_source_software'], 'name' );
$app->name = $data['convert_start_application'] . '_' . $data['convert_start_source_software'] . '_' . time();
}
catch( \OutOfRangeException $e )
{
$app->name = $data['convert_start_application'] . '_' . $data['convert_start_source_software'];
}
if ( isset( $values['convert_start_parent'] ) )
{
$app->parent = $values['convert_start_parent'];
}
else
{
$app->parent = 0;
}
if ( !isset( $values['convert_start_database_prefix'] ) )
{
$values['convert_start_database_prefix'] = '';
}
$app->db_host = $values['convert_start_database_host'];
$app->db_port = $values['convert_start_database_port'];
$app->db_db = $values['convert_start_database_name'];
$app->db_user = $values['convert_start_database_user'];
$app->db_pass = $values['convert_start_database_pass'];
$app->db_prefix = $values['convert_start_database_prefix'];
/* Check for existing apps */
try
{
$existingApp = \IPS\DB::i()->select( '*', 'convert_apps', array( 'sw=? AND app_key=? AND db_host=? AND db_db=? AND db_user=? AND db_pass=? AND db_prefix=?', $app->sw, $app->app_key, $app->db_host, $app->db_db, $app->db_user, $app->db_pass, $app->db_prefix ) )->first();
/* App already exists */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$existingApp['app_id']}" ), 'conversion_app_already_exists' );
}
catch( \UnderflowException $e ) { }
if ( !empty( $values['convert_start_database_charset'] ) )
{
$app->db_charset = $values['convert_start_database_charset'];
}
else
{
$app->db_charset = 'utf8';
}
$app->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$app->app_id}" ) );
}
return $form;
}
}
@@ -0,0 +1,417 @@
<?php
namespace IPS\convert\modules\admin\manage;
/* 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;
}
/**
* manage
*/
class _manage extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Output::i()->responsive = FALSE;
\IPS\Dispatcher::i()->checkAcpPermission( 'manage_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* If mod_rewrite is not enabled, advise the administrator that old URLs will not redirect to the new locations automatically */
if( !\IPS\Settings::i()->htaccess_mod_rewrite )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_mod_rewrite_urls', 'warning' );
}
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'convert_apps', \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ) );
$table->langPrefix = 'convert_';
$table->include = array( 'sw', 'app_key', 'name', 'parent' );
$table->parsers = array(
'sw' => function( $val, $row )
{
switch( $val )
{
case 'board':
$val = 'forums';
break;
case 'ccs':
$val = 'cms';
break;
}
try
{
return \IPS\Application::load( $val )->_title;
}
catch( \OutOfRangeException $e )
{
return ucwords( $val );
}
},
'app_key' => function( $val, $row )
{
$app = \IPS\convert\App::constructFromData( $row );
try
{
$classname = get_class( $app->getSource() );
return $classname::softwareName();
}
catch( \Exception $ex )
{
return $app->name;
}
},
'parent' => function( $val, $row )
{
try
{
if ( ! $val )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'convert_no_parent' );
}
else
{
return \IPS\convert\App::load( $val )->name;
}
}
catch( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'convert_cannot_parent' );
}
}
);
$table->rootButtons = array(
'start' => array(
'icon' => 'plus',
'title' => 'convert_start',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=create&_new=1" ),
)
);
if ( \IPS\IN_DEV )
{
$table->rootButtons += array(
'software' => array(
'icon' => 'plus',
'title' => 'new_software',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=software" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('new_software') )
),
'library' => array(
'icon' => 'plus',
'title' => 'new_library',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=library" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('new_library') )
)
);
}
$table->rowButtons = function( $row )
{
try
{
/* Try to load the application to make sure it's installed */
\IPS\Application::load( $row['sw'] );
/* Try to load the app class - if exception, the converter no longer exists */
get_class( \IPS\convert\App::constructFromData( $row )->getSource() );
$return = array();
$return[] = array(
'icon' => 'chevron-circle-right',
'title' => 'continue',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$row['app_id']}" )
);
if ( $row['parent'] == 0 )
{
$return[] = array(
'icon' => 'check',
'title' => 'finish',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$row['app_id']}" ),
'data' => array(
'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->get( 'convert_finish_confirm' )
)
);
}
$return[] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=edit&id={$row['app_id']}" ),
);
$return[] = array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=delete&id={$row['app_id']}" ),
'data' => array( 'delete' => '' ),
);
return $return;
}
catch( \InvalidArgumentException $e )
{
return array();
}
/* Application has been uninstalled */
catch( \OutOfRangeException $e )
{
return array();
}
};
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__convert_manage' );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
}
/**
* Create New Converter
*
* @return void
*/
public function software()
{
if ( \IPS\IN_DEV === FALSE )
{
\IPS\Output::i()->error( 'new_sofware_not_in_dev', '1V100/1', 403 );
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'classname', NULL, TRUE ) );
$apps = array();
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Library' ) as $file )
{
if ( !$file->isDir() AND !$file->isDot() AND ( \substr( $file->getFilename(), -4 ) == '.php' ) AND $file->getFilename() != 'Board.php' AND $file->getFilename() != 'Ccs.php' )
{
$apps[ str_replace( '.php', '', $file->getFilename() ) ] = str_replace( '.php', '', $file->getFilename() );
}
}
$form->add( new \IPS\Helpers\Form\Select( 'library', NULL, FALSE, array( 'options' => $apps ) ) );
if ( $values = $form->values() )
{
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Software.txt' );
$code = str_replace( array( '<#CLASS#>', '<#APP#>', '<#CLASS_LOWER#>' ), array( $values['classname'], $values['library'], mb_strtolower( $values['classname'] ) ), $default );
\file_put_contents( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' . $values['library'] . '/' . $values['classname'] . '.php', $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'new_software' );
\IPS\Output::i()->output = (string) $form;
}
/**
* Create New Library
*
* @return void
*/
public function library()
{
if ( \IPS\IN_DEV === FALSE )
{
\IPS\Output::i()->error( 'new_library_not_in_dev', '1V100/2', 403 );
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'classname', NULL, TRUE ) );
if ( $values = $form->values() )
{
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Library.txt' );
$code = str_replace( array( '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $values['classname'], mb_strtolower( $values['classname'] ) ), $default );
\file_put_contents( \IPS\ROOT_PATH . '/applications/convert/sources/Library/' . $values['classname'] . '.php', $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'new_library' );
\IPS\Output::i()->output = (string) $form;
}
/**
* Edit a conversion
*
* @return void
*/
public function edit()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V100/3' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V100/4', 404 );
}
$classname = $app->getSource( FALSE );
$form = new \IPS\Helpers\Form;
if ( $classname::getPreConversionInformation() !== NULL )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $classname::getPreConversionInformation() ), '', FALSE );
}
$form->add( new \IPS\Helpers\Form\Text( 'db_host', $app->db_host, FALSE ) );
$form->add( new \IPS\Helpers\Form\Number( 'db_port', $app->db_port, FALSE, array( 'max' => 65535, 'min' => 1 ) ) );
$form->add( new \IPS\Helpers\Form\Text( 'db_db', $app->db_db, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'db_user', $app->db_user, FALSE ) );
$form->add( new \IPS\Helpers\Form\Password( 'db_pass', $app->db_pass, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'db_prefix', $app->db_prefix, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'db_charset', $app->db_charset, FALSE ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'edit_conversion' );
if ( $values = $form->values() )
{
try
{
/* Test the connection */
$connectionSettings = array(
'sql_host' => $values['db_host'],
'sql_port' => $values['db_port'],
'sql_user' => $values['db_user'],
'sql_pass' => $values['db_pass'],
'sql_database' => $values['db_db'],
'sql_tbl_prefix' => $values['db_prefix'],
);
if ( $values['db_charset'] === 'utf8mb4' )
{
$connectionSettings['sql_utf8mb4'] = TRUE;
}
$db = \IPS\Db::i( 'convertertest', $connectionSettings );
/* Now test the charset */
if ( $values['db_charset'] AND !in_array( $values['db_charset'], array( 'utf8', 'utf8mb4' ) ) )
{
/* Get all db charsets and make sure the one we entered is valid */
$charsets = \IPS\convert\Software::getDatabaseCharsets( $db );
if ( !in_array( mb_strtolower( $values['db_charset'] ), $charsets ) )
{
throw new \InvalidArgumentException( 'invalid_charset' );
}
$db->set_charset( $values['db_charset'] );
}
/* Try to verify that the db prefix is correct */
$appClass = $app->getSource( FALSE, FALSE );
$canConvert = $appClass::canConvert();
$testAgainst = array_shift( $canConvert );
if( !$db->checkForTable( $testAgainst['table'] ) )
{
throw new \InvalidArgumentException( 'invalid_prefix' );
}
}
catch( \InvalidArgumentException $e )
{
if( $e->getMessage() == 'invalid_charset' )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db_charset');
\IPS\Output::i()->output = $form;
return;
}
else if( $e->getMessage() == 'invalid_prefix' )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db_prefix');
\IPS\Output::i()->output = $form;
return;
}
else
{
throw $e;
}
}
catch( \Exception $e )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db');
\IPS\Output::i()->output = $form;
return;
}
$app->db_host = $values['db_host'];
$app->db_port = $values['db_port'];
$app->db_db = $values['db_db'];
$app->db_user = $values['db_user'];
$app->db_pass = $values['db_pass'];
$app->db_prefix = $values['db_prefix'];
$app->db_charset = $values['db_charset'];
$app->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
}
\IPS\Output::i()->output = $form;
}
/**
* Delete a Conversion
*
* @return void
*/
public function delete()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V100/5' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
/* Check for children */
try
{
\IPS\DB::i()->select( '*', 'convert_apps', array( 'parent=?', $app->app_id ) )->first();
\IPS\Output::i()->error( 'conversion_app_has_children', '2V100/6' );
}
catch( \UnderflowException $ex ) { }
$app->delete();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), 'conversion_deleted' );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V100/6', 404 );
}
}
}