first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
iplookup info
-------------
1/ old plugins are not supported anymore
2/ general information in admin settings "Site Administration/Location/Location settings"
3/ technical info:
xplanet commadline
xplanet -projection rectangular -latitude 0.00 -longitude 0.00 -num_times 1 -geometry 620x310 -output earth.jpeg -quality 90 -config config.txt
config.txt
[earth]
shade=100
original Earth map from:
http://www.radcyberzine.com/xglobe/
marker.gif
custom made in Inkscape
Petr Skoda (skodak), January 2008
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+150
View File
@@ -0,0 +1,150 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 '<h1 class="iplookup h2">' . htmlspecialchars($title, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE) . '</h1>';
$mapdim = 'width: '
. (($width > 0) ? $width . 'px' : '100%')
. '; height: '
. (($height > 0) ? $height . 'px;' : '100%; min-height:360px;');
} else {
$mapdim = 'width:100%; height:100%;min-height:360px';
}
if (empty($CFG->googlemapkey3)) { // No Google API key is set, we use OSM.
// Have a fixed zoom factor to calculate corners of the map.
$fkt = 4;
$bboxleft = $info['longitude'] - $fkt;
$bboxbottom = $info['latitude'] - $fkt;
$bboxright = $info['longitude'] + $fkt;
$bboxtop = $info['latitude'] + $fkt;
echo '<div id="map" style="' . $mapdim . '">'
. '<object data="https://www.openstreetmap.org/export/embed.html?bbox='
. $bboxleft . '%2C' . $bboxbottom . '%2C' . $bboxright . '%2C' . $bboxtop
. '&layer=mapnik&marker=' . $info['latitude'] . '%2C' . $info['longitude'] . '" style="' . $mapdim . '"></object>'
. '</div>'
. '<div id="note">' . $info['note'] . '</div>';
} else { // Google API key is set, then use Google Maps.
$PAGE->requires->js(new moodle_url(
'https://maps.googleapis.com/maps/api/js',
[
'key' => $CFG->googlemapkey3,
'sensor' => 'false'
]
));
$module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
$PAGE->requires->js_init_call('M.core_iplookup.init3', [$info['latitude'], $info['longitude'], $ip], true, $module);
echo '<div id="map" style="' . $mapdim . '"></div>';
echo '<div id="note">'.$info['note'].'</div>';
}
echo $OUTPUT->footer();
+107
View File
@@ -0,0 +1,107 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* IP Lookup utility functions
*
* @package core
* @subpackage iplookup
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Returns location information
* @param string $ip
* @return array
*/
function iplookup_find_location($ip) {
global $CFG;
$info = array('city'=>null, 'country'=>null, 'longitude'=>null, 'latitude'=>null, 'error'=>null, 'note'=>'', 'title'=>array());
if (!empty($CFG->geoip2file) and file_exists($CFG->geoip2file)) {
$reader = new GeoIp2\Database\Reader($CFG->geoip2file);
$record = $reader->city($ip);
if (empty($record)) {
$info['error'] = get_string('iplookupfailed', 'error', $ip);
return $info;
}
$info['city'] = core_text::convert($record->city->name, 'iso-8859-1', 'utf-8');
$info['title'][] = $info['city'];
$countrycode = $record->country->isoCode;
$countries = get_string_manager()->get_list_of_countries(true);
if (isset($countries[$countrycode])) {
// Prefer our localized country names.
$info['country'] = $countries[$countrycode];
} else {
$info['country'] = $record->country->names['en'];
}
$info['title'][] = $info['country'];
$info['longitude'] = $record->location->longitude;
$info['latitude'] = $record->location->latitude;
$info['note'] = get_string('iplookupmaxmindnote', 'admin');
return $info;
} else {
require_once($CFG->libdir.'/filelib.php');
if (strpos($ip, ':') !== false) {
// IPv6 is not supported by geoplugin.net.
$info['error'] = get_string('invalidipformat', 'error');
return $info;
}
$ipdata = download_file_content('http://www.geoplugin.net/json.gp?ip='.$ip);
if ($ipdata) {
$ipdata = preg_replace('/^geoPlugin\((.*)\)\s*$/s', '$1', $ipdata);
$ipdata = json_decode($ipdata, true);
}
if (!is_array($ipdata)) {
$info['error'] = get_string('cannotgeoplugin', 'error');
return $info;
}
$info['latitude'] = (float)$ipdata['geoplugin_latitude'];
$info['longitude'] = (float)$ipdata['geoplugin_longitude'];
$info['city'] = s($ipdata['geoplugin_city']);
$info['accuracyRadius'] = (int)$ipdata['geoplugin_locationAccuracyRadius']; // Unit is in Miles.
$countrycode = $ipdata['geoplugin_countryCode'];
$countries = get_string_manager()->get_list_of_countries(true);
if (isset($countries[$countrycode])) {
// prefer our localized country names
$info['country'] = $countries[$countrycode];
} else {
$info['country'] = s($ipdata['geoplugin_countryName']);
}
$info['note'] = get_string('iplookupgeoplugin', 'admin');
$info['title'][] = $info['city'];
$info['title'][] = $info['country'];
return $info;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

+42
View File
@@ -0,0 +1,42 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Iplookup utility functions
*
* @package core_iplookup
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.core_iplookup = {};
M.core_iplookup.init3 = function(Y, latitude, longitude, ip) {
var ipLatlng = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
center: ipLatlng,
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marker = new google.maps.Marker({
position: ipLatlng,
map: map,
title: ip
});
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+10
View File
@@ -0,0 +1,10 @@
GeoIP2-City-Test.mmdb:
Copyright: maxmind (github.com/maxmind)
https://github.com/maxmind/MaxMind-DB/blob/master/test-data/GeoIP2-City-Test.mmdb
Licence: Creative Commons Attribution-ShareAlike 3.0 Unported License
http://creativecommons.org/licenses/by-sa/3.0/
No changes have been made to this file.
+85
View File
@@ -0,0 +1,85 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("{$CFG->libdir}/filelib.php");
require_once("{$CFG->dirroot}/iplookup/lib.php");
/**
* GeoIp data file parsing test.
*
* @package core
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class geoip_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
}
/**
* Setup the GeoIP2File system.
*/
public function setup_geoip2file() {
global $CFG;
$CFG->geoip2file = "$CFG->dirroot/iplookup/tests/fixtures/GeoIP2-City-Test.mmdb";
}
/**
* Test the format of data returned in the iplookup_find_location function.
*
* @dataProvider ip_provider
* @param string $ip The IP to test
*/
public function test_ip($ip): void {
$this->setup_geoip2file();
// Note: The results we get from the iplookup tests are beyond our control.
// We used to check a specific IP to a known location, but these have become less reliable and change too
// frequently to be used for testing.
$result = iplookup_find_location($ip);
$this->assertIsArray($result);
$this->assertIsFloat($result['latitude']);
$this->assertIsFloat($result['longitude']);
$this->assertIsString($result['city']);
$this->assertIsString($result['country']);
$this->assertIsArray($result['title']);
$this->assertIsString($result['title'][0]);
$this->assertIsString($result['title'][1]);
$this->assertNull($result['error']);
}
/**
* Data provider for IP lookup test.
*
* @return array
*/
public function ip_provider() {
return [
'IPv4: IPV4 test' => ['81.2.69.142'],
'IPv6: IPV6 test' => ['2001:252:1::1:1:1'],
];
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core;
/**
* GeoIp data file parsing test.
*
* @package core
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class geoplugin_test extends \advanced_testcase {
/**
* Load required test libraries
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once("{$CFG->dirroot}/iplookup/lib.php");
}
/**
* In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php
*/
public function setUp(): void {
if (!PHPUNIT_LONGTEST) {
$this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
}
}
/**
* Test IPv4 address
*
* @covers ::iplookup_find_location
*/
public function test_ipv4(): void {
$result = iplookup_find_location('50.0.184.0');
$this->assertIsArray($result);
$this->assertIsFloat($result['latitude']);
$this->assertIsFloat($result['longitude']);
$this->assertIsString($result['city']);
$this->assertIsString($result['country']);
$this->assertIsArray($result['title']);
$this->assertIsString($result['title'][0]);
$this->assertIsString($result['title'][1]);
$this->assertNull($result['error']);
}
/**
* Test IPv6 address (unsupported by Geoplugin)
*
* @covers ::iplookup_find_location
*/
public function test_ipv6(): void {
$result = iplookup_find_location('2a01:8900:2:3:8c6c:c0db:3d33:9ce6');
$this->assertEquals($result['error'], get_string('invalidipformat', 'error'));
}
}