Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
online_whois
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\members\controller;
15
16use phpbb\auth\auth;
17use phpbb\db\driver\driver_interface;
18use phpbb\controller\helper;
19use phpbb\exception\http_exception;
20use phpbb\language\language;
21use phpbb\template\template;
22use phpbb\user;
23use Symfony\Component\HttpFoundation\Response;
24
25class online_whois
26{
27    /** @var auth */
28    protected $auth;
29
30    /** @var driver_interface */
31    protected $db;
32
33    /** @var helper */
34    protected $helper;
35
36    /** @var language */
37    protected $language;
38
39    /** @var template */
40    protected $template;
41
42    /** @var user */
43    protected $user;
44
45    /** @var string */
46    private $users_table;
47
48    /** @var string */
49    private $sessions_table;
50
51    /** @var string */
52    private $phpbb_root_path;
53
54    /** @var string */
55    private $php_ex;
56
57    /**
58     * online_whois constructor.
59     * @param auth $auth
60     * @param driver_interface $db
61     * @param helper $helper
62     * @param language $language
63     * @param template $template
64     * @param user $user
65     * @param string $users_table
66     * @param string $sessions_table
67     * @param string $phpbb_root_path
68     * @param string $php_ex
69     */
70    public function __construct(auth $auth, driver_interface $db, helper $helper, language $language, template $template, user $user, string $users_table, string $sessions_table, string $phpbb_root_path, string $php_ex)
71    {
72        $this->auth                = $auth;
73        $this->db                = $db;
74        $this->helper            = $helper;
75        $this->language            = $language;
76        $this->template            = $template;
77        $this->user                = $user;
78        $this->users_table        = $users_table;
79        $this->sessions_table    = $sessions_table;
80        $this->phpbb_root_path    = $phpbb_root_path;
81        $this->php_ex            = $php_ex;
82    }
83
84    /**
85     * Controller for /online/whois/{session_id} route
86     *
87     * @param $session_id
88     * @return Response a Symfony response object
89     */
90    public function handle($session_id): Response
91    {
92        if (!function_exists('user_ipwhois'))
93        {
94            include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ex);
95        }
96
97        // Load language strings
98        $this->language->add_lang('memberlist');
99
100        if (!$this->auth->acl_get('a_'))
101        {
102            $this->language->add_lang('acp/common');
103
104            throw new http_exception(403, 'NO_ADMIN');
105        }
106
107        $sql = 'SELECT u.user_id, u.username, u.user_type, s.session_ip
108            FROM ' . $this->users_table . ' u, ' . $this->sessions_table . " s
109            WHERE s.session_id = '" . $this->db->sql_escape($session_id) . "'
110                AND    u.user_id = s.session_user_id";
111        $result = $this->db->sql_query($sql);
112
113        if ($row = $this->db->sql_fetchrow($result))
114        {
115            $this->template->assign_var('WHOIS', user_ipwhois($row['session_ip']));
116        }
117        $this->db->sql_freeresult($result);
118
119        // Render
120        return $this->helper->render('viewonline_whois.html', $this->language->lang('WHO_IS_ONLINE'));
121    }
122}