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

+193 -159
View File
@@ -11,33 +11,66 @@
namespace IPS\core\modules\admin\staff;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Data\Store;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Interval;
use IPS\Helpers\Form\Member as FormMember;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Table\Db as TableDb;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Group;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function in_array;
use function intval;
use function is_array;
use const IPS\CIC;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
use const IPS\Helpers\Table\SEARCH_MEMBER;
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;
}
/**
* Admin CP Restrictions
*/
class _admin extends \IPS\Dispatcher\Controller
class admin extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
Dispatcher::i()->checkAcpPermission( 'restrictions_manage' );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'members/restrictions.css', 'core', 'admin' ) );
return parent::execute();
parent::execute();
}
/**
@@ -45,41 +78,41 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_permission_rows', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
$table = new TableDb( 'core_admin_permission_rows', Url::internal( 'app=core&module=staff&controller=admin' ) );
/* Columns */
$table->selects = array( 'row_perm_cache', 'row_updated', 'row_id', 'row_id_type' );
$table->langPrefix = 'acprestrictions_';
$table->joins = array(
array( 'select' => "IF(core_admin_permission_rows.row_id_type= 'group', w.word_custom, m.name) as name", 'from' => array( 'core_members', 'm' ), 'where' => "m.member_id=core_admin_permission_rows.row_id AND core_admin_permission_rows.row_id_type='member'" ),
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_admin_permission_rows.row_id ) AND core_admin_permission_rows.row_id_type='group' AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=CONCAT( 'core_group_', core_admin_permission_rows.row_id ) AND core_admin_permission_rows.row_id_type='group' AND w.lang_id=" . Member::loggedIn()->language()->id )
);
$table->include = array( 'name', 'row_updated', 'row_perm_cache' );
$table->parsers = array(
'name' => function( $val, $row )
{
$return = \IPS\Theme::i()->getTemplate( 'global' )->shortMessage( $row['row_id_type'], array( 'ipsBadge', 'ipsBadge_neutral', 'ipsBadge_label' ) );
$return = Theme::i()->getTemplate( 'global' )->shortMessage( $row['row_id_type'], array( 'ipsBadge', 'ipsBadge--neutral', 'ipsBadge--label' ) );
try
{
$name = empty( $row['name'] ) ? \IPS\Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['row_id_type'] === 'group' ) ? \IPS\Member\Group::load( $row['row_id'] )->formattedName : $name;
$name = empty( $row['name'] ) ? Member::loggedIn()->language()->addToStack('deleted_member') : htmlentities( $row['name'], ENT_DISALLOWED, 'UTF-8', FALSE );
$return .= ( $row['row_id_type'] === 'group' ) ? Group::load( $row['row_id'] )->formattedName : $name;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$return .= \IPS\Member::loggedIn()->language()->addToStack('deleted_group');
$return .= Member::loggedIn()->language()->addToStack('deleted_group');
}
return $return;
},
'row_updated' => function( $val )
{
return ( $val ) ? \IPS\DateTime::ts( $val )->localeDate() : \IPS\Member::loggedIn()->language()->addToStack('never');
return ( $val ) ? DateTime::ts( $val )->localeDate() : Member::loggedIn()->language()->addToStack('never');
},
'row_perm_cache' => function( $val )
{
return \IPS\Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
return Theme::i()->getTemplate( 'members' )->restrictionsLabel( $val );
}
);
$table->mainColumn = 'name';
@@ -91,15 +124,15 @@ class _admin extends \IPS\Dispatcher\Controller
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) or \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) or Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'add' => array(
'primary' => TRUE,
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=add' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=add' ),
'title' => 'acprestrictions_add',
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_add') )
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('acprestrictions_add') )
),
);
}
@@ -110,13 +143,13 @@ class _admin extends \IPS\Dispatcher\Controller
$buttons = array(
'edit' => array(
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=admin&do=edit&id={$row['row_id']}&type={$row['row_id_type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=admin&do=edit&id={$row['row_id']}&type={$row['row_id_type']}" ),
'title' => 'edit',
'class' => '',
),
'delete' => array(
'icon' => 'times-circle',
'link' => \IPS\Http\Url::internal( "app=core&module=staff&controller=admin&do=delete&id={$row['row_id']}&type={$row['row_id_type']}" ),
'link' => Url::internal( "app=core&module=staff&controller=admin&do=delete&id={$row['row_id']}&type={$row['row_id_type']}" ),
'title' => 'delete',
'data' => array( 'delete' => '' ),
)
@@ -124,17 +157,17 @@ class _admin extends \IPS\Dispatcher\Controller
if ( $row['row_id_type'] === 'member' )
{
if ( $row['row_id'] == \IPS\Member::loggedIn()->member_id )
if ( $row['row_id'] == Member::loggedIn()->member_id )
{
return array();
}
else
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_member' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_member' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_member' ) )
{
unset( $buttons['delete'] );
}
@@ -142,17 +175,17 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
if ( \IPS\Member::loggedIn()->inGroup( $row['row_id'] ) )
if ( Member::loggedIn()->inGroup( $row['row_id'] ) )
{
return array();
}
else
{
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_edit_group' ) )
{
unset( $buttons['edit'] );
}
if ( !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_group' ) )
if ( !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_delete_group' ) )
{
unset( $buttons['delete'] );
}
@@ -163,36 +196,36 @@ class _admin extends \IPS\Dispatcher\Controller
};
/* Buttons for logs */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs' ) )
{
\IPS\Output::i()->sidebar['actions']['actionLogs'] = array(
Output::i()->sidebar['actions']['actionLogs'] = array(
'title' => 'acplogs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ),
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs' ) )
{
\IPS\Output::i()->sidebar['actions']['loginLogs'] = array(
Output::i()->sidebar['actions']['loginLogs'] = array(
'title' => 'adminloginlogs',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ),
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ),
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'members' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'members' ) )
{
\IPS\Output::i()->sidebar['actions']['list_admins'] = array(
Output::i()->sidebar['actions']['list_admins'] = array(
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=members&controller=members&filter=members_filter_administrators' ),
'link' => Url::internal( 'app=core&module=members&controller=members&filter=members_filter_administrators' ),
'title' => 'security_list_admins',
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions');
\IPS\Output::i()->output = (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack('acprestrictions');
Output::i()->output = (string) $table;
}
/**
@@ -200,33 +233,33 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function add()
protected function add() : void
{
$form = new \IPS\Helpers\Form();
$form = new Form();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) and Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Radio( 'acprestrictions_type', NULL, TRUE, array( 'options' => array( 'group' => 'group', 'member' => 'member' ), 'toggles' => array( 'group' => array( 'acprestrictions_group' ), 'member' => array( 'acprestrictions_member' ) ) ) ) );
$form->add( new Radio( 'acprestrictions_type', NULL, TRUE, array( 'options' => array( 'group' => 'group', 'member' => 'member' ), 'toggles' => array( 'group' => array( 'acprestrictions_group' ), 'member' => array( 'acprestrictions_member' ) ) ) ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
{
$form->add( new \IPS\Helpers\Form\Select( 'acprestrictions_group', NULL, FALSE, array( 'options' => \IPS\Member\Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'acprestrictions_group' ) );
$form->add( new Select( 'acprestrictions_group', NULL, FALSE, array( 'options' => Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'acprestrictions_group' ) );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_group' ) )
{
$form->add( new \IPS\Helpers\Form\Member( 'acprestrictions_member', NULL, ( \IPS\Request::i()->acprestrictions_type === 'member' ), array( 'multiple' => 1 ), NULL, NULL, NULL, 'acprestrictions_member' ) );
$form->add( new FormMember( 'acprestrictions_member', NULL, ( Request::i()->acprestrictions_type === 'member' ), array( 'multiple' => 1 ), NULL, NULL, NULL, 'acprestrictions_member' ) );
}
if ( $values = $form->values() )
{
$rowId = NULL;
if ( $values['acprestrictions_type'] === 'group' or !\IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
if ( $values['acprestrictions_type'] === 'group' or !Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_add_member' ) )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_group' );
if ( \IPS\Member::loggedIn()->inGroup( $values['acprestrictions_group'] ) )
Dispatcher::i()->checkAcpPermission( 'restrictions_add_group' );
if ( Member::loggedIn()->inGroup( $values['acprestrictions_group'] ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
$form->error = Member::loggedIn()->language()->addToStack('acprestrictions_noself');
}
else
{
@@ -235,10 +268,10 @@ class _admin extends \IPS\Dispatcher\Controller
}
elseif ( $values['acprestrictions_member'] )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_add_member' );
if ( $values['acprestrictions_member']->member_id === \IPS\Member::loggedIn()->member_id )
Dispatcher::i()->checkAcpPermission( 'restrictions_add_member' );
if ( $values['acprestrictions_member']->member_id === Member::loggedIn()->member_id )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_noself');
$form->error = Member::loggedIn()->language()->addToStack('acprestrictions_noself');
}
else
{
@@ -248,9 +281,9 @@ class _admin extends \IPS\Dispatcher\Controller
if ( $rowId !== NULL )
{
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", $rowId, $values['acprestrictions_type'] ) );
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", $rowId, $values['acprestrictions_type'] ) );
if ( !\count( $current ) )
if ( !count( $current ) )
{
$current = array(
'row_id' => $rowId,
@@ -258,7 +291,7 @@ class _admin extends \IPS\Dispatcher\Controller
'row_perm_cache' => '*',
'row_updated' => time()
);
\IPS\Db::i()->insert( 'core_admin_permission_rows', $current );
Db::i()->insert( 'core_admin_permission_rows', $current );
if( $values['acprestrictions_type'] == 'group' )
{
@@ -269,21 +302,21 @@ class _admin extends \IPS\Dispatcher\Controller
$logValue = array( $values['acprestrictions_member']->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__acpr_created', $logValue );
Session::i()->log( 'acplog__acpr_created', $logValue );
}
else
{
$current = $current->first();
}
unset( \IPS\Data\Store::i()->administrators );
unset( Store::i()->administrators );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=staff&controller=admin" ) );
Output::i()->redirect( Url::internal( "app=core&module=staff&controller=admin" ) );
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acprestrictions_add');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'acprestrictions_add', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('acprestrictions_add');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'acprestrictions_add', $form, FALSE );
}
/**
@@ -292,41 +325,41 @@ class _admin extends \IPS\Dispatcher\Controller
* @csrfChecked Uses form helper 7 Oct 2019
* @return void
*/
protected function edit()
protected function edit() : void
{
try
{
/* Get record */
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2C113/1', 404, '' );
Output::i()->error( 'node_error', '2C113/1', 404, '' );
}
/* Check permissions */
if ( $current['row_id_type'] === 'member' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_edit_member' );
if ( $current['row_id'] == \IPS\Member::loggedIn()->member_id )
Dispatcher::i()->checkAcpPermission( 'restrictions_edit_member' );
if ( $current['row_id'] == Member::loggedIn()->member_id )
{
\IPS\Output::i()->error( 'acprestrictions_noself', '1C113/3', 403, '' );
Output::i()->error( 'acprestrictions_noself', '1C113/3', 403, '' );
}
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_edit_group' );
if ( $current['row_id_type'] === 'group' and \IPS\Member::loggedIn()->inGroup( $current['row_id'] ) )
Dispatcher::i()->checkAcpPermission( 'restrictions_edit_group' );
if ( $current['row_id_type'] === 'group' and Member::loggedIn()->inGroup( $current['row_id'] ) )
{
\IPS\Output::i()->error( 'acprestrictions_noself', '1C113/4', 403, '' );
Output::i()->error( 'acprestrictions_noself', '1C113/4', 403, '' );
}
}
/* Get available restrictions */
$restrictions = array();
foreach ( \IPS\Application::applications() as $app )
foreach ( Application::applications() as $app )
{
if ( !\IPS\CIC or !\in_array( "{$app->directory}", \IPS\Member::$cicBlockedAcpRestrictions ) )
if ( !CIC or !in_array( "{$app->directory}", Member::$cicBlockedAcpRestrictions ) )
{
$restrictions['applications'][ $app->directory ] = $app->id;
@@ -340,7 +373,7 @@ class _admin extends \IPS\Dispatcher\Controller
foreach ( $app->modules( 'admin' ) as $module )
{
if ( !$module->protected and ( !\IPS\CIC or !\in_array( "{$app->directory}.{$module->key}", \IPS\Member::$cicBlockedAcpRestrictions ) ) )
if ( !$module->protected and ( !CIC or !in_array( "{$app->directory}.{$module->key}", Member::$cicBlockedAcpRestrictions ) ) )
{
$restrictions['modules'][ $app->id ][ $module->key ] = $module->id;
@@ -350,7 +383,7 @@ class _admin extends \IPS\Dispatcher\Controller
{
foreach ( $items as $restrictionKey => $langKey )
{
if ( !\IPS\CIC or !\in_array( "{$app->directory}.{$module->key}.{$restrictionKey}", \IPS\Member::$cicBlockedAcpRestrictions ) )
if ( !CIC or !in_array( "{$app->directory}.{$module->key}.{$restrictionKey}", Member::$cicBlockedAcpRestrictions ) )
{
$restrictions['items'][ $module->id ][ $group ][ $restrictionKey ] = $langKey;
}
@@ -363,9 +396,9 @@ class _admin extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
\IPS\Output::i()->title = $current['row_id_type'] === 'group' ? \IPS\Member\Group::load( $current['row_id'] )->name : \IPS\Member::load( $current['row_id'] )->name;
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global' )->block( 'acprestrictions', \IPS\Theme::i()->getTemplate( 'members' )->acpRestrictions( $current['row_perm_cache'] === '*' ? '*' : json_decode( $current['row_perm_cache'], TRUE ), $restrictions, $current ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_members.js', 'core', 'admin' ) );
Output::i()->title = $current['row_id_type'] === 'group' ? Group::load( $current['row_id'] )->name : Member::load( $current['row_id'] )->name;
Output::i()->output .= Theme::i()->getTemplate( 'global' )->block( 'acprestrictions', Theme::i()->getTemplate( 'members' )->acpRestrictions( $current['row_perm_cache'] === '*' ? '*' : json_decode( $current['row_perm_cache'], TRUE ), $restrictions, $current ) );
}
/**
@@ -373,23 +406,23 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function save()
protected function save() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* Get record */
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
if ( !$current )
{
\IPS\Output::i()->error( 'node_error', '2C113/2', 404, '' );
Output::i()->error( 'node_error', '2C113/2', 404, '' );
}
$permissions = ( \IPS\Request::i()->admin_use_restrictions == 'no' ) ? '*' : json_encode( ( \is_array( \IPS\Request::i()->r ) ) ? \IPS\Request::i()->r : array() );
$permissions = ( Request::i()->admin_use_restrictions == 'no' ) ? '*' : json_encode( ( is_array( Request::i()->r ) ) ? Request::i()->r : array() );
/* Save */
\IPS\Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => $permissions, 'row_updated' => time() ), array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) );
Db::i()->update( 'core_admin_permission_rows', array( 'row_perm_cache' => $permissions, 'row_updated' => time() ), array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) );
unset( \IPS\Data\Store::i()->administrators );
unset( Store::i()->administrators );
/* Log */
if( $current['row_id_type'] == 'group' )
@@ -398,13 +431,13 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
$logValue = array( \IPS\Member::load( $current['row_id'] )->name => FALSE );
$logValue = array( Member::load( $current['row_id'] )->name => FALSE );
}
\IPS\Session::i()->log( 'acplog__acpr_edited', $logValue );
Session::i()->log( 'acplog__acpr_edited', $logValue );
/* Boink */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
}
/**
@@ -412,21 +445,21 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function delete()
protected function delete() : void
{
$current = \IPS\Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) )->first();
$current = Db::i()->select( '*', 'core_admin_permission_rows', array( "row_id=? AND row_id_type=?", intval( Request::i()->id ), Request::i()->type ) )->first();
if ( $current['row_id_type'] === 'member' )
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_delete_member' );
Dispatcher::i()->checkAcpPermission( 'restrictions_delete_member' );
}
else
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_delete_group' );
Dispatcher::i()->checkAcpPermission( 'restrictions_delete_group' );
}
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
if( $current['row_id_type'] == 'group' )
{
@@ -434,7 +467,7 @@ class _admin extends \IPS\Dispatcher\Controller
{
$name = 'core_group_' . $current['row_id'];
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$name = 'deleted_group';
}
@@ -443,7 +476,7 @@ class _admin extends \IPS\Dispatcher\Controller
}
else
{
$member = \IPS\Member::load( $current['row_id'] );
$member = Member::load( $current['row_id'] );
if( $member->member_id )
{
@@ -455,12 +488,12 @@ class _admin extends \IPS\Dispatcher\Controller
}
}
\IPS\Session::i()->log( 'acplog__acpr_deleted', $logValue );
Session::i()->log( 'acplog__acpr_deleted', $logValue );
\IPS\Db::i()->delete( 'core_admin_permission_rows', array( 'row_id=? AND row_id_type=?', \intval( \IPS\Request::i()->id ), \IPS\Request::i()->type ) );
unset ( \IPS\Data\Store::i()->administrators );
Db::i()->delete( 'core_admin_permission_rows', array( 'row_id=? AND row_id_type=?', intval( Request::i()->id ), Request::i()->type ) );
unset ( Store::i()->administrators );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ) );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ) );
}
/**
@@ -468,22 +501,22 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogs()
protected function actionLogs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs' );
Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_logs', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ) );
$table = new TableDb( 'core_admin_logs', Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ) );
$table->langPrefix = 'acplogs_';
$table->include = array( 'member_id', 'action', 'ip_address', 'ctime' );
$table->mainColumn = 'action';
$table->parsers = array(
'member_id' => function( $val, $row )
{
$member = \IPS\Member::load( $val );
$member = Member::load( $val );
if ( $member->member_id )
{
return htmlentities( \IPS\Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
return htmlentities( Member::load( $val )->name, ENT_DISALLOWED, 'UTF-8', FALSE );
}
else if ( $row['member_name'] != '' )
{
@@ -505,10 +538,10 @@ class _admin extends \IPS\Dispatcher\Controller
$params = array();
foreach ( json_decode( $row['note'], TRUE ) as $k => $v )
{
$params[] = ( $v ? \IPS\Member::loggedIn()->language()->addToStack( $k ) : $k );
$params[] = ( $v ? Member::loggedIn()->language()->addToStack( $k ) : $k );
}
return \IPS\Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
return Member::loggedIn()->language()->addToStack( $langKey, FALSE, array( 'sprintf' => $params ) );
}
else
{
@@ -517,15 +550,15 @@ class _admin extends \IPS\Dispatcher\Controller
},
'ip_address'=> function( $val )
{
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'members', 'membertools_ip' ) )
{
return "<a href='" . \IPS\Http\Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
return "<a href='" . Url::internal( "app=core&module=members&controller=ip&ip={$val}" ) . "'>{$val}</a>";
}
return $val;
},
'ctime' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
return (string) DateTime::ts( $val );
}
);
$table->sortBy = $table->sortBy ?: 'ctime';
@@ -533,16 +566,16 @@ class _admin extends \IPS\Dispatcher\Controller
/* Search */
$table->advancedSearch = array(
'member_id' => \IPS\Helpers\Table\SEARCH_MEMBER,
'ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'ctime' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'member_id' => SEARCH_MEMBER,
'ip_address' => SEARCH_CONTAINS_TEXT,
'ctime' => SEARCH_DATE_RANGE,
);
/* Custom quick search function to search unicode entities in JSON encoded data */
$table->quickSearch = function( $val )
{
$searchTerm = mb_strtolower( trim( \IPS\Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( \IPS\Request::i()->quicksearch ) ), '"' ) );
$searchTerm = mb_strtolower( trim( Request::i()->quicksearch ) );
$jsonSearchTerm = str_replace( '\\', '\\\\\\', trim( json_encode( trim( Request::i()->quicksearch ) ), '"' ) );
return array(
"(`note` LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_custom`) LIKE CONCAT( '%', ?, '%' ) OR LOWER(`word_default`) LIKE CONCAT( '%', ?, '%' ))",
@@ -553,26 +586,26 @@ class _admin extends \IPS\Dispatcher\Controller
};
$table->joins = array(
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . \IPS\Member::loggedIn()->language()->id )
array( 'from' => array( 'core_sys_lang_words', 'w' ), 'where' => "w.word_key=lang_key AND w.lang_id=" . Member::loggedIn()->language()->id )
);
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs_prune' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_adminlogs_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=actionLogSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), \IPS\Member::loggedIn()->language()->addToStack( 'acplogs' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('acplogs');
\IPS\Output::i()->output = (string) $table;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), Member::loggedIn()->language()->addToStack( 'acplogs' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('acplogs');
Output::i()->output = (string) $table;
}
/**
@@ -580,22 +613,22 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function actionLogSettings()
protected function actionLogSettings() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs_prune' );
Dispatcher::i()->checkAcpPermission( 'restrictions_adminlogs_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_log_admin', \IPS\Settings::i()->prune_log_admin, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_admin' ) );
$form = new Form;
$form->add( new Interval( 'prune_log_admin', Settings::i()->prune_log_admin, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_admin' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__adminlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), 'saved' );
Session::i()->log( 'acplog__adminlog_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin&do=actionLogs' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminlogssettings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminlogssettings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'adminlogssettings', $form, FALSE );
}
/**
@@ -603,12 +636,12 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function loginLogs()
protected function loginLogs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs' );
Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_admin_login_logs', \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ) );
$table = new TableDb( 'core_admin_login_logs', Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ) );
$table->joins[] = array( 'from' => 'core_members', 'where' => 'core_admin_login_logs.admin_username=core_members.email' );
$table->langPrefix = 'adminloginlogs_';
$table->sortBy = $table->sortBy ?: 'admin_time';
@@ -619,17 +652,18 @@ class _admin extends \IPS\Dispatcher\Controller
$table->quickSearch = 'admin_username';
$table->advancedSearch = array(
'admin_username' => array(
\IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
SEARCH_CONTAINS_TEXT,
array(),
function( $val ){
if( !empty( $val ) )
{
return array( "(core_members.name LIKE CONCAT(?, '%') OR admin_username LIKE CONCAT(?,'%'))", $val, $val );
}
return null;
}
),
'admin_ip_address' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
'admin_time' => \IPS\Helpers\Table\SEARCH_DATE_RANGE
'admin_ip_address' => SEARCH_CONTAINS_TEXT,
'admin_time' => SEARCH_DATE_RANGE
);
/* Filters */
@@ -642,40 +676,40 @@ class _admin extends \IPS\Dispatcher\Controller
$table->parsers = array(
'admin_username' => function( $val, $row )
{
$member = \IPS\Member::constructFromData( $row );
$member = Member::constructFromData( $row );
if( $member->member_id )
{
return "<a href='{$member->acpUrl()}'>" . htmlentities( $member->name, ENT_DISALLOWED, 'UTF-8', FALSE ) . "</a>";
}
return $val;
},
'admin_time' => function( $val, $row )
'admin_time' => function( $val )
{
return \IPS\DateTime::ts( $val );
return DateTime::ts( $val );
},
'admin_success' => function( $val, $row )
'admin_success' => function( $val )
{
return ( $val ) ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
return ( $val ) ? "<i class='fa-solid fa-check'></i>" : "<i class='fa-solid fa-xmark'></i>";
},
);
/* Add a button for settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs_prune' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'staff', 'restrictions_acploginlogs_prune' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogsSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=staff&controller=admin&do=loginLogsSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
/* Display */
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ), \IPS\Member::loggedIn()->language()->addToStack( 'adminloginlogs' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminloginlogs');
\IPS\Output::i()->output = (string) $table;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=staff&controller=admin&do=loginLogs' ), Member::loggedIn()->language()->addToStack( 'adminloginlogs' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminloginlogs');
Output::i()->output = (string) $table;
}
/**
@@ -683,21 +717,21 @@ class _admin extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function loginLogsSettings()
protected function loginLogsSettings() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs_prune' );
Dispatcher::i()->checkAcpPermission( 'restrictions_acploginlogs_prune' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_log_adminlogin', \IPS\Settings::i()->prune_log_adminlogin, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_adminlogin' ) );
$form = new Form;
$form->add( new Interval( 'prune_log_adminlogin', Settings::i()->prune_log_adminlogin, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_log_adminlogin' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplog__adminloginlog_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
Session::i()->log( 'acplog__adminloginlog_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=staff&controller=admin' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('adminloginlogssettings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'adminloginlogssettings', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('adminloginlogssettings');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'adminloginlogssettings', $form, FALSE );
}
}