Commit 7597bced by Scott

Controller: IP page

parent 4234de91
......@@ -438,7 +438,6 @@ function qa_page_routing()
'feedback' => 'pages/feedback.php',
'forgot' => 'pages/forgot.php',
'hot/' => 'pages/hot.php',
'ip/' => 'pages/ip.php',
'login' => 'pages/login.php',
'logout' => 'pages/logout.php',
'messages/' => 'pages/messages.php',
......@@ -474,6 +473,9 @@ function qa_routing_config()
$router->addRoute('user-blocked', 'get', 'users/blocked', '\Q2A\Controllers\User\UsersList', 'blocked');
$router->addRoute('user-new', 'get', 'users/new', '\Q2A\Controllers\User\UsersList', 'newest');
$router->addRoute('user-special', 'get', 'users/special', '\Q2A\Controllers\User\UsersList', 'special');
$router->addRoute('ip', 'get', 'ip/{str}', '\Q2A\Controllers\User\Ip', 'address');
$router->addRoute('ip', 'post', 'ip/{str}', '\Q2A\Controllers\User\Ip', 'address');
}
......
......@@ -3,9 +3,6 @@
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
Description: Controller for page showing recent activity for an IP address
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
......@@ -19,25 +16,34 @@
More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
namespace Q2A\Controllers\User;
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
use Q2A\Auth\NoPermissionException;
/**
* Controller for page showing recent activity for an IP address
*/
class Ip extends \Q2A\Controllers\BaseController
{
public function __construct()
{
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
parent::__construct();
}
$ip = qa_request_part(1); // picked up from qa-page.php
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
public function address($ip)
{
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
// Find recently (hidden, queued or not) questions, answers, comments and edits for this IP
// Find recently (hidden, queued or not) questions, answers, comments and edits for this IP
$userid = qa_get_logged_in_userid();
$userid = qa_get_logged_in_userid();
list($qs, $qs_queued, $qs_hidden, $a_qs, $a_queued_qs, $a_hidden_qs, $c_qs, $c_queued_qs, $c_hidden_qs, $edit_qs) =
list($qs, $qs_queued, $qs_hidden, $a_qs, $a_queued_qs, $a_hidden_qs, $c_qs, $c_queued_qs, $c_hidden_qs, $edit_qs) =
qa_db_select_with_pending(
qa_db_qs_selectspec($userid, 'created', 0, null, $ip, false),
qa_db_qs_selectspec($userid, 'created', 0, null, $ip, 'Q_QUEUED'),
......@@ -52,20 +58,18 @@ list($qs, $qs_queued, $qs_hidden, $a_qs, $a_queued_qs, $a_hidden_qs, $c_qs, $c_q
);
// Check we have permission to view this page, and whether we can block or unblock IPs
// Check we have permission to view this page, and whether we can block or unblock IPs
if (qa_user_maximum_permit_error('permit_anon_view_ips')) {
$qa_content = qa_content_prepare();
$qa_content['error'] = qa_lang_html('users/no_permission');
return $qa_content;
}
if (qa_user_maximum_permit_error('permit_anon_view_ips')) {
throw new NoPermissionException;
}
$blockable = qa_user_level_maximum() >= QA_USER_LEVEL_MODERATOR; // allow moderator in one category to block across all categories
$blockable = qa_user_level_maximum() >= QA_USER_LEVEL_MODERATOR; // allow moderator in one category to block across all categories
// Perform blocking or unblocking operations as appropriate
// Perform blocking or unblocking operations as appropriate
if (qa_clicked('doblock') || qa_clicked('dounblock') || qa_clicked('dohideall')) {
if (qa_clicked('doblock') || qa_clicked('dounblock') || qa_clicked('dohideall')) {
if (!qa_check_form_security_code('ip-' . $ip, qa_post_text('code')))
$pageerror = qa_lang_html('misc/form_security_again');
......@@ -114,26 +118,26 @@ if (qa_clicked('doblock') || qa_clicked('dounblock') || qa_clicked('dohideall'))
qa_redirect(qa_request());
}
}
}
}
// Combine sets of questions and get information for users
// Combine sets of questions and get information for users
$questions = qa_any_sort_by_date(array_merge($qs, $qs_queued, $qs_hidden, $a_qs, $a_queued_qs, $a_hidden_qs, $c_qs, $c_queued_qs, $c_hidden_qs, $edit_qs));
$questions = qa_any_sort_by_date(array_merge($qs, $qs_queued, $qs_hidden, $a_qs, $a_queued_qs, $a_hidden_qs, $c_qs, $c_queued_qs, $c_hidden_qs, $edit_qs));
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
$hostname = gethostbyaddr($ip);
$hostname = gethostbyaddr($ip);
// Prepare content for theme
// Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html_sub('main/ip_address_x', qa_html($ip));
$qa_content['error'] = @$pageerror;
$qa_content['title'] = qa_lang_html_sub('main/ip_address_x', qa_html($ip));
$qa_content['error'] = @$pageerror;
$qa_content['form'] = array(
$qa_content['form'] = array(
'tags' => 'method="post" action="' . qa_self_html() . '"',
'style' => 'wide',
......@@ -149,10 +153,10 @@ $qa_content['form'] = array(
'hidden' => array(
'code' => qa_get_form_security_code('ip-' . $ip),
),
);
);
if ($blockable) {
if ($blockable) {
require_once QA_INCLUDE_DIR . 'app/limits.php';
$blockipclauses = qa_block_ips_explode(qa_opt('block_ips_write'));
......@@ -187,12 +191,12 @@ if ($blockable) {
'label' => qa_lang_html('misc/block_ip_button'),
);
}
}
}
$qa_content['q_list']['qs'] = array();
$qa_content['q_list']['qs'] = array();
if (count($questions)) {
if (count($questions)) {
$qa_content['q_list']['title'] = qa_lang_html_sub('misc/recent_activity_from_x', qa_html($ip));
foreach ($questions as $question) {
......@@ -224,8 +228,10 @@ if (count($questions)) {
$qa_content['q_list']['qs'][] = $htmlfields;
}
} else
} else
$qa_content['q_list']['title'] = qa_lang_html_sub('misc/no_activity_from_x', qa_html($ip));
return $qa_content;
return $qa_content;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment