Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-63759

Replace geoip lookup with openstreetmap

XMLWordPrintable

    • MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_401_STABLE
    • MOODLE_403_STABLE
    • MDL-63759-master
    • Hide

      Setup

      • In the config.php empty the values for
      • $CFG->geoip2file
      • $CFG->googlemapkey3

      in case these are set.

      Test 1

       - Call the URL http://localhost:8000/iplookup/index.php?ip=<ip> (replace the domain name with your setup) and replace the <ip> token with these 3 IPs

      1. 207.97.177.83
      2. 129.13.157.23
      3. 24.232.170.30

      Expected result:

      1. The map displays the US east coast and a place in New York (zoom in to verify this)
      2. The map displayes a small sample in the north of Karlsruhe, Germany, the marker is placed in Graben Neudorf (you still should see Karlsruhe at the lower edge).
      3. The map displayes square streets of a city, the marker is placed at an intersection. When zooming out, you should see that you are in the center of Villa María, Cordoba, Argentina.

      Verify that you can see the detailed information at the top of the page. Example:  207.97.177.83 - New York - United States 

      If the output differs (that should not happen) you may verify that the location shown in Moodle reflects the data that the geo service returned. Use the following curl call to check the raw output (here with a sample IP from the test set):

       

      curl -i --url 'http://www.geoplugin.net/json.gp?ip=24.232.170.30'

       

      Test 2

      Call the following URLs (again adjust your domain):

      Expected result: the map is displayed exactly in this size as provided by the params. Note that the zoom factor differs because it's calculation depends on the with and height of the map.

      Show
      Setup In the config.php empty the values for $CFG->geoip2file $CFG->googlemapkey3 in case these are set. Test 1  - Call the URL http://localhost:8000/iplookup/index.php?ip= <ip> (replace the domain name with your setup) and replace the <ip> token with these 3 IPs 207.97.177.83 129.13.157.23 24.232.170.30 Expected result: The map displays the US east coast and a place in New York (zoom in to verify this) The map displayes a small sample in the north of Karlsruhe, Germany, the marker is placed in Graben Neudorf (you still should see Karlsruhe at the lower edge). The map displayes square streets of a city, the marker is placed at an intersection. When zooming out, you should see that you are in the center of Villa María, Cordoba, Argentina. Verify that you can see the detailed information at the top of the page. Example:  207.97.177.83 - New York - United States  If the output differs (that should not happen) you may verify that the location shown in Moodle reflects the data that the geo service returned. Use the following curl call to check the raw output (here with a sample IP from the test set):   curl -i --url 'http://www.geoplugin.net/json.gp?ip=24.232.170.30'   Test 2 Call the following URLs (again adjust your domain): http://localhost:8000/iplookup/index.php?ip=207.97.177.83&width=900&height=600 http://localhost:8000/iplookup/index.php?ip=207.97.177.83&width=400&height=800 Expected result : the map is displayed exactly in this size as provided by the params. Note that the zoom factor differs because it's calculation depends on the with and height of the map.

      Hi,

      I would like to propose a quick enhancement code for iplookup/index.php.

      In the code there is 2 ways to show geoip lookup, on a static image or on a google maps if you have api keys. This way we can use openstreetmap-based maps instead of google.

      To achieve this we can replace google maps code to this code:

      Old code:

       

      if (is_https()) {
          $PAGE->requires->js(new moodle_url('https://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false')));
      } else {
          $PAGE->requires->js(new moodle_url('http://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false')));
      }
       
      $module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
      $PAGE->requires->js_init_call('M.core_iplookup.init3', array($info['latitude'], $info['longitude'], $ip), true, $module);
      echo '<div id="map" style="width: 650px; height: 360px"></div>';
      echo '<div id="note">'.$info['note'].'</div>';
      

      New code:

       

      $lon = $info['longitude'];
      $lat = $info['latitude'];
      	
      //bounding box calculation to set the initial "zoom level" on the map:
       
      $bboxleft = $lon-1.8270;
      $bboxbottom = $lat-1.0962;
      $bboxright =  $lon+1.8270;
      $bboxtop =  $lat+1.0962;
      	
      echo '<div id="map" style="width: 610px; height: 310px">';	
      echo '<object data="https://www.openstreetmap.org/export/embed.html?bbox='.$bboxleft.'%2C'.$bboxbottom.'%2C'.$bboxright.'%2C'.$bboxtop.'&layer=mapnik&marker='.$lat.'%2C'.$lon.'" width="100%" height="100%"></object>';
      echo '</div>';
      echo '<div id="note">'.$info['note'].'</div>';
      

      To test my version all you need is to write something into the api key field at admin -> settings -> location settings.

      I also attached the whole php file for evaluation.

      What is your thoughts?

      Peter

       

       

        1. (I) Passed -- (Master)MDL-63759.png
          (I) Passed -- (Master)MDL-63759.png
          140 kB
        2. (II) Passed -- (Master)MDL-63759.png
          (II) Passed -- (Master)MDL-63759.png
          358 kB
        3. geoip.PNG
          geoip.PNG
          180 kB
        4. image-2023-05-24-10-15-46-902.png
          image-2023-05-24-10-15-46-902.png
          729 kB
        5. image-2023-05-24-10-15-58-981.png
          image-2023-05-24-10-15-58-981.png
          729 kB
        6. index.php
          4 kB

            strobotta Stephan Robotta
            péterlukács Péter Lukács
            Luca Bösch Luca Bösch
            Huong Nguyen Huong Nguyen
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            3 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.