diff --git a/.env.example b/.env.example index 898aa7694..f47c87658 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ # Common params APP_ENV=local APP_CRON_ENABLED=true +APP_DEMO_MODE=false # Database credentials DB_CONNECTION=mysql diff --git a/CHANGELOG.md b/CHANGELOG.md index 12678a086..a1a8c86bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ **Merged pull requests:** - Release 2.4.2 🐯 ([belomaxorka](https://github.com/belomaxorka)) +- Added demo mode 📺 [\#1399](https://github.com/torrentpier/torrentpier/pull/1399) ([belomaxorka](https://github.com/belomaxorka)) - Added ability to view post_text of topic [\#1401](https://github.com/torrentpier/torrentpier/pull/1401) ([belomaxorka](https://github.com/belomaxorka)) - Added support for rutracker font BBCode tag [\#1397](https://github.com/torrentpier/torrentpier/pull/1397) ([belomaxorka](https://github.com/belomaxorka)) - Added mod "Reason to move topic" [\#1388](https://github.com/torrentpier/torrentpier/pull/1388) ([belomaxorka](https://github.com/belomaxorka)) @@ -18,7 +19,7 @@ - Used hashing for filenames generation [\#1385](https://github.com/torrentpier/torrentpier/pull/1385) ([belomaxorka](https://github.com/belomaxorka)) - Minor improvements [\#1382](https://github.com/torrentpier/torrentpier/pull/1382), [\#1383](https://github.com/torrentpier/torrentpier/pull/1383), [\#1391](https://github.com/torrentpier/torrentpier/pull/1391), [\#1398](https://github.com/torrentpier/torrentpier/pull/1398) ([belomaxorka](https://github.com/belomaxorka)) - Some bugfixes [\#1380](https://github.com/torrentpier/torrentpier/pull/1380) ([belomaxorka](https://github.com/belomaxorka)) -- New Crowdin updates [\#1384](https://github.com/torrentpier/torrentpier/pull/1384), [\#1389](https://github.com/torrentpier/torrentpier/pull/1389), [\#1392](https://github.com/torrentpier/torrentpier/pull/1392) ([Exileum](https://github.com/Exileum)) +- New Crowdin updates [\#1384](https://github.com/torrentpier/torrentpier/pull/1384), [\#1389](https://github.com/torrentpier/torrentpier/pull/1389), [\#1392](https://github.com/torrentpier/torrentpier/pull/1392), [\#1402](https://github.com/torrentpier/torrentpier/pull/1402) ([Exileum](https://github.com/Exileum)) ## [v2.4.1](https://github.com/torrentpier/torrentpier/tree/v2.4.1) (2024-02-04) [Full Changelog](https://github.com/torrentpier/torrentpier/compare/v2.4.0...v2.4.1) diff --git a/admin/admin_cron.php b/admin/admin_cron.php index eba8954f8..aa31d4439 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -29,6 +29,11 @@ if ($mode == 'run' && !$job_id) { require __DIR__ . '/pagestart.php'; } +// Check for demo mode +if (IN_DEMO_MODE && ($submit || !in_array($mode, ['add', 'list']))) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + if (!IS_SUPER_ADMIN) { bb_die($lang['ONLY_FOR_SUPER_ADMIN']); } diff --git a/admin/admin_extensions.php b/admin/admin_extensions.php index 340f5a1fc..f1e4ac4ba 100644 --- a/admin/admin_extensions.php +++ b/admin/admin_extensions.php @@ -47,6 +47,11 @@ $add_forum = isset($_POST['add_forum']); $delete_forum = isset($_POST['del_forum']); $submit = isset($_POST['submit']); +// Check for demo mode +if (IN_DEMO_MODE && ($submit || $add_forum || $delete_forum)) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + // Get Attachment Config $attach_config = []; diff --git a/admin/admin_forumauth.php b/admin/admin_forumauth.php index caec84c33..9c0bd2fc1 100644 --- a/admin/admin_forumauth.php +++ b/admin/admin_forumauth.php @@ -72,10 +72,17 @@ if (isset($_GET['adv'])) { unset($adv); } +$submit = isset($_POST['submit']); + +// Check for demo mode +if (IN_DEMO_MODE && $submit) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + /** * Start program proper */ -if (isset($_POST['submit'])) { +if ($submit) { $sql = ''; if (!empty($forum_id)) { diff --git a/admin/admin_forumauth_list.php b/admin/admin_forumauth_list.php index 5f5db591b..3c4f5dcbb 100644 --- a/admin/admin_forumauth_list.php +++ b/admin/admin_forumauth_list.php @@ -80,10 +80,17 @@ if (isset($_GET['adv'])) { unset($adv); } -// -// Start program proper -// -if (isset($_POST['submit'])) { +$submit = isset($_POST['submit']); + +// Check for demo mode +if (IN_DEMO_MODE && $submit) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + +/** + * Start program proper + */ +if ($submit) { $sql = ''; if (!empty($forum_id)) { diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 0983324db..73479cb0b 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -53,6 +53,20 @@ if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) { } } +// Check for demo mode +if (IN_DEMO_MODE && in_array($mode, [ + // Category + 'editcat', + 'modcat', + 'deletecat', + // Forum + 'editforum', + 'modforum', + 'deleteforum' + ])) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + $show_main_page = false; if ($mode) { diff --git a/admin/admin_phpinfo.php b/admin/admin_phpinfo.php index 77d1ad9b4..7bfe4053a 100644 --- a/admin/admin_phpinfo.php +++ b/admin/admin_phpinfo.php @@ -8,11 +8,22 @@ */ if (!empty($setmodules)) { - $module['GENERAL']['PHP_INFO'] = basename(__FILE__); + if (IS_SUPER_ADMIN) { + $module['GENERAL']['PHP_INFO'] = basename(__FILE__); + } return; } require __DIR__ . '/pagestart.php'; +if (!IS_SUPER_ADMIN) { + bb_die($lang['ONLY_FOR_SUPER_ADMIN']); +} + +// Check for demo mode +if (IN_DEMO_MODE) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + /** @noinspection ForgottenDebugOutputInspection */ phpinfo(); diff --git a/admin/admin_ug_auth.php b/admin/admin_ug_auth.php index 0964a66a2..f58e2b16c 100644 --- a/admin/admin_ug_auth.php +++ b/admin/admin_ug_auth.php @@ -26,6 +26,11 @@ $cat_id = isset($_REQUEST['c']) ? (int)$_REQUEST['c'] : 0; $mode = isset($_REQUEST['mode']) ? (string)$_REQUEST['mode'] : ''; $submit = isset($_REQUEST['submit']); +// Check for demo mode +if (IN_DEMO_MODE && $submit) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + $group_data = []; $forum_auth_fields = array( @@ -166,13 +171,12 @@ elseif ($submit && $mode == 'group' && (!empty($_POST['auth']) && is_array($_POS if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) { $page_cfg['quirks_mode'] = true; - $this_userdata = false; if (!empty($_POST['username'])) { $this_userdata = get_userdata($_POST['username'], true); - } elseif (!empty($user_id)) { + $user_id = $this_userdata['user_id']; + } else { $this_userdata = get_userdata($user_id); } - if (!$this_userdata) { bb_die($lang['NO_SUCH_USER']); } diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php index 49d5a1501..c56ac19f9 100644 --- a/admin/admin_user_ban.php +++ b/admin/admin_user_ban.php @@ -14,7 +14,14 @@ if (!empty($setmodules)) { require __DIR__ . '/pagestart.php'; -if (isset($_POST['submit'])) { +$submit = isset($_POST['submit']); + +// Check for demo mode +if (IN_DEMO_MODE && $submit) { + bb_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + +if ($submit) { // Ban action if (!empty($_POST['username'])) { if (!$this_userdata = get_userdata($_POST['username'], true)) { diff --git a/admin/index.php b/admin/index.php index 015568166..19927a800 100644 --- a/admin/index.php +++ b/admin/index.php @@ -166,8 +166,8 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $template->assign_block_vars('reg_user_row', [ 'ROW_CLASS' => $row_class, 'USER' => profile_url($onlinerow_reg[$i], true), - 'STARTED' => bb_date($onlinerow_reg[$i]['session_start'], 'H:i', false), - 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'H:i', false), + 'STARTED' => bb_date($onlinerow_reg[$i]['session_start'], 'd-M-Y H:i', false), + 'LASTUPDATE' => bb_date($onlinerow_reg[$i]['user_session_time'], 'd-M-Y H:i', false), 'IP_ADDRESS' => $reg_ip, 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $reg_ip, ]); @@ -185,8 +185,8 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $template->assign_block_vars('guest_user_row', [ 'ROW_CLASS' => $row_class, - 'STARTED' => bb_date($onlinerow_guest[$i]['session_start'], 'H:i', false), - 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'H:i', false), + 'STARTED' => bb_date($onlinerow_guest[$i]['session_start'], 'd-M-Y H:i', false), + 'LASTUPDATE' => bb_date($onlinerow_guest[$i]['session_time'], 'd-M-Y H:i', false), 'IP_ADDRESS' => $guest_ip, 'U_WHOIS_IP' => $bb_cfg['whois_info'] . $guest_ip, ]); diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 5f98cebda..0b26ed5c2 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -610,20 +610,20 @@ CREATE TABLE IF NOT EXISTS `bb_cron` INSERT INTO `bb_cron` (`cron_active`, `cron_title`, `cron_script`, `schedule`, `run_day`, `run_time`, `run_order`, `last_run`, `next_run`, `run_interval`, `log_enabled`, `log_file`, `log_sql_queries`, `disable_board`, `run_counter`) -VALUES ('1', 'Attach maintenance', 'attach_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '1', '', '0', +VALUES ('1', 'Attach maintenance', 'attach_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '0', '', '0', '1', '0'), - ('1', 'Board maintenance', 'board_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '1', '', '0', '1', + ('1', 'Board maintenance', 'board_maintenance.php', 'daily', '', '05:00:00', '40', '', '', '', '0', '', '0', '1', '0'), - ('1', 'Prune forums', 'prune_forums.php', 'daily', '', '05:00:00', '50', '', '', '', '1', '', '0', '1', '0'), - ('1', 'Prune topic moved stubs', 'prune_topic_moved.php', 'daily', '', '05:00:00', '60', '', '', '', '1', '', + ('1', 'Prune forums', 'prune_forums.php', 'daily', '', '05:00:00', '50', '', '', '', '0', '', '0', '1', '0'), + ('1', 'Prune topic moved stubs', 'prune_topic_moved.php', 'daily', '', '05:00:00', '60', '', '', '', '0', '', '0', '1', '0'), - ('1', 'Logs cleanup', 'clean_log.php', 'daily', '', '05:00:00', '70', '', '', '', '1', '', '0', '1', '0'), - ('1', 'PM cleanup', 'clean_pm.php', 'daily', '', '05:00:00', '70', '', '', '', '1', '', '0', '1', '0'), - ('1', 'Tracker maintenance', 'tr_maintenance.php', 'daily', '', '05:00:00', '90', '', '', '', '1', '', '0', '1', + ('1', 'Logs cleanup', 'clean_log.php', 'daily', '', '05:00:00', '70', '', '', '', '0', '', '0', '1', '0'), + ('1', 'PM cleanup', 'clean_pm.php', 'daily', '', '05:00:00', '70', '', '', '', '0', '', '0', '1', '0'), + ('1', 'Tracker maintenance', 'tr_maintenance.php', 'daily', '', '05:00:00', '90', '', '', '', '0', '', '0', '1', '0'), - ('1', 'Clean dlstat', 'clean_dlstat.php', 'daily', '', '05:00:00', '100', '', '', '', '1', '', '0', '1', '0'), - ('1', 'Prune inactive users', 'prune_inactive_users.php', 'daily', '', '05:00:00', '110', '', '', '', '1', '', + ('1', 'Clean dlstat', 'clean_dlstat.php', 'daily', '', '05:00:00', '100', '', '', '', '0', '', '0', '1', '0'), + ('1', 'Prune inactive users', 'prune_inactive_users.php', 'daily', '', '05:00:00', '110', '', '', '', '0', '', '0', '1', '0'), ('1', 'Sessions cleanup', 'sessions_cleanup.php', 'interval', '', '', '255', '', '', '00:03:00', '0', '', '0', '0', '0'), @@ -652,7 +652,9 @@ VALUES ('1', 'Attach maintenance', 'attach_maintenance.php', 'daily', '', '05:00 ('1', 'Sitemap update', 'sitemap.php', 'daily', '', '06:00:00', '30', '', '', '', '0', '', '0', '0', '0'), ('1', 'Update forums atom', 'update_forums_atom.php', 'interval', '', '', '255', '', '', '00:15:00', '0', '', '0', - '0', '0'); + '0', '0'), + ('1', 'Demo mode', 'demo_mode.php', 'daily', '', '05:00:00', '255', '', '', '', '1', 'demo_mode_cron', '1', '1', + '0'); -- ---------------------------- -- Table structure for `bb_disallow` diff --git a/library/ajax/edit_user_profile.php b/library/ajax/edit_user_profile.php index 10a9e09c1..a707fd24c 100644 --- a/library/ajax/edit_user_profile.php +++ b/library/ajax/edit_user_profile.php @@ -21,6 +21,11 @@ if (!$field = (string)$this->request['field']) { $this->ajax_die('invalid profile field'); } +// Check for demo mode +if (IN_DEMO_MODE && in_array($field, ['username', 'user_email'])) { + $this->ajax_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + $table = BB_USERS; $value = $this->request['value'] = (string)(isset($this->request['value'])) ? $this->request['value'] : 0; diff --git a/library/ajax/manage_user.php b/library/ajax/manage_user.php index bb71d1501..24b78271b 100644 --- a/library/ajax/manage_user.php +++ b/library/ajax/manage_user.php @@ -21,9 +21,13 @@ if (!$user_id = (int)$this->request['user_id']) { $this->ajax_die($lang['NO_USER_ID_SPECIFIED']); } +// Check for demo mode +if (IN_DEMO_MODE) { + $this->ajax_die($lang['CANT_EDIT_IN_DEMO_MODE']); +} + switch ($mode) { case 'delete_profile': - if ($userdata['user_id'] == $user_id) { $this->ajax_die($lang['USER_DELETE_ME']); } @@ -39,11 +43,8 @@ switch ($mode) { } else { $this->ajax_die($lang['USER_DELETE_CSV']); } - break; - case 'delete_topics': - if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) { $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); } @@ -60,11 +61,8 @@ switch ($mode) { } else { $this->ajax_die($lang['NOT_ADMIN']); } - break; - case 'delete_message': - if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) { $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); } @@ -79,23 +77,16 @@ switch ($mode) { } else { $this->ajax_die($lang['NOT_ADMIN']); } - break; - case 'user_activate': - if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['DEACTIVATE_CONFIRM']); } DB()->query("UPDATE " . BB_USERS . " SET user_active = '1' WHERE user_id = " . $user_id); - $this->response['info'] = $lang['USER_ACTIVATE_ON']; - break; - case 'user_deactivate': - if ($userdata['user_id'] == $user_id) { $this->ajax_die($lang['USER_DEACTIVATE_ME']); } @@ -105,9 +96,7 @@ switch ($mode) { DB()->query("UPDATE " . BB_USERS . " SET user_active = '0' WHERE user_id = " . $user_id); \TorrentPier\Sessions::delete_user_sessions($user_id); - $this->response['info'] = $lang['USER_ACTIVATE_OFF']; - break; default: diff --git a/library/includes/cron/jobs/demo_mode.php b/library/includes/cron/jobs/demo_mode.php new file mode 100644 index 000000000..eb61b0563 --- /dev/null +++ b/library/includes/cron/jobs/demo_mode.php @@ -0,0 +1,44 @@ +clean(); +foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { + CACHE($cache_name)->rm(); +} + +// Drop tables & Insert sql dump +$temp_line = ''; +foreach (file($dump_path) as $line) { + if (str_starts_with($line, '--') || $line == '') { + continue; + } + + $temp_line .= $line; + if (str_ends_with(trim($line), ';')) { + if (!DB()->query($temp_line)) { + $cron_runtime_log = date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'] . "\n"; + } + $temp_line = ''; + } +} diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index a20ff1183..8e18583e7 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -24,6 +24,9 @@ $user_ip = \TorrentPier\Helpers\IPHelper::ip2long($client_ip); define('CLIENT_IP', $client_ip); define('USER_IP', $user_ip); +// Initialize demo mode +define('IN_DEMO_MODE', env('APP_DEMO_MODE', false)); + /** * @param $contents * @return string diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index 6d87539d9..7a408db6b 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -101,9 +101,9 @@ switch ($mode) { // field => can_edit $profile_fields = [ 'user_active' => IS_ADMIN, - 'username' => IS_ADMIN || $bb_cfg['allow_namechange'], - 'user_password' => true, - 'user_email' => true, // должен быть после user_password + 'username' => (IS_ADMIN || $bb_cfg['allow_namechange']) && !IN_DEMO_MODE, + 'user_password' => !IN_DEMO_MODE, + 'user_email' => !IN_DEMO_MODE, // должен быть после user_password 'user_lang' => $bb_cfg['allow_change']['language'], 'user_gender' => $bb_cfg['gender'], 'user_birthday' => $bb_cfg['birthday_enabled'], @@ -164,10 +164,6 @@ $can_edit_tpl = []; foreach ($profile_fields as $field => $can_edit) { $can_edit = (bool)$can_edit; $can_edit_tpl['CAN_EDIT_' . strtoupper($field)] = $can_edit; - if ($can_edit === false) { - // TODO: При continue; не устанавливаются переменные ($tp_data) шаблона прописанные в case - // continue; - } switch ($field) { /** @@ -187,7 +183,7 @@ foreach ($profile_fields as $field => $can_edit) { case 'username': $username = !empty($_POST['username']) ? clean_username($_POST['username']) : $pr_data['username']; - if ($submit) { + if ($submit && $can_edit) { $err = \TorrentPier\Validate::username($username); if (!$errors and $err && $mode == 'register') { $errors[] = $err; @@ -222,7 +218,7 @@ foreach ($profile_fields as $field => $can_edit) { * Пароль (edit, reg) */ case 'user_password': - if ($submit) { + if ($submit && $can_edit) { $cur_pass = (string)@$_POST['cur_pass']; $new_pass = (string)@$_POST['new_pass']; $cfm_pass = (string)@$_POST['cfm_pass']; @@ -256,14 +252,13 @@ foreach ($profile_fields as $field => $can_edit) { */ case 'user_email': $email = !empty($_POST['user_email']) ? (string)$_POST['user_email'] : $pr_data['user_email']; - if ($submit) { + if ($submit && $can_edit) { if ($mode == 'register') { if (!$errors and $err = \TorrentPier\Validate::email($email)) { $errors[] = $err; } $db_data['user_email'] = $email; } elseif ($email != $pr_data['user_email']) { - // если смена мейла юзером if ($bb_cfg['email_change_disabled'] && !$adm_edit && !IS_ADMIN) { $errors[] = $lang['EMAIL_CHANGING_DISABLED']; } diff --git a/library/language/source/main.php b/library/language/source/main.php index fbad3926d..60ce33da6 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -128,6 +128,8 @@ $lang['ONLINE_ADMIN'] = 'Administrator'; $lang['ONLINE_MOD'] = 'Moderator'; $lang['ONLINE_GROUP_MEMBER'] = 'Group member'; +$lang['CANT_EDIT_IN_DEMO_MODE'] = 'This action can not be performed in demo mode!'; + $lang['CURRENT_TIME'] = 'Current time is: %s'; $lang['SEARCH_NEW'] = 'View newest posts'; diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index cbb6a6a85..70bd6176a 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -64,7 +64,7 @@ class SqlDb $this->do_explain = ($this->dbg_enabled && !empty($_COOKIE['explain'])); $this->slow_time = SQL_SLOW_QUERY_TIME; - // Links to the global vairables (for recording all the logs on all servers, counting total request count and etc) + // Links to the global variables (for recording all the logs on all servers, counting total request count and etc) $this->DBS['log_file'] =& $DBS->log_file; $this->DBS['log_counter'] =& $DBS->log_counter; $this->DBS['num_queries'] =& $DBS->num_queries; diff --git a/styles/templates/default/index.tpl b/styles/templates/default/index.tpl index 1141eca29..52ae2c5e1 100644 --- a/styles/templates/default/index.tpl +++ b/styles/templates/default/index.tpl @@ -1,3 +1,10 @@ + +