. /** * Displays IP address on map. * * This script is not compatible with IPv6. * * @package core_iplookup * @copyright 2008 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require('../config.php'); require_once('lib.php'); require_login(0, false); if (isguestuser()) { // Guest users cannot perform lookups. throw new require_login_exception('Guests are not allowed here.'); } $ip = optional_param('ip', getremoteaddr(), PARAM_RAW); $user = optional_param('user', 0, PARAM_INT); $width = optional_param('width', 0, PARAM_INT); $height = optional_param('height', 0, PARAM_INT); $ispopup = optional_param('popup', 0, PARAM_INT); if (isset($CFG->iplookup)) { // Clean up of old settings. set_config('iplookup', NULL); } $urlparams = [ 'id' => $ip, 'user' => $user, ]; // Params width and height are set, we assume to have a popup. if ($width > 0 && $height > 0) { $urlparams['width'] = $width; $urlparams['height'] = $height; $ispopup = 1; } else if ($ispopup === 1) { // Param popup was set, then we know that we want a popup. $urlparams['ispopup'] = 1; } // Set the page layout accordingly. if ($ispopup) { $PAGE->set_pagelayout('popup'); } else { $PAGE->set_pagelayout('standard'); } $PAGE->set_url('/iplookup/index.php', $urlparams); $PAGE->set_context(context_system::instance()); $info = array($ip); $note = array(); if (cleanremoteaddr($ip) === false) { throw new \moodle_exception('invalidipformat', 'error'); } if (!ip_is_public($ip)) { throw new \moodle_exception('iplookupprivate', 'error'); } $info = iplookup_find_location($ip); if ($info['error']) { // Can not display. notice($info['error']); } if ($user) { if ($user = $DB->get_record('user', array('id'=>$user, 'deleted'=>0))) { // note: better not show full names to everybody if (has_capability('moodle/user:viewdetails', context_user::instance($user->id))) { array_unshift($info['title'], fullname($user)); } } } $title = $ip; foreach ($info['title'] as $component) { if (!empty(trim($component))) { $title .= ' - ' . $component; } } $PAGE->set_title(get_string('iplookup', 'admin').': '.$title); $PAGE->set_heading($title); echo $OUTPUT->header(); // The map dimension is here as big as the popup/page is, so max with and at least 360px height. if ($ispopup) { echo '