Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,21 +12,52 @@
namespace IPS\convert\modules\admin\manage;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use InvalidArgumentException;
use IPS\Application;
use IPS\convert\App;
use IPS\convert\Software;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Password;
use IPS\Helpers\Form\Text;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function file_put_contents;
use function get_class;
use function in_array;
use const IPS\CONVERTERS_DEV_UI;
use const IPS\DEMO_MODE;
use const IPS\FOLDER_PERMISSION_NO_WRITE;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Converter overview
*/
class _manage extends \IPS\Dispatcher\Controller
class manage extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
@@ -35,13 +66,13 @@ class _manage extends \IPS\Dispatcher\Controller
*/
public function execute()
{
if ( \IPS\DEMO_MODE === TRUE )
if ( DEMO_MODE === TRUE )
{
\IPS\Output::i()->error( 'demo_mode_function_blocked', '2V407/1', 403, '' );
Output::i()->error( 'demo_mode_function_blocked', '2V407/1', 403, '' );
}
\IPS\Output::i()->responsive = FALSE;
\IPS\Dispatcher::i()->checkAcpPermission( 'manage_manage' );
Output::i()->responsive = FALSE;
Dispatcher::i()->checkAcpPermission( 'manage_manage' );
parent::execute();
}
@@ -53,16 +84,16 @@ class _manage extends \IPS\Dispatcher\Controller
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 )
if( !Settings::i()->htaccess_mod_rewrite )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_mod_rewrite_urls', 'warning' );
Output::i()->output .= Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_mod_rewrite_urls', 'warning' );
}
/* Remind the user that they must configure permissions after the conversion is complete */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_configure_permissions', 'info' );
Output::i()->output .= Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_configure_permissions', 'info' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'convert_apps', \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), array( 'parent=?', 0 ) );
$table = new \IPS\Helpers\Table\Db( 'convert_apps', Url::internal( 'app=convert&module=manage&controller=manage' ), array( 'parent=?', 0 ) );
$table->langPrefix = 'convert_';
$table->include = array( 'app_key', 'sw', 'start_date', 'finished' );
@@ -86,48 +117,48 @@ class _manage extends \IPS\Dispatcher\Controller
};
/* The main row will always be the core application (except for legacy conversions) */
$applications = array( \IPS\Application::load( $translate( $val ) )->_title );
$applications = array( Application::load( $translate( $val ) )->_title );
foreach( \IPS\Db::i()->select( '*', 'convert_apps', array( 'parent=?', $row['app_id'] ) ) as $software )
foreach( Db::i()->select( '*', 'convert_apps', array( 'parent=?', $row['app_id'] ) ) as $software )
{
/* Translate the software key, if required */
$software['sw'] = $translate( $software['sw'] );
try
{
if ( \IPS\CONVERTERS_DEV_UI === TRUE )
if ( CONVERTERS_DEV_UI === TRUE )
{
$continueUrl = \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$software['app_id']}&continue=1" )->csrf();
$applications[] = "<a href='{$continueUrl}'>" . \IPS\Application::load( $software['sw'] )->_title . "</a>";
$continueUrl = Url::internal( "app=convert&module=manage&controller=convert&id={$software['app_id']}&continue=1" )->csrf();
$applications[] = "<a href='{$continueUrl}'>" . Application::load( $software['sw'] )->_title . "</a>";
continue;
}
$applications[] = \IPS\Application::load( $software['sw'] )->_title;
$applications[] = Application::load( $software['sw'] )->_title;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$applications[] = mb_ucfirst( $software );
$applications[] = IPS::mb_ucfirst( $software );
}
}
return \IPS\Member::loggedIn()->language()->formatList( $applications );
return Member::loggedIn()->language()->formatList( $applications );
},
'app_key' => function( $val, $row )
{
$app = \IPS\convert\App::constructFromData( $row );
$app = App::constructFromData( $row );
try
{
$classname = \get_class( $app->getSource(true,false) );
$classname = get_class( $app->getSource() );
return $classname::softwareName();
}
catch( \Exception $ex )
catch( Exception $ex )
{
return $val;
}
},
'start_date' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
return (string) DateTime::ts( $val );
},
'finished' => function( $val )
{
@@ -144,27 +175,27 @@ class _manage extends \IPS\Dispatcher\Controller
if( !\IPS\CIC )
{
\IPS\Output::i()->sidebar['actions']['start'] = array(
Output::i()->sidebar['actions']['start'] = [
'primary' => true,
'icon' => 'plus',
'title' => 'convert_start',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=create&_new=1" ),
);
'link' => Url::internal( "app=convert&module=manage&controller=create&_new=1" ),
];
}
if ( \IPS\IN_DEV )
{
\IPS\Output::i()->sidebar['actions']['software'] = array(
Output::i()->sidebar['actions']['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') )
'link' => Url::internal( "app=convert&module=manage&controller=manage&do=software" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('new_software') )
);
\IPS\Output::i()->sidebar['actions']['library'] = array(
Output::i()->sidebar['actions']['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') )
'link' => Url::internal( "app=convert&module=manage&controller=manage&do=library" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('new_library') )
);
}
@@ -173,29 +204,29 @@ class _manage extends \IPS\Dispatcher\Controller
try
{
/* Try to load the application to make sure it's installed */
\IPS\Application::load( $row['sw'] );
Application::load( $row['sw'] );
/* Try to load the app class - if exception, the converter no longer exists */
\IPS\convert\App::constructFromData( $row )->getSource();
App::constructFromData( $row )->getSource();
$return = array();
if ( !$row['finished'] OR \IPS\CONVERTERS_DEV_UI === TRUE )
if ( !$row['finished'] OR CONVERTERS_DEV_UI === TRUE )
{
$return[] = array(
'icon' => 'chevron-circle-right',
'title' => 'continue',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$row['app_id']}&continue=1" )->csrf()
'link' => Url::internal( "app=convert&module=manage&controller=convert&id={$row['app_id']}&continue=1" )->csrf()
);
if( \IPS\CONVERTERS_DEV_UI === TRUE AND !$row['finished'] )
if( CONVERTERS_DEV_UI === TRUE AND !$row['finished'] )
{
$return[] = array(
'icon' => 'check',
'title' => 'finish',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$row['app_id']}" )->csrf(),
'link' => Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$row['app_id']}" )->csrf(),
'data' => array(
'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->get( 'convert_finish_confirm' )
'confirm' => '', 'confirmSubMessage' => Member::loggedIn()->language()->get( 'convert_finish_confirm' )
)
);
}
@@ -203,26 +234,26 @@ class _manage extends \IPS\Dispatcher\Controller
$return[] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=edit&id={$row['app_id']}" ),
'link' => Url::internal( "app=convert&module=manage&controller=manage&do=edit&id={$row['app_id']}" ),
);
}
return $return;
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
return array();
}
/* Application has been uninstalled */
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
return array();
}
};
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__convert_manage' );
\IPS\Output::i()->output .= (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack( 'menu__convert_manage' );
Output::i()->output .= (string) $table;
}
/**
@@ -234,11 +265,11 @@ class _manage extends \IPS\Dispatcher\Controller
{
if ( \IPS\IN_DEV === FALSE )
{
\IPS\Output::i()->error( 'new_sofware_not_in_dev', '1V100/1', 403 );
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 ) );
$form = new Form;
$form->add( new Text( 'classname', NULL, TRUE ) );
if ( $values = $form->values() )
{
@@ -266,24 +297,24 @@ class _manage extends \IPS\Dispatcher\Controller
$code = str_replace( array( '<#NAMESPACE#>', '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $namespace, $classname, mb_strtolower( $classname ) ), $default );
/* Check if we need to create a folder */
if( \count( $copied ) > 1 )
if( count( $copied ) > 1 )
{
$folder = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . $copied[0];
if( !file_exists( $folder ) )
{
@mkdir( $folder );
@chmod( $folder, \IPS\FOLDER_PERMISSION_NO_WRITE );
@chmod( $folder, FOLDER_PERMISSION_NO_WRITE );
}
}
/* Generate the file */
\file_put_contents( $filepath, $code );
file_put_contents( $filepath, $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
Output::i()->redirect( 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;
Output::i()->title = Member::loggedIn()->language()->addToStack( 'new_software' );
Output::i()->output = (string) $form;
}
/**
@@ -295,11 +326,11 @@ class _manage extends \IPS\Dispatcher\Controller
{
if ( \IPS\IN_DEV === FALSE )
{
\IPS\Output::i()->error( 'new_library_not_in_dev', '1V100/2', 403 );
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 ) );
$form = new Form;
$form->add( new Text( 'classname', NULL, TRUE ) );
if ( $values = $form->values() )
{
@@ -327,24 +358,24 @@ class _manage extends \IPS\Dispatcher\Controller
$code = str_replace( array( '<#NAMESPACE#>', '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $namespace, $classname, mb_strtolower( $classname ) ), $default );
/* Check if we need to create a folder */
if( \count( $copied ) > 1 )
if( count( $copied ) > 1 )
{
$folder = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . $copied[0];
if( !file_exists( $folder ) )
{
@mkdir( $folder );
@chmod( $folder, \IPS\FOLDER_PERMISSION_NO_WRITE );
@chmod( $folder, FOLDER_PERMISSION_NO_WRITE );
}
}
/* Generate the file */
\file_put_contents( $filepath, $code );
file_put_contents( $filepath, $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), 'saved' );
Output::i()->redirect( 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;
Output::i()->title = Member::loggedIn()->language()->addToStack( 'new_library' );
Output::i()->output = (string) $form;
}
/**
@@ -354,38 +385,38 @@ class _manage extends \IPS\Dispatcher\Controller
*/
public function edit()
{
if ( !isset( \IPS\Request::i()->id ) )
if ( !isset( Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V100/3' );
Output::i()->error( 'no_conversion_app', '2V100/3' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
$app = App::load( Request::i()->id );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V100/4', 404 );
Output::i()->error( 'conversion_app_not_found', '2V100/4', 404 );
}
$classname = $app->getSource( FALSE );
$form = new \IPS\Helpers\Form;
$form = new Form;
if ( $classname::getPreConversionInformation() !== NULL )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $classname::getPreConversionInformation() ), '', FALSE );
$form->addMessage( 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 ) );
$form->add( new Text( 'db_host', $app->db_host, FALSE ) );
$form->add( new Number( 'db_port', $app->db_port, FALSE, array( 'max' => 65535, 'min' => 1 ) ) );
$form->add( new Text( 'db_db', $app->db_db, FALSE ) );
$form->add( new Text( 'db_user', $app->db_user, FALSE ) );
$form->add( new Password( 'db_pass', $app->db_pass, FALSE ) );
$form->add( new Text( 'db_prefix', $app->db_prefix, FALSE ) );
$form->add( new Text( 'db_charset', $app->db_charset, FALSE ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'edit_conversion' );
Output::i()->title = Member::loggedIn()->language()->addToStack( 'edit_conversion' );
if ( $values = $form->values() )
{
@@ -406,17 +437,17 @@ class _manage extends \IPS\Dispatcher\Controller
$connectionSettings['sql_utf8mb4'] = TRUE;
}
$db = \IPS\Db::i( 'convertertest', $connectionSettings );
$db = Db::i( 'convertertest', $connectionSettings );
/* Now test the charset */
if ( $values['db_charset'] AND !\in_array( $values['db_charset'], array( 'utf8', 'utf8mb4' ) ) )
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 );
$charsets = Software::getDatabaseCharsets( $db );
if ( !\in_array( mb_strtolower( $values['db_charset'] ), $charsets ) )
if ( !in_array( mb_strtolower( $values['db_charset'] ), $charsets ) )
{
throw new \InvalidArgumentException( 'invalid_charset' );
throw new InvalidArgumentException( 'invalid_charset' );
}
$db->set_charset( $values['db_charset'] );
@@ -430,21 +461,21 @@ class _manage extends \IPS\Dispatcher\Controller
if( !$db->checkForTable( $testAgainst['table'] ) )
{
throw new \InvalidArgumentException( 'invalid_prefix' );
throw new InvalidArgumentException( 'invalid_prefix' );
}
}
catch( \InvalidArgumentException $e )
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;
$form->error = Member::loggedIn()->language()->addToStack('convert_cant_connect_db_charset');
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;
$form->error = Member::loggedIn()->language()->addToStack('convert_cant_connect_db_prefix');
Output::i()->output = $form;
return;
}
else
@@ -452,10 +483,10 @@ class _manage extends \IPS\Dispatcher\Controller
throw $e;
}
}
catch( \Exception $e )
catch( Exception $e )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('convert_cant_connect_db');
\IPS\Output::i()->output = $form;
$form->error = Member::loggedIn()->language()->addToStack('convert_cant_connect_db');
Output::i()->output = $form;
return;
}
@@ -480,9 +511,9 @@ class _manage extends \IPS\Dispatcher\Controller
$child->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
Output::i()->redirect( Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
}
\IPS\Output::i()->output = $form;
Output::i()->output = $form;
}
}