New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/14830] Fix FORM_INVALID error during some ACP setting operations #4489

Merged
merged 8 commits into from Oct 28, 2016
@@ -597,13 +597,13 @@ function main($id, $mode)
if (!sizeof($error))
{
if (!check_form_key($form_key))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save)) || ($action == 'edit' && $save))
{
if (!check_form_key($form_key))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$this->save_profile_field($cp, $field_type, $action);
}
}
@@ -50,14 +50,12 @@ function main($id, $mode)
function settings($id, $mode)
{
global $db, $user, $auth, $template, $cache;
global $db, $user, $auth, $template, $cache, $request;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$submit = (isset($_POST['submit'])) ? true : false;
$form_key = 'acp_search';
add_form_key($form_key);
if ($submit && !check_form_key($form_key))
if ($submit && !check_link_hash($request->variable('hash', ''), 'acp_search'))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
@@ -233,7 +231,7 @@ function settings($id, $mode)
'S_YES_SEARCH' => (bool) $config['load_search'],
'S_SETTINGS' => true,
'U_ACTION' => $this->u_action)
'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'))
);
}
@@ -253,10 +251,7 @@ function index($id, $mode)
}
$submit = $request->is_set_post('submit', false);
$form_key = 'acp_search';
add_form_key($form_key);
if (!check_form_key($form_key) && in_array($action, array('delete', 'create')))
if (!check_link_hash($request->variable('hash', ''), 'acp_search') && in_array($action, array('create', 'delete')))
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
@@ -310,7 +305,7 @@ function index($id, $mode)
if (method_exists($this->search, 'delete_index'))
{
// pass a reference to myself so the $search object can make use of save_state() and attributes
if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete", false)))
if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false)))
{
$this->state = array('');
$this->save_state();
@@ -355,7 +350,7 @@ function index($id, $mode)
$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
$rows_per_second = $row_count / $totaltime;
meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter));
meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter, $rows_per_second));
}
}
@@ -445,7 +440,7 @@ function index($id, $mode)
$mtime = explode(' ', microtime());
$totaltime = $mtime[0] + $mtime[1] - $starttime;
$rows_per_second = $row_count / $totaltime;
meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter));
meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
}
}
@@ -524,7 +519,7 @@ function index($id, $mode)
$template->assign_vars(array(
'S_INDEX' => true,
'U_ACTION' => $this->u_action,
'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'),
'U_PROGRESS_BAR' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar"),
'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar")),
));
@@ -533,7 +528,7 @@ function index($id, $mode)
{
$template->assign_vars(array(
'S_CONTINUE_INDEXING' => $this->state[1],
'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[1],
'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[1] . '&hash=' . generate_link_hash('acp_search'),
'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
'L_CONTINUE_EXPLAIN' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
);
@@ -76,37 +76,33 @@ protected function create_search_index()
{
$this->add_lang('acp/search');
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$form_values = $crawler->selectButton('Delete index')->form()->getValues();
$crawler = self::request(
'POST',
'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid,
$form = $crawler->selectButton('Create index')->form();
$form_values = $form->getValues();
$form_values = array_merge($form_values,
array(
'search_type' => $this->search_backend,
'action' => 'create',
'submit' => true,
'form_token' => $form_values['form_token'],
'creation_time' => $form_values['creation_time'],
)
);
$form->setValues($form_values);
$crawler = self::submit($form);
$this->assertContainsLang('SEARCH_INDEX_CREATED', $crawler->text());
}
protected function delete_search_index()
{
$this->add_lang('acp/search');
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$form_values = $crawler->selectButton('Delete index')->form()->getValues();
$crawler = self::request(
'POST',
'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid,
$form = $crawler->selectButton('Delete index')->form();
$form_values = $form->getValues();
$form_values = array_merge($form_values,
array(
'search_type' => $this->search_backend,
'action' => 'delete',
'submit' => true,
'form_token' => $form_values['form_token'],
'creation_time' => $form_values['creation_time'],
)
);
$form->setValues($form_values);
$crawler = self::submit($form);
$this->assertContainsLang('SEARCH_INDEX_REMOVED', $crawler->text());
}
}
ProTip! Use n and p to navigate between commits in a pull request.