protected function execute(InputInterface $input, OutputInterface $output) { $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); $this->cache->purge(); $this->load_migrations(); $orig_version = $this->config['version']; while (!$this->migrator->finished()) { try { $this->migrator->update(); } catch (\phpbb\db\migration\exception $e) { $output->writeln('<error>' . $e->getLocalisedMessage($this->user) . '</error>'); $this->finalise_update(); return 1; } } if ($orig_version != $this->config['version']) { $this->log->add('admin', ANONYMOUS, '', 'LOG_UPDATE_DATABASE', time(), array($orig_version, $this->config['version'])); } $this->finalise_update(); $output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']); }
function main($id, $mode) { global $phpbb_container, $user, $template, $config, $request; $this->phpbb_container = $phpbb_container; $this->user = $user; $this->template = $template; $this->config = $config; $this->request = $request; $this->log = $this->phpbb_container->get('log'); $this->tpl_name = 'acp_codebox_plus'; $this->page_title = $this->user->lang('CODEBOX_PLUS_TITLE'); add_form_key('o0johntam0o/acp_codebox_plus'); if ($this->request->is_set_post('submit')) { if (!check_form_key('o0johntam0o/acp_codebox_plus')) { trigger_error('FORM_INVALID'); } $this->config->set('codebox_plus_syntax_highlighting', $request->variable('codebox_plus_syntax_highlighting', 0)); $this->config->set('codebox_plus_expanded', $request->variable('codebox_plus_expanded', 0)); $this->config->set('codebox_plus_download', $request->variable('codebox_plus_download', 0)); $this->config->set('codebox_plus_login_required', $request->variable('codebox_plus_login_required', 0)); $this->config->set('codebox_plus_prevent_bots', $request->variable('codebox_plus_prevent_bots', 0)); $this->config->set('codebox_plus_captcha', $request->variable('codebox_plus_captcha', 0)); $this->config->set('codebox_plus_max_attempt', $request->variable('codebox_plus_max_attempt', 0)); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'CODEBOX_PLUS_LOG_MSG'); trigger_error($this->user->lang('CODEBOX_PLUS_SAVED') . adm_back_link($this->u_action)); } $this->template->assign_vars(array('U_ACTION' => $this->u_action, 'S_CODEBOX_PLUS_VERSION' => isset($this->config['codebox_plus_version']) ? $this->config['codebox_plus_version'] : 0, 'S_CODEBOX_PLUS_SYNTAX_HIGHLIGHTING' => isset($this->config['codebox_plus_syntax_highlighting']) ? $this->config['codebox_plus_syntax_highlighting'] : 0, 'S_CODEBOX_PLUS_EXPANDED' => isset($this->config['codebox_plus_expanded']) ? $this->config['codebox_plus_expanded'] : 0, 'S_CODEBOX_PLUS_DOWNLOAD' => isset($this->config['codebox_plus_download']) ? $this->config['codebox_plus_download'] : 0, 'S_CODEBOX_PLUS_LOGIN_REQUIRED' => isset($this->config['codebox_plus_login_required']) ? $this->config['codebox_plus_login_required'] : 0, 'S_CODEBOX_PLUS_PREVENT_BOTS' => isset($this->config['codebox_plus_prevent_bots']) ? $this->config['codebox_plus_prevent_bots'] : 0, 'S_CODEBOX_PLUS_CAPTCHA' => isset($this->config['codebox_plus_captcha']) ? $this->config['codebox_plus_captcha'] : 0, 'S_CODEBOX_PLUS_MAX_ATTEMPT' => isset($this->config['codebox_plus_max_attempt']) ? $this->config['codebox_plus_max_attempt'] : 0)); }
/** * Run the cronjob. */ public function run() { $time = strtotime('- ' . $this->config['ajaxshoutbox_prune_days'] . ' days'); $sql = 'SELECT * FROM ' . $this->table . ' WHERE post_time <= ' . $time; $result = $this->db->sql_query($sql); $canpush = $this->push->canPush(); $delete = array(); while ($row = $this->db->sql_fetchrow($result)) { if ($canpush) { if ($this->push->delete($row['shout_id']) !== false) { $delete[] = $row['shout_id']; } } else { $delete[] = $row['shout_id']; } } $this->db->sql_freeresult(); if (sizeof($delete)) { $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $this->db->sql_in_set('shout_id', $delete); $this->db->sql_query($sql); $uuid = $this->user->data['user_id']; if (!$uuid) { $uuid = ANONYMOUS; } $this->log->add('admin', $uuid, $this->user->ip, 'LOG_AJAX_SHOUTBOX_PRUNED', time(), array(sizeof($delete))); } $this->config->set('shoutbox_prune_gc', time(), false); }
/** * If login failed set the conter +1 * * @param object $event The event object * @return null * @access public */ public function login_box_failed($event) { // Set the counter +1 $sql = 'UPDATE ' . USERS_TABLE . " SET failed_logins_count = failed_logins_count + 1\n\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($event['username'])) . "'"; $this->db->sql_query($sql); // Add to user log $this->log->add('user', ANONYMOUS, $this->user->ip, 'TRY_TO_LOGIN_FAIL', time(), array('reportee_id' => ANONYMOUS, 'username' => $event['username'])); }
public function main($id, $mode) { global $config, $db, $request, $template, $user, $phpbb_root_path, $phpEx, $phpbb_container; $this->config = $config; $this->db = $db; $this->log = $phpbb_container->get('log'); $this->request = $request; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; // Load a template from adm/style for our ACP page $this->tpl_name = 'acp_usermerge'; // Set the page title for our ACP page $this->page_title = 'ACP_USER_MERGE'; // Quick var-checking and var setup. $action = $this->request->variable('action', ''); $merge = $action == 'merge' ? true : false; $errors = array(); $old_username = $this->request->variable('old_username', '', true); $new_username = $this->request->variable('new_username', '', true); $form_key = 'acp_user_merge'; add_form_key($form_key); // Hath we an invalid form key? if ($this->request->is_set_post('submit') && !check_form_key($form_key)) { $errors[] = $user->lang['FORM_INVALID']; } if ($this->request->is_set_post('submit') || $merge) { $old_user_id = $this->check_user($old_username, $errors, true); $new_user_id = $this->check_user($new_username, $errors, false); } // Make sure we have submitted the form, and that we do not have errors if (($this->request->is_set_post('submit') || $merge) && !sizeof($errors)) { if ($old_user_id == $new_user_id) { $warning = sprintf($this->user->lang['CANNOT_MERGE_SAME'], $old_username); trigger_error($warning . adm_back_link($this->u_action), E_USER_WARNING); } // Have we confirmed this change? if (confirm_box(true)) { // Let's roll! $this->user_merge($old_user_id, $new_user_id); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_USERS_MERGED', time(), array($old_username . ' » ' . $new_username)); trigger_error($this->user->lang['USERS_MERGED'] . adm_back_link($this->u_action)); } else { $hidden_fields = array('i' => $id, 'mode' => $mode, 'old_username' => $old_username, 'new_username' => $new_username, 'action' => 'merge'); // Be annoying. Are you suuuuuuuuuuuure? No, really, are you sure? $merge_users_confirm = sprintf($this->user->lang['MERGE_USERS_CONFIRM'], $old_username); confirm_box(false, $merge_users_confirm, build_hidden_fields($hidden_fields)); } } $user_merge_version = !empty($this->config['usermerge_version']) ? $this->config['usermerge_version'] : ''; // Assign template stuffs now. $this->page_title = $this->user->lang['ACP_USER_MERGE_TITLE']; $template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => implode('<br />', $errors), 'USER_MERGE_VERSION' => $user_merge_version, 'U_FIND_OLD_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=searchuser&form=user_merge&field=old_username&select_single=true'), 'U_FIND_NEW_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=searchuser&form=user_merge&field=new_username&select_single=true'), 'OLD_USERNAME' => !empty($old_user_id) ? $old_username : '', 'NEW_USERNAME' => !empty($new_user_id) ? $new_username : '', 'L_TITLE' => $this->user->lang['ACP_USER_MERGE_TITLE'], 'L_EXPLAIN' => $this->user->lang['ACP_USER_MERGE_EXPLAIN'], 'USERMERGE_VERSION' => $user_merge_version, 'U_ACTION' => $this->u_action)); }
/** * Log failed login attempts * * @param object $event The event object * @return null * @access public */ public function failed_login($event) { $result = $event['result']; $username = $event['username']; $additional_data = array(); $additional_data['reportee_id'] = $result['user_row']['user_id']; // We want to log Admin fails to the Admin log and User fails to the user log $log_type = $this->get_userid_from_username($username); switch ($result['status']) { case LOGIN_ERROR_USERNAME: $error_msg = 'ERROR_LOGIN_USERNAME'; $log_type = 'user'; // This can only be user as we have no data to test $additional_data[] = $username; break; case LOGIN_ERROR_PASSWORD: $error_msg = 'ERROR_LOGIN_PASSWORD'; break; case LOGIN_ERROR_ATTEMPTS: $error_msg = 'ERROR_LOGIN_ATTEMPTS'; break; case LOGIN_ERROR_PASSWORD_CONVERT: $error_msg = 'ERROR_LOGIN_PASSWORD_CONVERT'; break; default: // Let's have a catchall for any other fails $error_msg = 'ERROR_LOGIN_UNKNOWN'; $log_type = 'user'; $additional_data[] = $result['status']; $additional_data[] = $username; break; } $this->log->add($log_type, $result['user_row']['user_id'], $this->user->ip, $error_msg, time(), $additional_data); }
/** * Validate config vars and update config table if needed * * @return null */ public function process() { $submit = $this->request->is_set_post('submit') ? true : false; $this->new_config = $this->config; $cfg_array = $this->request->is_set('config') ? $this->request->variable('config', array('' => ''), true) : $this->new_config; $error = array(); // We validate the complete config if whished validate_config_vars($this->display_vars['vars'], $cfg_array, $error); // Do not write values if there is an error if (sizeof($error)) { $submit = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($this->display_vars['vars'] as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if ($submit) { $this->config->set($config_name, $config_value); } } if ($submit) { $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'DIR_CONFIG_SETTINGS'); trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $this->template->assign_vars(array('L_TITLE' => $this->user->lang[$this->display_vars['title']], 'L_TITLE_EXPLAIN' => $this->user->lang[$this->display_vars['title'] . '_EXPLAIN'], 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action)); }
/** * Activate user * * @param object $event The event object * @return null * @access public */ private function user_justification_activate() { $user = $this->data; if (!function_exists('user_active_flip')) { include $this->root_path . 'includes/functions_user.' . $this->php_ext; } if (!class_exists('messenger')) { include $this->root_path . 'includes/functions_messenger.' . $this->php_ext; } user_active_flip('activate', $user['user_id']); $messenger = new \messenger(false); $messenger->template('admin_welcome_activated', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); $messenger->anti_abuse_headers($this->config, $this->user); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user['username']))); $messenger->send(NOTIFY_EMAIL); $messenger->save_queue(); // Remove the notification $this->notification_manager->delete_notifications('notification.type.admin_activate_user', $user['user_id']); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\tSET user_actkey = ''\n\t\t\tWHERE user_id = {$user['user_id']}"; $this->db->sql_query($sql); // Create the correct logs $this->log->add('user', $this->user->data['user_id'], $this->user->ip, 'LOG_USER_ACTIVE_USER', false, array('reportee_id' => $user['user_id'])); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_USER_ACTIVE', false, array($user['username'])); }
/** * Submit auto group rule form data * * @param int $autogroups_id An auto group identifier * A value of 0 is new, otherwise we're updating * @return null * @access protected */ protected function submit_autogroup_rule($autogroups_id = 0) { $data = array('autogroups_type_id' => $this->request->variable('autogroups_type_id', 0), 'autogroups_min_value' => $this->request->variable('autogroups_min_value', 0), 'autogroups_max_value' => $this->request->variable('autogroups_max_value', 0), 'autogroups_group_id' => $this->request->variable('autogroups_group_id', 0), 'autogroups_default' => $this->request->variable('autogroups_default', false), 'autogroups_notify' => $this->request->variable('autogroups_notify', false)); // Prevent form submit when no user groups are available or selected if (!$data['autogroups_group_id']) { trigger_error($this->user->lang('ACP_AUTOGROUPS_INVALID_GROUPS') . adm_back_link($this->u_action), E_USER_WARNING); } // Prevent form submit when min and max values are identical if ($data['autogroups_min_value'] == $data['autogroups_max_value']) { trigger_error($this->user->lang('ACP_AUTOGROUPS_INVALID_RANGE') . adm_back_link($this->u_action), E_USER_WARNING); } if ($autogroups_id != 0) { $sql = 'UPDATE ' . $this->autogroups_rules_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE autogroups_id = ' . (int) $autogroups_id; $this->db->sql_query($sql); } else { $sql = 'INSERT INTO ' . $this->autogroups_rules_table . ' ' . $this->db->sql_build_array('INSERT', $data); $this->db->sql_query($sql); $autogroups_id = $this->db->sql_nextid(); } // Apply the auto group to all users $this->manager->sync_autogroups($autogroups_id); // Log the action $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_AUTOGROUPS_SAVED_LOG', time()); // Output message to user after submitting the form trigger_error($this->user->lang('ACP_AUTOGROUPS_SUBMIT_SUCCESS') . adm_back_link($this->u_action)); }
/** * {@inheritdoc} */ public function run() { $this->language->add_lang('migrator'); if (!isset($this->config['version_update_from'])) { $this->config->set('version_update_from', $this->config['version']); } $original_version = $this->config['version_update_from']; $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new installer_migrator_output_handler($this->iohandler), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); $migrations = $this->extension_manager->get_finder()->core_path('phpbb/db/migration/data/')->extension_directory('/migrations')->get_classes(); $this->migrator->set_migrations($migrations); $migration_step_count = $this->installer_config->get('database_update_migration_steps', -1); if ($migration_step_count < 0) { $migration_step_count = count($this->migrator->get_installable_migrations()) * 2; $this->installer_config->set('database_update_migration_steps', $migration_step_count); } $progress_count = $this->installer_config->get('database_update_count', 0); $restart_progress_bar = $progress_count === 0; // Only "restart" when the update runs for the first time $this->iohandler->set_task_count($migration_step_count, $restart_progress_bar); $this->installer_config->set_task_progress_count($migration_step_count); while (!$this->migrator->finished()) { try { $this->migrator->update(); $progress_count++; $last_run_migration = $this->migrator->get_last_run_migration(); if (isset($last_run_migration['effectively_installed']) && $last_run_migration['effectively_installed']) { // We skipped two step, so increment $progress_count by another one $progress_count++; } else { if ($last_run_migration['task'] === 'process_schema_step' && !$last_run_migration['state']['migration_schema_done'] || $last_run_migration['task'] === 'process_data_step' && !$last_run_migration['state']['migration_data_done']) { // We just run a step that wasn't counted yet so make it count $migration_step_count++; } } $this->iohandler->set_task_count($migration_step_count); $this->installer_config->set_task_progress_count($migration_step_count); $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count); } catch (exception $e) { $msg = $e->getParameters(); array_unshift($msg, $e->getMessage()); $this->iohandler->add_error_message($msg); throw new user_interaction_required_exception(); } if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) { $this->installer_config->set('database_update_count', $progress_count); $this->installer_config->set('database_update_migration_steps', $migration_step_count); throw new resource_limit_reached_exception(); } } if ($original_version !== $this->config['version']) { $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version'])); } $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL'); $this->config->delete('version_update_from'); $this->cache->purge(); $this->config->increment('assets_version', 1); }
/** * Log failed login attempts for members of specific groups * * @param object $event The event object * @return null * @access public */ public function log_failed_login_attempts($event) { if (!$this->config['sec_login_attempts']) { return; } if ($this->in_watch_group($event['result']['user_row']['user_id'])) { $this->log->add('user', $event['result']['user_row']['user_id'], $this->user->ip, 'LOG_TEAM_AUTH_FAIL', time(), array('reportee_id' => $event['result']['user_row']['user_id'])); } }
function main() { // Only registered users can go beyond this point if (!$this->user->data['is_registered']) { if ($this->user->data['is_bot']) { redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}")); } login_box('', $this->user->lang['LOGIN_INFO']); } $adm_points = $this->request->variable('adm_points', false); $u_id = $this->request->variable('user_id', 0); $post_id = $this->request->variable('post_id', 0); if (empty($u_id)) { $message = $this->user->lang['EDIT_NO_ID_SPECIFIED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank_edit')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } $user_id = $u_id; add_form_key('bank_edit'); if ($adm_points != false && ($this->auth->acl_get('a_') || $this->auth->acl_get('m_chg_bank'))) { $this->template->assign_block_vars('administer_bank', array()); $submit = isset($_POST['submit']) ? true : false; if ($submit) { if (!check_form_key('bank_edit')) { trigger_error('FORM_INVALID'); } $new_points = round($this->request->variable('points', 0.0), 2); $this->functions_points->set_bank($u_id, $new_points); $sql_array = array('SELECT' => 'user_id, username, user_points, user_colour', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $u_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $points_user = $this->db->sql_fetchrow($result); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MOD_BANK', false, array($points_user['username'])); $message = $post_id ? sprintf($this->user->lang['EDIT_P_RETURN_POST'], '<a href="' . append_sid("{$this->phpbb_root_path}viewtopic.{$this->phpEx}", "p=" . $post_id) . '">', '</a>') : sprintf($this->user->lang['EDIT_P_RETURN_INDEX'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") . '">', '</a>'); trigger_error(sprintf($this->user->lang['EDIT_POINTS_SET'], $this->config['points_name']) . $message); } else { $sql_array = array('SELECT' => 'u.user_id, u.username, u.user_points, u.user_colour, b.holding', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array($this->points_bank_table => 'b'), 'ON' => 'u.user_id = b.user_id')), 'WHERE' => 'u.user_id = ' . (int) $u_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); if (empty($u_id)) { $message = $this->user->lang['EDIT_USER_NOT_EXIST'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank_edit')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } $hidden_fields = build_hidden_fields(array('user_id' => $u_id, 'post_id' => $post_id)); $this->template->assign_vars(array('USER_NAME' => get_username_string('full', $u_id, $row['username'], $row['user_colour']), 'BANK_POINTS' => sprintf($this->functions_points->number_format_points($row['holding'])), 'POINTS_NAME' => $this->config['points_name'], 'CURRENT_VALUE' => $row['holding'], 'L_POINTS_MODIFY' => sprintf($this->user->lang['EDIT_BANK_MODIFY'], $this->config['points_name']), 'L_P_BANK_TITLE' => sprintf($this->user->lang['EDIT_P_BANK_TITLE'], $this->config['points_name']), 'L_USERNAME' => $this->user->lang['USERNAME'], 'L_SET_AMOUNT' => $this->user->lang['EDIT_SET_AMOUNT'], 'U_USER_LINK' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", "mode=viewprofile&u=" . $u_id), 'S_ACTION' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank_edit', 'adm_points' => '1')), 'S_HIDDEN_FIELDS' => $hidden_fields)); } } // Generate the page page_header($this->user->lang['EDIT_POINTS_ADMIN']); // Generate the page template $this->template->set_filenames(array('body' => 'points/points_bank_edit.html')); page_footer(); }
/** * Post to the shoutbox-app server * * @param array $data * @param string $path * * @return mixed */ private function postData($data, $path) { $browser = new Browser(new Curl()); try { $headers = array('Content-Type' => 'application/json'); $data = @json_encode($data); /** @var \Buzz\Message\Response $response */ $response = $browser->post($this->config['ajaxshoutbox_api_server'] . $path, $headers, $data); if ($response->isSuccessful()) { $rsp = $response->getContent(); $rsp = @json_decode($rsp, true); if (isset($rsp['error'])) { throw new \Exception(htmlspecialchars($rsp['error'])); // ;) } return $rsp; } } catch (\Exception $e) { $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_AJAX_SHOUTBOX_ERROR', time(), array($e->getMessage())); return false; } }
function main($id, $mode) { global $user, $template, $cache, $config, $phpbb_root_path, $phpEx, $phpbb_container, $request; $this->config = $config; $this->phpbb_container = $phpbb_container; $this->config_text = $this->phpbb_container->get('config_text'); $this->log = $this->phpbb_container->get('log'); $this->request = $request; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; $this->user->add_lang_ext('davidiq/reimg', 'reimg_acp'); $this->tpl_name = 'reimg'; $this->page_title = 'ACP_REIMG_SETTINGS'; $form_name = 'acp_reimg'; add_form_key($form_name); $reimg_swap_portrait = $this->request->variable('reimg_swap_portrait', (bool) $this->config['reimg_swap_portrait']); $reimg_resize_sig_img = $this->request->variable('reimg_resize_sig_img', (bool) $this->config['reimg_resize_sig_img']); $reimg_link = $this->request->variable('reimg_link', $this->config['reimg_link']); $reimg_zoom = $this->request->variable('reimg_zoom', $this->config['reimg_zoom']); $reimg_attachments = $this->request->variable('reimg_attachments', (bool) $this->config['reimg_attachments']); $reimg_for_all = $this->request->variable('reimg_for_all', (bool) $this->config['reimg_for_all']); if ($this->request->is_set_post('submit')) { if (!check_form_key($form_name)) { trigger_error($this->user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } //Update configuration now $this->config->set('reimg_swap_portrait', $reimg_swap_portrait); $this->config->set('reimg_resize_sig_img', $reimg_resize_sig_img); $this->config->set('reimg_link', $reimg_link); $this->config->set('reimg_zoom', $reimg_zoom); $this->config->set('reimg_attachments', $reimg_attachments); $this->config->set('reimg_for_all', $reimg_for_all); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_REIMG_UPDATED'); trigger_error($user->lang['REIMG_UPDATED'] . adm_back_link($this->u_action)); } $template->assign_vars(array('S_REIMG_SWAP_PORTRAIT' => $reimg_swap_portrait, 'S_REIMG_RESIZE_SIG_IMG' => $reimg_resize_sig_img, 'S_REIMG_LINK' => $this->select_reimg_link_method($reimg_link), 'S_REIMG_ZOOM' => $this->select_reimg_zoom_method($reimg_zoom), 'S_REIMG_ATTACHMENTS' => $reimg_attachments, 'S_REIMG_FOR_ALL' => $reimg_for_all, 'U_ACTION' => $this->u_action)); }
/** * Performs add|edit|del|clean|prune actions */ public function mchat_action($action, $sql_ary = null, $message_id = 0, $log_username = '') { switch ($action) { // User adds a message case 'add': $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->mchat_add_user_session(); break; // User edits a message // User edits a message case 'edit': $sql = 'UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE message_id = ' . (int) $message_id; $this->mchat_add_user_session(); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($log_username)); break; // User deletes a message // User deletes a message case 'del': $sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id; $this->mchat_add_user_session(); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($log_username)); $this->cache->destroy('sql', $this->mchat_table); break; // Founder purges all messages // Founder purges all messages case 'clean': $sql = 'TRUNCATE TABLE ' . $this->mchat_table; $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED'); $this->cache->destroy('sql', $this->mchat_table); break; // User triggers messages to be pruned // User triggers messages to be pruned case 'prune': $sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE message_id < ' . (int) $message_id; $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED'); $this->cache->destroy('sql', $this->mchat_table); break; default: return; } $result = $this->db->sql_query($sql); if ($result !== false) { switch ($action) { case 'add': if ($this->db->sql_nextid() == 1) { $this->cache->destroy('sql', $this->mchat_table); } break; } } }
/** * Sets the title of an idea. * * @param int $idea_id ID of the idea to be updated. * @param string $title New title. * * @return boolean True if updated, false if invalid length. */ public function set_title($idea_id, $title) { if (utf8_clean_string($title) === '' || utf8_strlen($title) > 64) { return false; } $sql_ary = array('idea_title' => $title); $this->update_idea_data($sql_ary, $idea_id, 'table_ideas'); // We also need to update the topic's title $idea = $this->get_idea($idea_id); $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\t\tSET topic_title='" . $this->db->sql_escape($title) . "'\n\t\t\tWHERE topic_id=" . (int) $idea['topic_id']; $this->db->sql_query($sql); $this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'ACP_PHPBB_IDEAS_TITLE_EDITED_LOG', time(), array($idea_id)); return true; }
/** * Main ACP module * * @param int $id * @param string $mode * @return null * @access public */ public function main($id, $mode) { $this->tpl_name = 'acp_teamsecurity'; $this->page_title = $this->user->lang('ACP_TEAM_SECURITY_SETTINGS'); // Only allow founders to view/manage these settings if ($this->user->data['user_type'] != USER_FOUNDER) { trigger_error($this->user->lang('ACP_FOUNDER_MANAGE_ONLY'), E_USER_WARNING); } $form_key = 'acp_teamsecurity'; add_form_key($form_key); if ($this->request->is_set_post('submit')) { if (!check_form_key($form_key)) { trigger_error($this->user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } // Validate the email address submitted by the user $sec_contact = $this->request->variable('sec_contact', ''); if ($sec_contact != '' && !preg_match('/^' . get_preg_expression('email') . '$/i', $sec_contact)) { trigger_error($this->user->lang('EMAIL_INVALID_EMAIL') . adm_back_link($this->u_action), E_USER_WARNING); } $this->config->set('sec_contact', $sec_contact); $this->config->set('sec_contact_name', $this->request->variable('sec_contact_name', '', true)); $this->config->set('sec_login_email', $this->request->variable('sec_login_email', 0)); $this->config->set('sec_login_attempts', $this->request->variable('sec_login_attempts', 0)); $this->config->set('sec_email_changes', $this->request->variable('sec_email_changes', 0)); $this->config->set('sec_strong_pass', $this->request->variable('sec_strong_pass', 0)); $this->config->set('sec_min_pass_chars', $this->request->variable('sec_min_pass_chars', 0)); $this->config->set('sec_usergroups', json_encode($this->request->variable('sec_usergroups', array(0)))); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_TEAM_SEC_UPDATED'); trigger_error($this->user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); } // Set template vars for usergroups multi-select box $group_id_ary = !$this->config['sec_usergroups'] ? array() : json_decode(trim($this->config['sec_usergroups']), true); $this->get_group_options($group_id_ary); // Set output vars for display in the template $this->template->assign_vars(array('S_ACP_LOGIN_EMAIL' => $this->config['sec_login_email'], 'ACP_CONTACT_EMAIL' => $this->config['sec_contact'], 'ACP_CONTACT_NAME' => $this->config['sec_contact_name'], 'S_ACP_LOGIN_ATTEMPTS' => $this->config['sec_login_attempts'], 'S_ACP_EMAIL_CHANGES' => $this->config['sec_email_changes'], 'S_ACP_STRONG_PASS' => $this->config['sec_strong_pass'], 'ACP_MIN_PASS_CHARS' => $this->config['sec_min_pass_chars'], 'U_ACTION' => $this->u_action)); }
/** * Get link's information and call appropriate action * * @param array $mark Website selected for (dis)approval * @return null */ public function exec_action($mark) { $this->_get_infos_links($mark); switch ($this->action) { case 'approved': $this->_action_approved(); break; case 'disapproved': $this->_action_disapproved(); break; default: return; } $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_LINK_' . strtoupper($this->action), time(), array(implode(', ', $this->affected_link_name))); }
function random_bonus_increment($user_id) { /** * Read out config values */ $sql = 'SELECT * FROM ' . $this->points_values_table; $result = $this->db->sql_query($sql); $points_values = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $bonus_chance = ''; $bonus = false; // Basic value, sorry.. $bonus_value = 0.0; // Basic value // Following numbers are 'times 100' to get rid of commas, as mt_rand doesn't get comma numbers. $bonus_chance = $points_values['points_bonus_chance'] * 100; // The chance percentage for a user to get the bonus $random_number = mt_rand(0, 10000); // The random number we compare to the chance percentage if ($random_number <= $bonus_chance) { $bonus = true; // Check if we want a fixed bonus value or not if ($points_values['points_bonus_min'] == $points_values['points_bonus_max']) { $bonus_value = $points_values['points_bonus_min']; } else { // Create the bonus value, between the set minimum and maximum // Following numbers are 'times 100' to get rid of commas, as mt_rand doesn't get comma numbers. $bonus_random = mt_rand($points_values['points_bonus_min'] * 100, $points_values['points_bonus_max'] * 100) / 100; $bonus_value = round($bonus_random, 0, PHP_ROUND_HALF_UP); } } if ($bonus && $bonus_value) { $this->add_points((int) $user_id, $bonus_value); // Send out notification // Increase our notification sent counter $this->config->increment('points_notification_id', 1); // Store the notification data we will use in an array $data = array('points_notify_id' => (int) $this->config['points_notification_id'], 'points_notify_msg' => sprintf($this->user->lang['NOTIFICATION_RANDOM_BONUS'], $bonus_value, $this->config['points_name']), 'sender' => (int) $this->user->data['user_id'], 'receiver' => (int) $user_id, 'mode' => 'logs'); $this->notification_manager->add_notifications('dmzx.ultimatepoints.notification.type.points', $data); $sql_array = array('SELECT' => 'username', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $user_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $points_user = $this->db->sql_fetchrow($result); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MOD_POINTS_RANDOM', false, array($points_user['username'])); } }
/** * Send notification to users * * @param int $rule_id The rule identifier * @return null * @access public */ public function send_notification($rule_id) { // Use a confirmation box routine when sending notifications if (confirm_box(true)) { // Increment our notifications sent counter $this->config->increment('boardrules_notification', 1); // Store the notification data we will use in an array $notification_data = array('rule_id' => $rule_id, 'notification_id' => $this->config['boardrules_notification']); // Create the notification $this->notification_manager->add_notifications('phpbb.boardrules.notification.type.boardrules', $notification_data); // Log the notification $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_BOARDRULES_NOTIFY_LOG'); } else { // Request confirmation from the user to send notification to all users // Build a hidden array of the form data confirm_box(false, $this->user->lang('ACP_BOARDRULES_NOTIFY_CONFIRM'), build_hidden_fields(array('action_send_notification' => true, 'rule_id' => $rule_id))); } }
/** * Activate user * * @param object $event The event object * @return null * @access public */ private function user_justification_activate() { $user = $this->data; if (!function_exists('user_active_flip')) { include $this->root_path . 'includes/functions_user.' . $this->php_ext; } if (!class_exists('messenger')) { include $this->root_path . 'includes/functions_messenger.' . $this->php_ext; } user_active_flip('activate', $user['user_id']); $messenger = new \messenger(false); $messenger->template('admin_welcome_activated', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); $messenger->anti_abuse_headers($this->config, $this->user); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user['username']))); $messenger->send(NOTIFY_EMAIL); $messenger->save_queue(); $this->log->add('user', $this->user->data['user_id'], $this->user->ip, 'LOG_USER_ACTIVE', time(), array($user['username'])); }
/** * Clear user reputation * * @param int $user_id User id * @param array $data Reputation data * @param arrat $post_ids Post IDs * @access public * @return null */ public function clear_user_reputation($user_id, $data, $post_ids) { // Required fields $fields = array('user_id_to', 'reputation_item_id'); foreach ($fields as $field) { if (!isset($data[$field])) { throw new \pico\reputation\exception\invalid_argument(array($field, 'FIELD_MISSING')); } } $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\tSET user_reputation = 0\n\t\t\tWHERE user_id = {$user_id}"; $this->db->sql_query($sql); $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_reputation = 0 WHERE ' . $this->db->sql_in_set('post_id', $post_ids, false, true); $this->db->sql_query($sql); $sql = 'DELETE FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$user_id}"; $this->db->sql_query($sql); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_USER_REPUTATION_CLEARED', false, array('user_id_to' => isset($data['username_to']) ? $data['username_to'] : $data['user_id_to'])); }
/** * Display the options a user can configure for this extension * * @return null * @access public */ public function display_options() { // Add the language file $this->language->add_lang('acp_autobackup', 'david63/autodbbackup'); // Create a form key for preventing CSRF attacks $form_key = 'auto_db_backup'; add_form_key($form_key); $this->get_filetypes(); $time = time(); // Submit if ($this->request->is_set_post('submit')) { // Is the submitted form is valid? if (!check_form_key($form_key)) { trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } // Get the date/time variables $day = $this->request->variable('auto_db_backup_day', 0); $month = $this->request->variable('auto_db_backup_month', 0); $year = $this->request->variable('auto_db_backup_year', 0); $hour = $this->request->variable('auto_db_backup_hour', 0); $minute = $this->request->variable('auto_db_backup_minute', 0); $enable = $this->request->variable('auto_db_backup_enable', 0); // Let's do a bit of validation if (!checkdate($month, $day, $year)) { trigger_error($this->language->lang('DATE_TIME_ERROR') . adm_back_link($this->u_action), E_USER_WARNING); } $dst = date('I', $time); $this->backup_date = mktime($hour + $dst, $minute, 0, $month, $day, $year); // Skip this check if disabling if ($enable && $this->backup_date <= $time) { trigger_error($this->language->lang('AUTO_DB_BACKUP_TIME_ERROR') . adm_back_link($this->u_action), E_USER_WARNING); } // Set the options the user has configured $this->set_options(); // Add option settings change action to the admin log $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_AUTO_DB_BACKUP_SETTINGS'); trigger_error($this->language->lang('AUTO_DB_BACKUP_SETTINGS_CHANGED') . adm_back_link($this->u_action)); } $next_backup_date = $this->config['auto_db_backup_last_gc'] > $time ? getdate($this->config['auto_db_backup_last_gc']) : getdate($this->config['auto_db_backup_last_gc'] + $this->config['auto_db_backup_gc']); // Output the page $this->template->assign_vars(array('AUTO_DB_BACKUP_COPIES' => $this->config['auto_db_backup_copies'], 'AUTO_DB_BACKUP_DAY' => $next_backup_date['mday'], 'AUTO_DB_BACKUP_GC' => $this->config['auto_db_backup_gc'] / 3600, 'AUTO_DB_BACKUP_HOUR' => $next_backup_date['hours'], 'AUTO_DB_BACKUP_MINUTE' => $next_backup_date['minutes'], 'AUTO_DB_BACKUP_MONTH' => $next_backup_date['mon'], 'AUTO_DB_BACKUP_VERSION' => ext::AUTO_DB_BACKUP_VERSION, 'AUTO_DB_BACKUP_YEAR' => $next_backup_date['year'], 'S_AUTO_DB_BACKUP_ENABLE' => $this->config['auto_db_backup_enable'], 'S_AUTO_DB_BACKUP_OPTIMIZE' => $this->config['auto_db_backup_optimize'], 'U_ACTION' => $this->u_action, 'YEAR_START' => $next_backup_date['year'], 'YEAR_END' => $next_backup_date['year'] + 1)); }
/** * Delete a page * * @param int $page_id The page identifier to delete * @return null * @access public */ public function delete_page($page_id) { // Initiate and load the page entity /* @var $entity \phpbb\pages\entity\page */ $entity = $this->container->get('phpbb.pages.entity')->load($page_id); try { // Delete the page $this->page_operator->delete_page($page_id); } catch (\phpbb\pages\exception\base $e) { // Display an error message if delete failed trigger_error($this->user->lang('ACP_PAGES_DELETE_ERRORED') . adm_back_link($this->u_action), E_USER_WARNING); } // Log the action $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PAGES_DELETED_LOG', time(), array($entity->get_title())); // If AJAX was used, show user a result message if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $this->user->lang('ACP_PAGES_DELETE_SUCCESS'), 'REFRESH_DATA' => array('time' => 3))); } }
/** * Delete a flag * * @param int $flag_id The flag identifier to delete * @return null * @access public */ public function delete_flag($flag_id) { if (confirm_box(true)) { // Grab the flag name for the log... $sql = 'SELECT flag_name, flag_image FROM ' . $this->flags_table . ' WHERE flag_id = ' . (int) $flag_id; $result = $this->db->sql_query($sql); $flag_row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Delete the flag... $sql = 'DELETE FROM ' . $this->flags_table . ' WHERE flag_id = ' . (int) $flag_id; $this->db->sql_query($sql); // Reset the flag for users $sql = 'UPDATE ' . USERS_TABLE . ' SET user_flag = 0 WHERE user_flag = ' . (int) $flag_id; $this->db->sql_query($sql); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_FLAGS_DELETED', time(), array($flag_row['flag_name'])); $this->cache->destroy('_user_flags'); $this->functions->cache_flags(); trigger_error($this->user->lang['MSG_FLAGS_DELETED'] . adm_back_link($this->u_action . "&mode=manage")); } else { // display a count of users who have this flag $sql = 'SELECT COUNT(user_flag) AS flag_count FROM ' . USERS_TABLE . ' WHERE user_flag = ' . (int) $flag_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $message = $this->user->lang['MSG_CONFIRM']; if (!empty($row['flag_count'])) { $message .= $row['flag_count'] != 1 ? $this->user->lang('MSG_FLAGS_CONFIRM_DELETE', $row['flag_count']) : $this->user->lang('MSG_FLAG_CONFIRM_DELETE', $row['flag_count']); } confirm_box(false, $message, build_hidden_fields(array('id' => (int) $flag_id, 'mode' => 'manage', 'action' => 'delete'))); // Use a redirect to take the user back to the previous page // if the user chose not delete the flag from the confirmation page. redirect("{$this->u_action}"); } }
private function get_file($url) { // We'll use curl..most servers have it installed as default if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $contents = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // if nothing is returned (SFS is down) if ($httpcode != 200) { return false; } return $contents; } $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_NEED_CURL', time()); return false; }
/** * {@inheritdoc} */ public function run() { $this->language->add_lang('migrator'); if (!isset($this->config['version_update_from'])) { $this->config->set('version_update_from', $this->config['version']); } $original_version = $this->config['version_update_from']; $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new installer_migrator_output_handler($this->iohandler), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); $migrations = $this->extension_manager->get_finder()->core_path('phpbb/db/migration/data/')->extension_directory('/migrations')->get_classes(); $this->migrator->set_migrations($migrations); $migration_count = count($this->migrator->get_migrations()); $this->iohandler->set_task_count($migration_count, true); $progress_count = $this->installer_config->get('database_update_count', 0); while (!$this->migrator->finished()) { try { $this->migrator->update(); $progress_count++; $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count); } catch (exception $e) { $msg = $e->getParameters(); array_unshift($msg, $e->getMessage()); $this->iohandler->add_error_message($msg); $this->iohandler->send_response(); throw new user_interaction_required_exception(); } if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) { $this->installer_config->set('database_update_count', $progress_count); throw new resource_limit_reached_exception(); } } if ($original_version !== $this->config['version']) { $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version'])); } $this->iohandler->finish_progress('INLINE_UPDATE_SUCCESSFUL'); $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL'); $this->config->delete('version_update_from'); $this->cache->purge(); $this->config->increment('assets_version', 1); }
/** * Set ideas forum options * * @return void * @access public */ public function set_ideas_forum_options() { // Check if Ideas forum is selected and apply relevant settings if it is // But display the confirm box first if (confirm_box(true)) { if (empty($this->config['ideas_forum_id'])) { trigger_error($this->language->lang('ACP_IDEAS_NO_FORUM') . adm_back_link($this->u_action), E_USER_WARNING); } if (!class_exists('auth_admin')) { include $this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext; } $auth_admin = new \auth_admin(); $forum_id = (int) $this->config['ideas_forum_id']; // Get the REGISTERED usergroup ID $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'"; $this->db->sql_query($sql); $group_id = (int) $this->db->sql_fetchfield('group_id'); // Get 'f_' local REGISTERED users group permissions array for the ideas forum // Default undefined permissions to ACL_NO $hold_ary = $auth_admin->get_mask('set', false, $group_id, $forum_id, 'f_', 'local', ACL_NO); $auth_settings = $hold_ary[$group_id][$forum_id]; // Set 'Can start new topics' permissions to 'Never' for the ideas forum $auth_settings['f_post'] = ACL_NEVER; // Update the registered usergroup permissions for selected Ideas forum... $auth_admin->acl_set('group', $forum_id, $group_id, $auth_settings); // Disable auto-pruning for ideas forum $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', array('enable_prune' => false)) . ' WHERE forum_id = ' . $forum_id; $this->db->sql_query($sql); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PHPBB_IDEAS_FORUM_SETUP_LOG'); trigger_error($this->language->lang('ACP_IDEAS_FORUM_SETUP_UPDATED') . adm_back_link($this->u_action)); } else { confirm_box(false, $this->language->lang('ACP_IDEAS_FORUM_SETUP_CONFIRM'), build_hidden_fields(array('ideas_forum_setup' => $this->request->is_set_post('ideas_forum_setup')))); } }
/** * The main cron task code. */ public function cron_tidy_warnings($topic_ids = array()) { $warning_list = $user_list = $unban_list = array(); $current_time = time(); $sql = 'SELECT * FROM ' . WARNINGS_TABLE . "\n\t\t\tWHERE warning_end < {$current_time} \n\t\t\tAND warning_end > 0 \n\t\t\tAND warning_status = 1"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $warning_list[] = $row['warning_id']; $user_list[$row['user_id']] = isset($user_list[$row['user_id']]) ? ++$user_list[$row['user_id']] : 1; } $this->db->sql_freeresult($result); if (sizeof($warning_list)) { $this->db->sql_transaction('begin'); $sql = 'UPDATE ' . WARNINGS_TABLE . ' SET warning_status = 0 WHERE ' . $this->db->sql_in_set('warning_id', $warning_list); $this->db->sql_query($sql); foreach ($user_list as $user_id => $value) { $sql = 'UPDATE ' . USERS_TABLE . " SET user_warnings = user_warnings - {$value}\n\t\t\t\t\tWHERE user_id = {$user_id}"; $this->db->sql_query($sql); } // Try to get storage engine type to detect if transactions are supported // to apply proper bans selection (MyISAM/InnoDB) $operator = '<'; /* Comment out this part of code for now as get_table_status() * as unavailable for \phpbb\db\driver\driver_interface if (strpos($this->db->get_sql_layer(), 'mysql') !== false) { $table_status = $this->db->get_table_status(USERS_TABLE); if (isset($table_status['Engine'])) { $operator = ($table_status['Engine'] === 'MyISAM') ? '<' : '<='; } } */ $sql = 'SELECT u.user_id, b.ban_id FROM ' . USERS_TABLE . ' u, ' . BANLIST_TABLE . " b\n\t\t\t\tWHERE u.user_ban_id = 1\n\t\t\t\t\tAND u.user_warnings {$operator} " . (int) $this->config['warnings_for_ban'] . ' AND u.user_id = b.ban_userid'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $unban_list[(int) $row['user_id']] = (int) $row['ban_id']; } $this->db->sql_freeresult($result); if (sizeof($unban_list)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_ban_id = 0 WHERE ' . $this->db->sql_in_set('user_id', array_keys($unban_list)); $this->db->sql_query($sql); $sql = 'SELECT u.username AS unban_info, u.user_id FROM ' . USERS_TABLE . ' u, ' . BANLIST_TABLE . ' b WHERE ' . $this->db->sql_in_set('b.ban_id', $unban_list) . ' AND u.user_id = b.ban_userid'; $result = $this->db->sql_query($sql); $l_unban_list = ''; $user_ids_ary = array(); while ($row = $this->db->sql_fetchrow($result)) { $l_unban_list .= ($l_unban_list != '' ? ', ' : '') . $row['unban_info']; $user_ids_ary[] = $row['user_id']; } $this->db->sql_freeresult($result); $sql = 'DELETE FROM ' . BANLIST_TABLE . ' WHERE ' . $this->db->sql_in_set('ban_id', $unban_list); $this->db->sql_query($sql); // Add to moderator log, admin log and user notes $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_UNBAN_USER', false, $l_unban_list); $this->phpbb_log->add('mod', 0, 0, 'LOG_UNBAN_USER', false, $l_unban_list); foreach ($user_ids_ary as $user_id) { $this->phpbb_log->add('user', $user_id, 0, 'LOG_UNBAN_USER', false, $l_unban_list); } } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', array(WARNINGS_TABLE, BANLIST_TABLE)); $this->config->set('warnings_last_gc', time(), true); }
/** * Main ACP module * * @param int $id * @param string $mode * @access public */ public function main($id, $mode) { $form_key = 'acp_similar_topics'; add_form_key($form_key); $action = $this->request->variable('action', ''); switch ($action) { case 'advanced': $forum_id = $this->request->variable('f', 0); if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); $similar_topic_forums = implode(',', $this->request->variable('similar_forums_id', array(0))); $this->validate_config_length($similar_topic_forums); $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\t\t\t\tSET similar_topic_forums = '" . $this->db->sql_escape($similar_topic_forums) . "'\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $this->db->sql_query($sql); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PST_LOG_MSG'); trigger_error($this->user->lang('PST_SAVED') . adm_back_link($this->u_action)); } $forum_name = ''; $selected = array(); if ($forum_id > 0) { $sql = 'SELECT forum_name, similar_topic_forums FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $result = $this->db->sql_query($sql); while ($fid = $this->db->sql_fetchrow($result)) { $selected = explode(',', trim($fid['similar_topic_forums'])); $forum_name = $fid['forum_name']; } $this->db->sql_freeresult($result); } $this->template->assign_vars(array('S_ADVANCED_SETTINGS' => true, 'SIMILAR_FORUMS_OPTIONS' => make_forum_select($selected, false, false, true), 'PST_FORUM_NAME' => $forum_name, 'PST_ADVANCED_EXP' => $this->user->lang('PST_ADVANCED_EXP', $forum_name), 'U_ACTION' => $this->u_action . '&action=advanced&f=' . $forum_id, 'U_BACK' => $this->u_action)); break; default: if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); // Get checkbox array form data and check string length $mark_noshow_forum = implode(',', $this->request->variable('mark_noshow_forum', array(0), true)); $mark_ignore_forum = implode(',', $this->request->variable('mark_ignore_forum', array(0), true)); $this->validate_config_length($mark_noshow_forum, $mark_ignore_forum); // Set basic config settings $this->config->set('similar_topics', $this->request->variable('pst_enable', 0)); $this->config->set('similar_topics_limit', abs($this->request->variable('pst_limit', 0))); // use abs for positive values only $this->config->set('similar_topics_cache', abs($this->request->variable('pst_cache', 0))); // use abs for positive values only $this->config->set('similar_topics_words', $this->request->variable('pst_words', '', true)); $this->config->set('similar_topics_hide', $mark_noshow_forum); $this->config->set('similar_topics_ignore', $mark_ignore_forum); // Set date/time config settings $pst_time = abs($this->request->variable('pst_time', 0)); // use abs for positive values only $pst_time_type = $this->request->variable('pst_time_type', ''); $this->config->set('similar_topics_type', $pst_time_type); $this->config->set('similar_topics_time', $this->set_pst_time($pst_time, $pst_time_type)); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PST_LOG_MSG'); trigger_error($this->user->lang('PST_SAVED') . adm_back_link($this->u_action)); } // Allow option to update the database to enable FULLTEXT support if ($this->request->is_set_post('fulltext')) { if (confirm_box(true)) { // If FULLTEXT is not supported, lets make it so if (!$this->fulltext_support_enabled()) { // Alter the database to support FULLTEXT $this->enable_fulltext_support(); // Store the original database storage engine in a config var for recovery on uninstall $this->config->set('similar_topics_fulltext', (string) $this->fulltext->get_engine()); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PST_LOG_FULLTEXT', time(), array(TOPICS_TABLE)); trigger_error($this->user->lang('PST_SAVE_FULLTEXT') . adm_back_link($this->u_action)); } else { trigger_error($this->user->lang('PST_ERR_FULLTEXT') . adm_back_link($this->u_action), E_USER_WARNING); } } else { confirm_box(false, $this->user->lang('CONFIRM_OPERATION'), build_hidden_fields(array('fulltext' => 1))); } } // Build the time options select menu $time_options = array('d' => $this->user->lang('PST_DAYS'), 'w' => $this->user->lang('PST_WEEKS'), 'm' => $this->user->lang('PST_MONTHS'), 'y' => $this->user->lang('PST_YEARS')); foreach ($time_options as $value => $label) { $this->template->assign_block_vars('similar_time_options', array('VALUE' => $value, 'LABEL' => $label, 'S_SELECTED' => $value == $this->config['similar_topics_type'])); } $this->template->assign_vars(array('S_PST_ENABLE' => $this->isset_or_default($this->config['similar_topics'], false), 'PST_LIMIT' => $this->isset_or_default($this->config['similar_topics_limit'], ''), 'PST_CACHE' => $this->isset_or_default($this->config['similar_topics_cache'], ''), 'PST_WORDS' => $this->isset_or_default($this->config['similar_topics_words'], ''), 'PST_TIME' => $this->get_pst_time($this->config['similar_topics_time'], $this->config['similar_topics_type']), 'S_PST_NO_SUPPORT' => !$this->fulltext_support_enabled(), 'S_PST_NO_MYSQL' => !$this->fulltext->is_mysql(), 'U_ACTION' => $this->u_action)); $ignore_forums = explode(',', trim($this->config['similar_topics_ignore'])); $noshow_forums = explode(',', trim($this->config['similar_topics_hide'])); $forum_list = $this->get_forum_list(); foreach ($forum_list as $row) { $this->template->assign_block_vars('forums', array('FORUM_NAME' => $row['forum_name'], 'FORUM_ID' => $row['forum_id'], 'CHECKED_IGNORE_FORUM' => in_array($row['forum_id'], $ignore_forums) ? 'checked="checked"' : '', 'CHECKED_NOSHOW_FORUM' => in_array($row['forum_id'], $noshow_forums) ? 'checked="checked"' : '', 'S_IS_ADVANCED' => (bool) $row['similar_topic_forums'], 'U_ADVANCED' => "{$this->u_action}&action=advanced&f=" . $row['forum_id'], 'U_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']))); } break; } }