Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -109,15 +109,52 @@ class _dashboard extends \IPS\Dispatcher\Controller
/* Warnings */
$warnings = array();
$dir = @dir( '/' );
if ( $dir instanceof \Directory )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('open_basedir_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('open_basedir_desc'),
);
}
$functionsToDisable = array( 'exec', 'system', 'passhtru', 'pcntl_exec', 'popen', 'proc_open', 'shell_exec' );
$showingFunctionWarning = FALSE;
foreach ( $functionsToDisable as $k => $function )
{
if ( function_exists( $function ) )
{
$showingFunctionWarning = TRUE;
}
else
{
unset( $functionsToDisable[ $k ] );
}
}
if ( $showingFunctionWarning )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('disable_functions_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('disable_functions_desc', FALSE, array( 'sprintf' => array( implode( ', ', $functionsToDisable ) ) ) ),
);
}
if ( !\IPS\IN_DEV and ini_get( 'display_errors' ) )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('display_errors_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('display_errors_desc'),
'risk' => "medium",
);
}
$tasks = \IPS\Db::i()->select( '*', 'core_tasks', 'lock_count >= 3' );
$keys = array();
foreach( $tasks as $task )
{
$keys[] = $task['key'];
}
if ( !empty( $keys ) )
{
$warnings[] = array(
@@ -143,6 +180,50 @@ class _dashboard extends \IPS\Dispatcher\Controller
);
}
if( !\IPS\Settings::i()->orig_tables_checked )
{
/* Check if we have any orig_* tables */
$tables = \IPS\Db::i()->getTables( 'orig_' . \IPS\Db::i()->prefix );
/* If we don't have any, we're good. Set a flag so we don't check this every dashboard load. */
if( !count( $tables ) )
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => 1 ), array( 'conf_key=?', 'orig_tables_checked' ) );
unset( \IPS\Data\Store::i()->settings );
}
else
{
/* Determine if the background queue task has already been launched */
try
{
\IPS\Db::i()->select( '*', 'core_queue', array( "`key`=?", 'CleanupOrigTables' ) )->first();
$inProgress = TRUE;
}
catch( \UnderflowException $e )
{
$inProgress = FALSE;
}
/* Launch the task if we clicked to do so */
if( !$inProgress AND isset( \IPS\Request::i()->cleanupOrigTables ) AND \IPS\Request::i()->cleanupOrigTables )
{
\IPS\Task::queue( 'core', 'CleanupOrigTables', array( 'originalCount' => count( $tables ) ), 5 );
$inProgress = TRUE;
\IPS\Output::i()->inlineMessage = \IPS\Member::loggedIn()->language()->addToStack('orig_tables_rebuilding');
}
if( !$inProgress )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('block_core_OrigTables'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('orig_cleanup_suggested')
);
}
}
}
/* Check Tasks */
try
{
@@ -155,21 +236,21 @@ class _dashboard extends \IPS\Dispatcher\Controller
if( \IPS\Settings::i()->task_use_cron == 'cron' )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_broken' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_cron_broken_desc' )
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasksrun_broken' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( \IPS\CIC ? 'dashboard_tasks_cron_broken_desc_cic' : 'dashboard_tasks_cron_broken_desc' )
);
}
elseif( \IPS\Settings::i()->task_use_cron == 'web' )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_broken' ),
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasksrun_broken' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_web_broken_desc' )
);
}
else
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_broken' ),
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasksrun_broken' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_tasks_not_enough_desc' )
);
}
@@ -184,8 +265,10 @@ class _dashboard extends \IPS\Dispatcher\Controller
'description' => \IPS\Member::loggedIn()->language()->addToStack('dasbhoard_tasks_site_offline_desc')
);
}
/* If there have been more than 10 datastore failurs in the last hour, or if an instant test fails, show a message */
/* If there have been more than 10 datastore failures in the last hour, or if an instant test fails, show a message */
if( !\IPS\Data\Store::i()->test() OR \IPS\Db::i()->select( 'COUNT(*)', 'core_log', array( '`category`=? AND `time`>?', 'datastore', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ) )->first() >= 10 )
{
/* Have we just recently updated the configuration? If so, ignore this warning for 24 hours */
@@ -197,13 +280,92 @@ class _dashboard extends \IPS\Dispatcher\Controller
);
}
}
if ( \IPS\CIC )
{
try
{
$cicEmails = \IPS\Data\Cache::i()->getWithExpire( 'cicEmailUsage', TRUE );
}
catch( \OutOfRangeException $e )
{
preg_match( '/^\/var\/www\/html\/(.+?)(?:\/|$)/i', \IPS\ROOT_PATH, $matches );
try
{
$cicEmails = \IPS\Http\Url::external( "http://ips-cic-email.invisioncic.com/blocked.php?account={$matches[1]}" )->request()->get()->decodeJson();
}
catch( \Exception $e )
{
/* Request failed, so assume okay and try again in an hour */
$cicEmails = array( 'status' => 'OKAY', 'time' => time() );
}
\IPS\Data\Cache::i()->storeWithExpire( 'cicEmailUsage', $cicEmails, \IPS\DateTime::create()->add( new \DateInterval( 'PT1H' ) ), true );
}
if ( isset( $cicEmails['status'] ) AND $cicEmails['status'] == 'BLOCKED' )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_cic_email_quota' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_cic_email_quota_desc' )
);
}
}
/* Cache Check */
if ( \IPS\CACHE_METHOD AND \IPS\CACHE_METHOD != 'None' AND \IPS\Data\Cache::i() instanceof \IPS\Data\Cache\None )
{
$warnings[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_invalid_cachesetup' ),
'description' => \IPS\Member::loggedIn()->language()->addToStack( 'dashboard_invalid_cachesetup_desc' )
);
}
/* Get new core update available data */
$update = \IPS\Application::load( 'core' )->availableUpgrade( TRUE );
$update = \IPS\Application::load( 'core' )->availableUpgrade( TRUE );
/* Determine if there are any new features to show */
$latestFeatureId = \IPS\Application::load( 'core' )->newFeature();
$features = array();
try
{
$latestSeenFeature = \IPS\Db::i()->select( 'feature_id', 'core_members_feature_seen', array( 'member_id=?', \IPS\Member::loggedIn()->member_id ) )->first();
}
catch( \UnderflowException $e )
{
$latestSeenFeature = 0;
}
if( $latestFeatureId AND ( !$latestSeenFeature OR $latestSeenFeature < $latestFeatureId ) )
{
try
{
$features = json_encode( \IPS\Http\Url::ips('newFeatures')->setQueryString( array( 'since' => (int) $latestSeenFeature ) )->request()->get()->decodeJson() );
/* Reset our last feature ID information so this doesn't show on subsequent page loads */
\IPS\Db::i()->replace( 'core_members_feature_seen', array( 'member_id' => \IPS\Member::loggedIn()->member_id, 'feature_id' => $latestFeatureId ) );
}
catch( \RuntimeException $e ){}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('dashboard');
\IPS\Output::i()->customHeader = \IPS\Theme::i()->getTemplate( 'dashboard' )->dashboardHeader( $info, $blocks );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'dashboard' )->dashboard( $update, $toShow, $blocks, $info, $bulletins, $warnings );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'dashboard' )->dashboard( $update, $features, $toShow, $blocks, $info, $bulletins, $warnings );
}
/**
* Reset the latest features we've seen so that we can see them again
*
* @return void
*/
public function whatsNew()
{
\IPS\Db::i()->delete( 'core_members_feature_seen', array( 'member_id=?', \IPS\Member::loggedIn()->member_id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=dashboard" ) );
}
/**
@@ -234,9 +396,12 @@ class _dashboard extends \IPS\Dispatcher\Controller
$blocks[ \IPS\Member::loggedIn()->member_id ] = $toShow;
\IPS\Settings::i()->acp_dashboard_blocks = json_encode( $blocks );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Settings::i()->acp_dashboard_blocks ), array( 'conf_key=?', 'acp_dashboard_blocks' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
}
/* Upon initial upgrade to 4.3 the key won't exist, so apply to bg queue by default */
elseif( !array_key_exists( 'collapsed', $toShow ) )
{
$toShow['collapsed'] = array( 'core_BackgroundQueue' );
}
if( $return === TRUE )
@@ -292,20 +457,17 @@ class _dashboard extends \IPS\Dispatcher\Controller
$saveBlocks = \IPS\Request::i()->blocks;
if( !isset( $saveBlocks['main'] ) )
foreach( array( 'main', 'side', 'collapsed' ) as $saveKey )
{
$saveBlocks['main'] = array();
}
if( !isset( $saveBlocks['side'] ) )
{
$saveBlocks['side'] = array();
if( !isset( $saveBlocks[ $saveKey ] ) )
{
$saveBlocks[ $saveKey ] = array();
}
}
$blocks[ \IPS\Member::loggedIn()->member_id ] = $saveBlocks;
\IPS\Settings::i()->acp_dashboard_blocks = json_encode( $blocks );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Settings::i()->acp_dashboard_blocks ), array( 'conf_key=?', 'acp_dashboard_blocks' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'acp_dashboard_blocks' => json_encode( $blocks ) ) );
if( \IPS\Request::i()->isAjax() )
{
@@ -72,16 +72,21 @@ class _files extends \IPS\Dispatcher\Controller
}*/
$table = new \IPS\Helpers\Table\Db( 'core_attachments', \IPS\Http\Url::internal( 'app=core&module=overview&controller=files' ) );
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'dashboard' ), 'fileTable' );
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'dashboard' ), 'fileTableRows' );
$table->filters = array(
'images' => "attach_is_image=1",
'files' => "attach_is_image=0",
);
$table->include = array( 'attach_file', 'attach_filesize', 'attach_date', 'attach_member_id' );
$table->include = array( 'attach_id', 'attach_file', 'attach_filesize', 'attach_date', 'attach_member_id' );
$table->rowClasses = array( 'attach_file' => array( 'ipsTable_wrap' ) );
if ( $table->filter !== 'images' )
{
$table->include[] = 'attach_hits';
}
$table->noSort = array( 'attach_type' );
$table->noSort = array( 'attach_type', 'attach_id' );
$table->quickSearch = 'attach_file';
$table->parsers = array(
'attach_file' => function( $val, $row ) use ( $table )
@@ -94,7 +99,7 @@ class _files extends \IPS\Dispatcher\Controller
else
{
$url = \IPS\Http\Url::external( \IPS\Settings::i()->base_url . "applications/core/interface/file/attachment.php" )->setQueryString( 'id', $row['attach_id'] )->makeSafeForAcp( FALSE );
$val = htmlentities( $val, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
$val = htmlentities( $val, ENT_DISALLOWED, 'UTF-8', FALSE );
return "<a href='{$url}' target='_blank'>{$val}</a>";
}
},
@@ -133,7 +138,7 @@ class _files extends \IPS\Dispatcher\Controller
}
else
{
return "<a href='" . \IPS\Http\Url::internal( 'app=core&module=members&controller=members&do=edit&id=' . $val ) . "'>" . htmlentities( \IPS\Member::load( $val )->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) . '</a>';
return "<a href='" . \IPS\Http\Url::internal( 'app=core&module=members&controller=members&do=edit&id=' . $val ) . "'>" . htmlentities( \IPS\Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE ) . '</a>';
}
}
@@ -168,7 +173,9 @@ class _files extends \IPS\Dispatcher\Controller
return $buttons;
};
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'dashboard/files.css', 'core', 'admin' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_files.js', 'core', 'admin' ) );
\IPS\Output::i()->output = (string) $table;
}
@@ -393,8 +400,7 @@ class _files extends \IPS\Dispatcher\Controller
\IPS\Task::queue( 'core', 'DeleteMovedFiles', array( 'delete' => true ), 5, array( 'delete' ) ); /* We use a key in the data array just to trigger the code that deletes duplicate tasks */
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $values ) ), array( 'conf_key=?', 'upload_settings' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'upload_settings' => json_encode( $values ) ) );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
@@ -558,7 +564,7 @@ class _files extends \IPS\Dispatcher\Controller
$toggles = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/system/File' ) as $f )
{
if ( !$f->isDot() and mb_substr( $f, -4 ) === '.php' and $f != 'File.php' and $f != 'Iterator.php' )
if ( !$f->isDot() and mb_substr( $f, -4 ) === '.php' and $f != 'File.php' and $f != 'Iterator.php' and $f != 'Exception.php' )
{
$key = mb_substr( $f, 0, -4 );
@@ -566,6 +572,12 @@ class _files extends \IPS\Dispatcher\Controller
{
continue;
}
/* Hide FTP option from form unless it's already in use */
if ( ( $key === 'Ftp' AND isset( $current['method'] ) AND $current['method'] !== 'Ftp' ) OR ( $key === 'Ftp' AND !isset( $current['method'] ) ) )
{
continue;
}
$handlers[ $key ] = 'filehandler__' . $key;
@@ -713,8 +725,7 @@ class _files extends \IPS\Dispatcher\Controller
}
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $settings ) ), array( 'conf_key=?', 'upload_settings' ) );
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'upload_settings' => json_encode( $settings ) ) );
if ( $values['filestorage_move'] )
{
@@ -853,4 +864,37 @@ class _files extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=files" ), 'orphaned_files_tasks_added' );
}
/**
* Multimod
*
* @return void
*/
protected function multimod()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'files_delete' );
\IPS\Session::i()->csrfCheck();
if( !isset( \IPS\Request::i()->multimod ) OR !is_array( \IPS\Request::i()->multimod ) OR !count( \IPS\Request::i()->multimod ) )
{
\IPS\Output::i()->error( 'nothing_mm_selected', '2C158/6', 403, '' );
}
foreach ( \IPS\Db::i()->select( '*', 'core_attachments', \IPS\Db::i()->in( 'attach_id', array_keys( \IPS\Request::i()->multimod ) ) ) as $attachment )
{
\IPS\File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
if( $attachment['attach_thumb_location'] )
{
\IPS\File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
}
\IPS\Session::i()->log( 'acplogs__file_deleted', array( $attachment['attach_file'] => FALSE ) );
}
\IPS\Db::i()->delete( 'core_attachments', \IPS\Db::i()->in( 'attach_id', array_keys( \IPS\Request::i()->multimod ) ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=files" ), 'deleted' );
}
}
@@ -1,403 +0,0 @@
<?php
/**
* @brief Security Settings
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 11 Jun 2013
*/
namespace IPS\core\modules\admin\overview;
/* 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;
}
/**
* Security Settings
*/
class _security extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'security_manage' );
parent::execute();
}
/**
* Security Center
*
* @return void
*/
protected function manage()
{
/* Init */
$content = array();
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=overview&controller=security&do=settings' ),
'title' => 'security_settings',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('security_settings') )
),
'list_admins' => array(
'icon' => 'key',
'link' => \IPS\Http\Url::internal( 'app=core&module=members&controller=members&filter=members_filter_administrators' ),
'title' => 'security_list_admins',
),
);
/* open_basedir */
$dir = @dir( '/' );
if ( $dir instanceof Directory )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('open_basedir_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('open_basedir_desc'),
'risk' => "high",
);
}
/* Htaccess Protection */
$needUploads = FALSE;
foreach( \IPS\Db::i()->select( '*', 'core_file_storage', array( 'method=?', 'FileSystem' ) ) as $uploads )
{
$uploads = json_decode( $uploads['configuration'], TRUE );
if( isset( $uploads['dir'] ) )
{
$uploads['dir'] = str_replace( '{root}', \IPS\ROOT_PATH, $uploads['dir'] );
if( !is_file( $uploads['dir'] . '/.htaccess' ) )
{
$needUploads = TRUE;
}
}
}
$storeSettings = json_decode( \IPS\STORE_CONFIG, TRUE );
if ( ( $needUploads OR
( \IPS\STORE_METHOD == 'FileSystem' AND !is_file( str_replace( '{root}', \IPS\ROOT_PATH, $storeSettings['path'] ) . '/.htaccess' ) ) ) AND !\IPS\NO_WRITES )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('htaccess_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('htaccess_desc'),
'risk' => "high",
'button' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('security_run_tool'), 'action' => "app=core&module=overview&controller=security&do=htaccess" ),
);
}
/* Configuration File */
if ( is_writable( \IPS\ROOT_PATH . '/conf_global.php' ) AND !\IPS\NO_WRITES )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('conf_writeable_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('conf_writeable_desc'),
'risk' => "high",
'button' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('security_run_tool'), 'action' => "app=core&module=overview&controller=security&do=conf" ),
);
}
/* Disabled PHP Functions */
$functionsToDisable = array( 'exec', 'system', 'passhtru', 'pcntl_exec', 'popen', 'proc_open', 'shell_exec' );
$showingFunctionWarning = FALSE;
foreach ( $functionsToDisable as $k => $function )
{
if ( function_exists( $function ) )
{
$showingFunctionWarning = TRUE;
}
else
{
unset( $functionsToDisable[ $k ] );
}
}
if ( $showingFunctionWarning )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('disable_functions_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('disable_functions_desc', FALSE, array( 'sprintf' => array( implode( ', ', $functionsToDisable ) ) ) ),
'risk' => "high",
);
}
/* Display Errors */
if ( ini_get( 'display_errors' ) )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('display_errors_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('display_errors_desc'),
'risk' => "medium",
);
}
/* ACP Directory Name */
if ( \IPS\CP_DIRECTORY == 'admin' and !\IPS\CIC )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('rename_admin_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('rename_admin_desc'),
'risk' => "low",
'button' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('security_learn_more'), 'action' => "app=core&module=overview&controller=security&do=renameAdmin" ),
);
}
/* ACP Password Protection */
if ( ! is_file( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/.htaccess' ) AND !\IPS\NO_WRITES AND !\IPS\CIC )
{
$content[] = array(
'title' => \IPS\Member::loggedIn()->language()->addToStack('admin_pass_title'),
'description' => \IPS\Member::loggedIn()->language()->addToStack('admin_pass_desc'),
'risk' => "low",
'button' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack('security_run_tool'), 'action' => "app=core&module=overview&controller=security&do=acpHtaccess" ),
);
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('security_center');
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/security.css', 'core', 'admin' ) );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'overview' )->security( $content );
}
/**
* Security Settings
*
* @return void
*/
protected function settings()
{
$form = new \IPS\Helpers\Form;
/* IP Addresses */
$form->addHeader( 'security_header_ips' );
if ( !\IPS\CIC )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'xforward_matching', \IPS\Settings::i()->xforward_matching, FALSE ) );
}
$form->add( new \IPS\Helpers\Form\YesNo( 'match_ipaddress', \IPS\Settings::i()->match_ipaddress, FALSE ) );
if( \IPS\BYPASS_ACP_IP_CHECK === TRUE )
{
\IPS\Member::loggedIn()->language()->words['match_ipaddress_warning'] = \IPS\Member::loggedIn()->language()->addToStack('ip_override_warn');
}
/* Account Security */
$form->addHeader( 'security_header_accounts' );
$form->add( new \IPS\Helpers\Form\YesNo( 'device_management', \IPS\Settings::i()->device_management, FALSE ) );
/* Password Strength */
$form->addHeader( 'security_header_passwords' );
$form->add( new \IPS\Helpers\Form\YesNo( 'password_strength_meter', \IPS\Settings::i()->password_strength_meter, FALSE, array( 'togglesOn' => array( 'password_strength_meter_enforce' ) ), NULL, NULL, NULL, 'password_strength_meter' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'password_strength_meter_enforce', \IPS\Settings::i()->password_strength_meter_enforce, FALSE, array( 'togglesOn' => array( 'password_strength_option' ) ), NULL, NULL, NULL, 'password_strength_meter_enforce' ) );
$strengthOptions = array(
'3' => 'strength_3',
'4' => 'strength_4',
'5' => 'strength_5',
);
$form->add( new \IPS\Helpers\Form\Radio( 'password_strength_option', \IPS\Settings::i()->password_strength_option, FALSE, array( 'options' => $strengthOptions ), NULL, NULL, NULL, 'password_strength_option' ) );
/* ACP Link */
$form->addHeader( 'security_header_admincp' );
$form->add( new \IPS\Helpers\Form\YesNo( 'security_remove_acp_link', !\IPS\Settings::i()->security_remove_acp_link, FALSE ) );
/* Handle Submissions */
if ( $values = $form->values() )
{
$values['security_remove_acp_link'] = $values['security_remove_acp_link'] ? FALSE : TRUE;
/* Disabling the password strength meter should also disable enforcing a strength */
$values['password_strength_meter_enforce'] = $values['password_strength_meter'] ? $values['password_strength_meter_enforce'] : FALSE;
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__security_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=security" ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('security_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'storage_settings', $form );
}
/**
* Change conf global permissions
*
* @return void
*/
protected function conf()
{
/* INIT */
$done = FALSE;
/* Try... */
if ( \IPS\NO_WRITES or !@chmod( \IPS\ROOT_PATH . '/conf_global.php', 0444 ) )
{
\IPS\Output::i()->error( 'conf_not_altered', '2C258/2', 500, '' );
}
/* All Done */
\IPS\Session::i()->log( 'acplogs__security_conf' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=security" ), 'conf_altered' );
}
/**
* Add htaccess files to writeable directory
*
* @return void
*/
protected function htaccess()
{
if ( \IPS\NO_WRITES )
{
\IPS\Output::i()->error( 'no_writes', '1C258/7', 403, '' );
}
/* INIT */
$errors = array();
$deny = <<<EOF
#<ipb-protection>
<Files ~ "^.*\.(php|cgi|pl|php3|php4|php5|php6|phtml|shtml|([a-z0-9]{32}))$">
Order allow,deny
Deny from all
</Files>
#</ipb-protection>
EOF;
foreach( \IPS\Db::i()->select( '*', 'core_file_storage', array( 'method=?', 'FileSystem' ) ) as $uploads )
{
$uploads = json_decode( $uploads['configuration'], TRUE );
if( isset( $uploads['dir'] ) )
{
$uploads['dir'] = str_replace( '{root}', \IPS\ROOT_PATH, $uploads['dir'] );
if( !is_file( $uploads['dir'] . '/.htaccess' ) )
{
if ( !@\file_put_contents( $uploads['dir'] . '/.htaccess', $deny ) )
{
$errors[] = $uploads['dir'];
}
}
}
}
if ( isset( $uploadSettings['FileSystem']['dir'] ) )
{
$directory = $uploadSettings['FileSystem']['dir'];
if ( !@\file_put_contents( $directory . '/.htaccess', $deny ) )
{
$errors[] = $directory;
}
}
$storeSettings = json_decode( \IPS\STORE_CONFIG, TRUE );
if ( \IPS\STORE_METHOD == 'FileSystem' )
{
$directory = str_replace( '{root}', \IPS\ROOT_PATH, $storeSettings['path'] );
if ( !@\file_put_contents( $directory . '/.htaccess', $deny ) )
{
$errors[] = $directory;
}
}
if( count( $errors ) )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'htaccess_not_written', FALSE, array( 'sprintf' => \IPS\Member::loggedIn()->language()->formatList( $errors ) ) ), '2C258/1', 403, '', array(), $deny );
}
/* All Done */
\IPS\Session::i()->log( 'acplogs__security_htaccess_writeable' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=security" ), 'htaccess_written' );
}
/**
* Rename ACP directory
*
* @return void
*/
protected function renameAdmin()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('rename_admin_title');
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Output::i()->title );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'overview' )->securityRenameAdmin();
}
/**
* ACP Htaccess Protection
*
* @return void
*/
protected function acpHtaccess()
{
if ( \IPS\NO_WRITES )
{
\IPS\Output::i()->error( 'no_writes', '1C258/6', 403, '' );
}
if ( !is_writable( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY ) )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'err_not_writable', FALSE, array( 'sprintf' => array( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY ) ) ), '1C258/5', 403, '' );
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'htaccess_username', NULL, TRUE ) );
$form->add( new \IPS\Helpers\Form\Password( 'htaccess_password', NULL, TRUE ) );
if ( $values = $form->values() )
{
$done = FALSE;
/* See this for an explanation why ErrorDocument is needed: http://www.myriadinteractive.com/blog/view/id/29/conflict-between-apache-url-rewriting-and-basic-authentication */
$htaccess_auth = "ErrorDocument 401 \"Unauthorized Access\"\n"
. "AuthType Basic\n"
. "AuthName \"Invision Community AdminCP\"\n"
. 'AuthUserFile "' . \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . "/.htpasswd\"\n"
. "Require valid-user\n";
$htaccess_pw = $values['htaccess_username'] . ":" .
( ( mb_strtoupper( mb_substr( PHP_OS, 0, 3 ) ) === 'WIN' ) ? $values['htaccess_password'] : crypt( $values['htaccess_password'], base64_encode( $values['htaccess_password'] ) ) );
if ( $FH = @\fopen( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/.htpasswd', 'w' ) )
{
\fwrite( $FH, $htaccess_pw );
\fclose( $FH );
$FF = @\fopen( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/.htaccess', 'w' );
\fwrite( $FF, $htaccess_auth );
\fclose( $FF );
$done = TRUE;
\IPS\Session::i()->log( 'acplogs__security_acp_password' );
\IPS\IPS::resyncIPSCloud('Added htaccess protection to ACP');
}
/* All Done */
if ( $done )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=security" ), 'admin_pass_written' );
}
else
{
\IPS\Output::i()->error( 'admin_pass_not_written', '1C258/3', 403, '' );
}
}
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'admin_pass_warning', 'warning' );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('admin_pass_title');
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Output::i()->title, $form );
}
}