Mini Shell
3
C��e�z � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZddl m
Z
ddlmZm
Z
ee�Ze
� ZddlmZ ddlmZ ddlmZmZ dd lmZmZ dd
lmZ ejejhZG dd� de �Z!G d
d� de �Z"G dd� de �Z#G dd� de �Z$G dd� de$�Z%G dd� de$�Z&G dd� de$�Z'G dd� de �Z(G dd� de �Z)G dd� de �Z*G dd � d e �Z+G d!d"� d"e �Z,da-d#d$� Z.dS )%a�
A GeoIP and WiFi location module - location detection based on IP address
How to use the geolocation module
First call init_geolocation() with appropriate parameters - this creates
the Geolocation singleton and specifies what geolocation provider will be
used.
To actually look up current position, call the refresh() function of the
singleton, this will trigger the actual online geolocation query, which
runs in a thread.
It's possible to wait for the lookup to finish by calling the
wait_for_refresh_to_finish() method of the singleton. If a lookup is in
progress it will block until the lookup finishes or a timeout is reached.
If no lookup is in progress it will return at once.
After the look-up thread finishes, the results are stored in the singleton
and can be retrieved using the territory, timezone and result properties.
If you use these properties without calling refresh() first or if the
look-up is currently in progress or failed to return any results, all
properties will return None.
====================
Geolocation backends
====================
This module currently supports three geolocation backends:
* Fedora GeoIP API
* Hostip GeoIP
* Google WiFi
Fedora GeoIP backend
This is the default backend. It queries the Fedora GeoIP API for location
data based on current public IP address. The reply is JSON formatted and
contains the following fields:
postal_code, latitude, longitude, region, city, country_code, country_name,
time_zone, country_code3, area_code, metro_code, region_name and dma_code
Anaconda currently uses just time_zone and country_code.
Hostip backend
A GeoIP look-up backend that can be used to determine current country code
from current public IP address. The public IP address is determined
automatically when calling the API.
GeoIP results from Hostip contain the current public IP and an approximate
address. To get this detail location info, use the result property to get
an instance of the LocationResult class, used to wrap the lookup result.
Google WiFi backend
This backend is probably the most accurate one, at least as long as the
computer has a working WiFi hardware and there are some WiFi APs nearby.
It sends data about nearby APs (ssid, MAC address & signal strength)
acquired from Network Manager to a Google API to get approximate
geographic coordinates. If there are enough AP nearby (such as in a
normal city) it can be very accurate, even up to currently determining
which building is the computer currently in.
But this only returns current geographic coordinates, to get country code
the Nominatim reverse-geocoding API is called to convert the coordinates
to an address, which includes a country code.
While having many advantages, this backend also has some severe disadvantages:
* needs working WiFi hardware
* tells your public IP address & possibly quite precise geographic coordinates
to two external entities (Google and Nominatim)
This could have severe privacy issues and should be carefully considered before
enabling it to be used by default. Also the Google WiFi geolocation API seems to
lack official documentation.
As a result its long-term stability might not be guaranteed.
Possible issues with GeoIP
"I'm in Switzerland connected to corporate VPN and anaconda tells me
I'm in the Netherlands."
The public IP address is not directly mapped to the physical location
of a computer. So while your world visible IP address is registered to
an IP block assigned to an ISP in Netherlands, it is just the external
address of the Internet gateway of your corporate network.
As VPNs and proxies can connect two computers anywhere on Earth,
this issue is unfortunately probably unsolvable.
Backends that could possibly be used in the future
* GPS geolocation
* (+) doesn't leak your coordinates to a third party
(not entirely true for assisted GPS)
* (-) unassisted cold GPS startup can take tens of minutes to acquire a GPS fix
* (+) assisted GPS startup (as used in most smartphones) can acquire a fix
in a couple seconds
* cell tower geolocation
� )�requests_sessionN)�network)�get_module_logger�get_sensitive_info_logger)� constants)�conf)�AnacondaThread� threadMgr)�get_preferred_timezone�is_valid_timezone)�flagsc @ sX e Zd ZdZddd�Zdd� Zdd � Zejfd
d�Z e
dd
� �Ze
dd� �Zdd� Z
dS )�GeolocationzTop level geolocation handler.NFc C sV | j ||�| _tj}|dk rF| jrF| j|�}|dkrBtjd|� n|}t|d�| _dS )a Prepare the geolocation module for handling geolocation queries.
This sets-up the Geolocation instance with the given geolocation_provider (or using the
default one if no provider is given. Please note that calling this method doesn't actually
execute any queries by itself, you need to call refresh() to do that.
:param geoloc_option: what was passed in boot or command line options
:type geoloc_option: str or None
:param options_override:
:type options_override: bool
Nz'geoloc: wrong provider id specified: %s)�provider_id) �$_check_if_geolocation_should_be_used�_geolocation_enabledr �GEOLOC_DEFAULT_PROVIDER�_get_provider_id_from_option�log�error�LocationInfo�_location_info)�self�
geoloc_option�options_overrider Z parsed_id� r �/usr/lib64/python3.6/geoloc.py�__init__� s
zGeolocation.__init__c C sh t jjstjd� dS t|�j� dkr4tjd� dS tjrZ|rLtjd� dS tjd� dS tjd� dS ) a~ Check if geolocation can be used during this installation run.
And set the geolocation_enabled module attribute accordingly.
The result is based on current installation type - fully interactive vs
fully or partially automated kickstart installation and on the state of the
"geoloc*" boot/CLI options.
By default geolocation is not enabled during a kickstart based installation,
unless the geoloc_use_with_ks boot/CLI option is used.
Also the geoloc boot/CLI option can be used to make sure geolocation
will not be used during an installation, like this:
inst.geoloc=0
:param geoloc_option: what was passed in boot or command line options
:type geoloc_option: str or None
:param options_override: use with kickstart due to CLI/boot option override
:type options_override: bool
z<Geolocation is disabled for image or directory installation.F�0z-Geolocation is disabled by the geoloc option.zaGeolocation is enabled during kickstart installation due to use of the geoloc-use-with-ks option.TzFGeolocation is disabled due to automated kickstart based installation.zGeolocation is enabled.) r �targetZis_hardwarer �info�str�stripr ZautomatedInstall)r r r r r r r � s
z0Geolocation._check_if_geolocation_should_be_usedc C s | j j� dS )z+Refresh information about current location.N)r �refresh)r r r r r"