mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Remove all MaxMind/GeoLite2 settings
This commit is contained in:
parent
ccac7d1bd4
commit
9b11fd4f18
8 changed files with 5 additions and 320 deletions
10
API.md
10
API.md
|
@ -672,7 +672,7 @@ Returns:
|
||||||
|
|
||||||
|
|
||||||
### get_geoip_lookup
|
### get_geoip_lookup
|
||||||
Get the geolocation info for an IP address. The GeoLite2 database must be installed.
|
Get the geolocation info for an IP address.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
|
@ -2571,10 +2571,6 @@ Returns:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### install_geoip_db
|
|
||||||
Downloads and installs the GeoLite2 database
|
|
||||||
|
|
||||||
|
|
||||||
### notify
|
### notify
|
||||||
Send a notification using Tautulli.
|
Send a notification using Tautulli.
|
||||||
|
|
||||||
|
@ -2851,10 +2847,6 @@ Returns:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### uninstall_geoip_db
|
|
||||||
Uninstalls the GeoLite2 database
|
|
||||||
|
|
||||||
|
|
||||||
### update
|
### update
|
||||||
Update Tautulli.
|
Update Tautulli.
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<% from plexpy.helpers import anon_url %>
|
|
||||||
<span class="text-muted">GeoLite2 data created by <a href="${anon_url('http://www.maxmind.com')}" target="_blank">MaxMind</a>.</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1268,7 +1268,7 @@
|
||||||
<p class="help-block">Enable to lookup links to MusicBrainz for music when available.</p>
|
<p class="help-block">Enable to lookup links to MusicBrainz for music when available.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="maxmind_license_key">Delete Lookup Info</label>
|
<label for="delete_lookup_info">Delete Lookup Info</label>
|
||||||
<p class="help-block">Delete all cached metadata lookup info in Tautulli.</p>
|
<p class="help-block">Delete all cached metadata lookup info in Tautulli.</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
|
@ -1281,54 +1281,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="padded-header">
|
|
||||||
<h3>Geolocation Database</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="help-block">The GeoLite2 database is used to geolocate IP addresses.</p>
|
|
||||||
<p class="help-block">
|
|
||||||
Please see the <a target='_blank' href='${anon_url('https://github.com/%s/%s-Wiki/wiki/3rd-Party-APIs-Guide' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO))}'>3rd Party APIs Guide</a> for instructions on setting up MaxMind.<br>
|
|
||||||
</p>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="maxmind_license_key">MaxMind License Key</label>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<input type="text" class="form-control" id="maxmind_license_key" name="maxmind_license_key" value="${config['maxmind_license_key']}" data-parsley-trigger="change">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="help-block">
|
|
||||||
Enter your MaxMind License Key to install the GeoLite2 database.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="geoip_db">GeoLite2 Database File</label> ${docker_msg | n}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-9">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" class="form-control" id="geoip_db" name="geoip_db" value="${config['geoip_db']}" ${docker_setting} data-parsley-trigger="change" data-parsley-pattern=".+\.mmdb$" data-parsley-errors-container="#geoip_db_error" data-parsley-error-message="Must end with '.mmdb'">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button class="btn btn-form" type="button" id="install_geoip_db">${'Update' if config["geoip_db_installed"] else 'Install'}</button>
|
|
||||||
<button class="btn btn-form" type="button" id="uninstall_geoip_db" ${'disabled' if not config['geoip_db_installed'] else ''}>Uninstall</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="geoip_db_error" class="alert alert-danger settings-alert" role="alert"></div>
|
|
||||||
</div>
|
|
||||||
<p class="help-block">
|
|
||||||
Leave blank to install in the default location. GeoLite2 database last updated <strong><span id="geoip_db_updated">never</span></strong>.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="form-group advanced-setting">
|
|
||||||
<label for="geoip_db_update_days">GeoLite2 Database Update Interval</label>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-2">
|
|
||||||
<input type="text" class="form-control" data-parsley-type="integer" id="geoip_db_update_days" name="geoip_db_update_days" value="${config['geoip_db_update_days']}" size="5" data-parsley-range="[7, 30]" data-parsley-trigger="change" data-parsley-errors-container="#geoip_db_update_days_error" required>
|
|
||||||
</div>
|
|
||||||
<div id="geoip_db_update_days_error" class="alert alert-danger settings-alert" role="alert"></div>
|
|
||||||
</div>
|
|
||||||
<p class="help-block">The interval (in days) Tautulli will automatically update the GeoLite2 database. Minimum 7, maximum 30, default 30.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -2942,56 +2894,6 @@ $(document).ready(function() {
|
||||||
$('#resources-xml').on('tripleclick', function () {
|
$('#resources-xml').on('tripleclick', function () {
|
||||||
openPlexXML('/api/resources', true, {includeHttps: 1});
|
openPlexXML('/api/resources', true, {includeHttps: 1});
|
||||||
});
|
});
|
||||||
|
|
||||||
if ("${kwargs.get('install_geoip')}" === 'true') {
|
|
||||||
gotoSetting('3rd_party_apis', 'geoip_db')
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("${config['geoip_db_installed']}" > "0") {
|
|
||||||
$("#geoip_db_updated").text(moment("${config['geoip_db_installed']}", "X").fromNow());
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#install_geoip_db").click(function () {
|
|
||||||
var maxmind_license_key = $("#maxmind_license_key");
|
|
||||||
maxmind_license_key.val($.trim(maxmind_license_key.val()));
|
|
||||||
if (maxmind_license_key.val() === "") {
|
|
||||||
maxmind_license_key.focus();
|
|
||||||
showMsg('<i class="fa fa-exclamation-circle"></i> Maxmind License Key is required.', false, true, 5000, true);
|
|
||||||
return false;
|
|
||||||
} else if (!(saveSettings())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var msg = 'Are you sure you want to install the GeoLite2 database?<br /><br />' +
|
|
||||||
'The database is used to lookup IP address geolocation info.<br />' +
|
|
||||||
'The database will be downloaded from <a href="${anon_url("https://dev.maxmind.com/geoip/geoip2/geolite2/")}" target="_blank">MaxMind</a>, <br />' +
|
|
||||||
'and requires <strong>100MB</strong> of free space to install.<br />';
|
|
||||||
var url = 'install_geoip_db';
|
|
||||||
if ($(this).text() === 'Update') {
|
|
||||||
url += '?update=true';
|
|
||||||
}
|
|
||||||
confirmAjaxCall(url, msg, null, 'Installing GeoLite2 database.', function (result) {
|
|
||||||
if (result.result === "success") {
|
|
||||||
$('#install_geoip_db').text('Update');
|
|
||||||
$('#uninstall_geoip_db').prop('disabled', false);
|
|
||||||
$('#geoip_db_updated').text(moment(result.updated, "X").fromNow());
|
|
||||||
}
|
|
||||||
getSchedulerTable();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#uninstall_geoip_db").click(function () {
|
|
||||||
var msg = 'Are you sure you want to uninstall the GeoLite2 database?<br /><br />' +
|
|
||||||
'You will not be able to lookup IP address geolocation info.';
|
|
||||||
var url = 'uninstall_geoip_db';
|
|
||||||
confirmAjaxCall(url, msg, null, 'Uninstalling GeoLite2 database.', function (result) {
|
|
||||||
if (result.result === "success") {
|
|
||||||
$('#install_geoip_db').text('Install');
|
|
||||||
$('#uninstall_geoip_db').prop('disabled', true);
|
|
||||||
$('#geoip_db_updated').text('never');
|
|
||||||
}
|
|
||||||
getSchedulerTable();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -450,8 +450,6 @@ def initialize_scheduler():
|
||||||
hours=backup_hours, minutes=0, seconds=0, args=(True, True))
|
hours=backup_hours, minutes=0, seconds=0, args=(True, True))
|
||||||
schedule_job(config.make_backup, 'Backup Tautulli config',
|
schedule_job(config.make_backup, 'Backup Tautulli config',
|
||||||
hours=backup_hours, minutes=0, seconds=0, args=(True, True))
|
hours=backup_hours, minutes=0, seconds=0, args=(True, True))
|
||||||
schedule_job(helpers.update_geoip_db, 'Update GeoLite2 database',
|
|
||||||
hours=12 * bool(CONFIG.GEOIP_DB_INSTALLED), minutes=0, seconds=0)
|
|
||||||
|
|
||||||
if WS_CONNECTED and CONFIG.PMS_IP and CONFIG.PMS_TOKEN:
|
if WS_CONNECTED and CONFIG.PMS_IP and CONFIG.PMS_TOKEN:
|
||||||
schedule_job(plextv.get_server_resources, 'Refresh Plex server URLs',
|
schedule_job(plextv.get_server_resources, 'Refresh Plex server URLs',
|
||||||
|
|
|
@ -214,8 +214,7 @@ SCHEDULER_LIST = [
|
||||||
'Refresh libraries list',
|
'Refresh libraries list',
|
||||||
'Refresh Plex server URLs',
|
'Refresh Plex server URLs',
|
||||||
'Backup Tautulli database',
|
'Backup Tautulli database',
|
||||||
'Backup Tautulli config',
|
'Backup Tautulli config'
|
||||||
'Update GeoLite2 database'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
DATE_TIME_FORMATS = [
|
DATE_TIME_FORMATS = [
|
||||||
|
|
|
@ -175,9 +175,6 @@ _CONFIG_DEFINITIONS = {
|
||||||
'FACEBOOK_ON_NEWDEVICE': (int, 'Facebook', 0),
|
'FACEBOOK_ON_NEWDEVICE': (int, 'Facebook', 0),
|
||||||
'FIRST_RUN_COMPLETE': (int, 'General', 0),
|
'FIRST_RUN_COMPLETE': (int, 'General', 0),
|
||||||
'FREEZE_DB': (int, 'General', 0),
|
'FREEZE_DB': (int, 'General', 0),
|
||||||
'GEOIP_DB': (str, 'General', ''),
|
|
||||||
'GEOIP_DB_INSTALLED': (int, 'General', 0),
|
|
||||||
'GEOIP_DB_UPDATE_DAYS': (int, 'General', 30),
|
|
||||||
'GET_FILE_SIZES': (int, 'General', 0),
|
'GET_FILE_SIZES': (int, 'General', 0),
|
||||||
'GET_FILE_SIZES_HOLD': (dict, 'General', {'section_ids': [], 'rating_keys': []}),
|
'GET_FILE_SIZES_HOLD': (dict, 'General', {'section_ids': [], 'rating_keys': []}),
|
||||||
'GIT_BRANCH': (str, 'General', 'master'),
|
'GIT_BRANCH': (str, 'General', 'master'),
|
||||||
|
@ -292,7 +289,6 @@ _CONFIG_DEFINITIONS = {
|
||||||
'LOG_BLACKLIST': (int, 'General', 1),
|
'LOG_BLACKLIST': (int, 'General', 1),
|
||||||
'LOG_DIR': (str, 'General', ''),
|
'LOG_DIR': (str, 'General', ''),
|
||||||
'LOGGING_IGNORE_INTERVAL': (int, 'Monitoring', 120),
|
'LOGGING_IGNORE_INTERVAL': (int, 'Monitoring', 120),
|
||||||
'MAXMIND_LICENSE_KEY': (str, 'General', ''),
|
|
||||||
'METADATA_CACHE_SECONDS': (int, 'Advanced', 1800),
|
'METADATA_CACHE_SECONDS': (int, 'Advanced', 1800),
|
||||||
'MOVIE_LOGGING_ENABLE': (int, 'Monitoring', 1),
|
'MOVIE_LOGGING_ENABLE': (int, 'Monitoring', 1),
|
||||||
'MOVIE_NOTIFY_ENABLE': (int, 'Monitoring', 0),
|
'MOVIE_NOTIFY_ENABLE': (int, 'Monitoring', 0),
|
||||||
|
@ -932,8 +928,6 @@ class Config(object):
|
||||||
self.CONFIG_VERSION = 13
|
self.CONFIG_VERSION = 13
|
||||||
|
|
||||||
if self.CONFIG_VERSION == 13:
|
if self.CONFIG_VERSION == 13:
|
||||||
if not self.GEOIP_DB:
|
|
||||||
self.GEOIP_DB = os.path.join(plexpy.DATA_DIR, 'GeoLite2-City.mmdb')
|
|
||||||
|
|
||||||
self.CONFIG_VERSION = 14
|
self.CONFIG_VERSION = 14
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,12 @@
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import base64
|
import base64
|
||||||
import certifi
|
|
||||||
import cloudinary
|
import cloudinary
|
||||||
from cloudinary.api import delete_resources_by_tag
|
from cloudinary.api import delete_resources_by_tag
|
||||||
from cloudinary.uploader import upload
|
from cloudinary.uploader import upload
|
||||||
from cloudinary.utils import cloudinary_url
|
from cloudinary.utils import cloudinary_url
|
||||||
import datetime
|
import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import geoip2.database, geoip2.errors
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import imghdr
|
import imghdr
|
||||||
from itertools import izip_longest
|
from itertools import izip_longest
|
||||||
|
@ -30,19 +28,15 @@ import ipwhois, ipwhois.exceptions, ipwhois.utils
|
||||||
from IPy import IP
|
from IPy import IP
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import maxminddb
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import urllib
|
import urllib
|
||||||
import urllib3
|
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
|
@ -607,164 +601,6 @@ def is_valid_ip(address):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def update_geoip_db():
|
|
||||||
if plexpy.CONFIG.GEOIP_DB_INSTALLED:
|
|
||||||
logger.info(u"Tautulli Helpers :: Checking for GeoLite2 database updates.")
|
|
||||||
now = int(time.time())
|
|
||||||
if now - plexpy.CONFIG.GEOIP_DB_INSTALLED >= plexpy.CONFIG.GEOIP_DB_UPDATE_DAYS * 24 * 60 * 60:
|
|
||||||
return install_geoip_db(update=True)
|
|
||||||
logger.info(u"Tautulli Helpers :: GeoLite2 database already updated within the last %s days."
|
|
||||||
% plexpy.CONFIG.GEOIP_DB_UPDATE_DAYS)
|
|
||||||
|
|
||||||
|
|
||||||
def install_geoip_db(update=False):
|
|
||||||
if not plexpy.CONFIG.MAXMIND_LICENSE_KEY:
|
|
||||||
logger.error(u"Tautulli Helpers :: Failed to download GeoLite2 database file from MaxMind: Missing MaxMindLicense Key")
|
|
||||||
return False
|
|
||||||
|
|
||||||
maxmind_db = 'GeoLite2-City'
|
|
||||||
maxmind_url = 'https://download.maxmind.com/app/geoip_download?edition_id={db}&suffix={{suffix}}&license_key={key}'.format(
|
|
||||||
db=maxmind_db, key=plexpy.CONFIG.MAXMIND_LICENSE_KEY)
|
|
||||||
geolite2_db_url = maxmind_url.format(suffix='tar.gz')
|
|
||||||
geolite2_md5_url = maxmind_url.format(suffix='tar.gz.md5')
|
|
||||||
geolite2_gz = maxmind_db + '.tar.gz'
|
|
||||||
geolite2_md5 = geolite2_gz + '.md5'
|
|
||||||
geolite2_db = maxmind_db + '.mmdb'
|
|
||||||
geolite2_db_path = plexpy.CONFIG.GEOIP_DB or os.path.join(plexpy.DATA_DIR, geolite2_db)
|
|
||||||
|
|
||||||
# Check path ends with .mmdb
|
|
||||||
if os.path.splitext(geolite2_db_path)[1] != os.path.splitext(geolite2_db)[1]:
|
|
||||||
geolite2_db_path = os.path.join(geolite2_db_path, geolite2_db)
|
|
||||||
|
|
||||||
temp_gz = os.path.join(plexpy.CONFIG.CACHE_DIR, geolite2_gz)
|
|
||||||
temp_md5 = os.path.join(plexpy.CONFIG.CACHE_DIR, geolite2_md5)
|
|
||||||
|
|
||||||
# Retrieve the GeoLite2 gzip file
|
|
||||||
logger.debug(u"Tautulli Helpers :: Downloading GeoLite2 gzip file from MaxMind...")
|
|
||||||
try:
|
|
||||||
maxmind = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
|
|
||||||
with maxmind.request('GET', geolite2_db_url, preload_content=False) as r_db, open(temp_gz, 'wb') as f_db:
|
|
||||||
shutil.copyfileobj(r_db, f_db)
|
|
||||||
with maxmind.request('GET', geolite2_md5_url, preload_content=False) as r_md5, open(temp_md5, 'wb') as f_md5:
|
|
||||||
shutil.copyfileobj(r_md5, f_md5)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(u"Tautulli Helpers :: Failed to download GeoLite2 gzip file from MaxMind: %s" % e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Check MD5 hash for GeoLite2 tar.gz file
|
|
||||||
logger.debug(u"Tautulli Helpers :: Checking MD5 checksum for GeoLite2 gzip file...")
|
|
||||||
try:
|
|
||||||
hash_md5 = hashlib.md5()
|
|
||||||
with open(temp_gz, 'rb') as f:
|
|
||||||
for chunk in iter(lambda: f.read(4096), b""):
|
|
||||||
hash_md5.update(chunk)
|
|
||||||
md5_hash = hash_md5.hexdigest()
|
|
||||||
|
|
||||||
with open(temp_md5, 'r') as f:
|
|
||||||
md5_checksum = f.read()
|
|
||||||
|
|
||||||
if md5_hash != md5_checksum:
|
|
||||||
logger.error(u"Tautulli Helpers :: MD5 checksum doesn't match for GeoLite2 database. "
|
|
||||||
"Checksum: %s, file hash: %s" % (md5_checksum, md5_hash))
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(u"Tautulli Helpers :: Failed to generate MD5 checksum for GeoLite2 gzip file: %s" % e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Extract the GeoLite2 database file
|
|
||||||
logger.debug(u"Tautulli Helpers :: Extracting GeoLite2 database...")
|
|
||||||
try:
|
|
||||||
mmdb = None
|
|
||||||
with tarfile.open(temp_gz, 'r:gz') as tar:
|
|
||||||
for member in tar.getmembers():
|
|
||||||
if geolite2_db in member.name:
|
|
||||||
member.name = os.path.basename(member.name)
|
|
||||||
tar.extractall(path=os.path.dirname(geolite2_db_path), members=[member])
|
|
||||||
mmdb = True
|
|
||||||
break
|
|
||||||
if not mmdb:
|
|
||||||
raise Exception("{} not found in gzip file.".format(geolite2_db))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(u"Tautulli Helpers :: Failed to extract the GeoLite2 database: %s" % e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Delete temportary GeoLite2 gzip file
|
|
||||||
logger.debug(u"Tautulli Helpers :: Deleting temporary GeoLite2 gzip file...")
|
|
||||||
try:
|
|
||||||
os.remove(temp_gz)
|
|
||||||
os.remove(temp_md5)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn(u"Tautulli Helpers :: Failed to remove temporary GeoLite2 gzip file: %s" % e)
|
|
||||||
|
|
||||||
plexpy.CONFIG.__setattr__('GEOIP_DB', geolite2_db_path)
|
|
||||||
plexpy.CONFIG.__setattr__('GEOIP_DB_INSTALLED', int(time.time()))
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
|
|
||||||
logger.debug(u"Tautulli Helpers :: GeoLite2 database installed successfully.")
|
|
||||||
|
|
||||||
if not update:
|
|
||||||
plexpy.schedule_job(update_geoip_db, 'Update GeoLite2 database', hours=12, minutes=0, seconds=0)
|
|
||||||
|
|
||||||
return plexpy.CONFIG.GEOIP_DB_INSTALLED
|
|
||||||
|
|
||||||
|
|
||||||
def uninstall_geoip_db():
|
|
||||||
logger.debug(u"Tautulli Helpers :: Uninstalling the GeoLite2 database...")
|
|
||||||
try:
|
|
||||||
os.remove(plexpy.CONFIG.GEOIP_DB)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(u"Tautulli Helpers :: Failed to uninstall the GeoLite2 database: %s" % e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
plexpy.CONFIG.__setattr__('GEOIP_DB_INSTALLED', 0)
|
|
||||||
plexpy.CONFIG.write()
|
|
||||||
|
|
||||||
logger.debug(u"Tautulli Helpers :: GeoLite2 database uninstalled successfully.")
|
|
||||||
|
|
||||||
plexpy.schedule_job(update_geoip_db, 'Update GeoLite2 database', hours=0, minutes=0, seconds=0)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def geoip_lookup(ip_address):
|
|
||||||
if not plexpy.CONFIG.GEOIP_DB_INSTALLED:
|
|
||||||
return 'GeoLite2 database not installed. Please install from the ' \
|
|
||||||
'<a href="settings?install_geoip=true">Settings</a> page.'
|
|
||||||
|
|
||||||
if not ip_address:
|
|
||||||
return 'No IP address provided.'
|
|
||||||
|
|
||||||
try:
|
|
||||||
reader = geoip2.database.Reader(plexpy.CONFIG.GEOIP_DB)
|
|
||||||
geo = reader.city(ip_address)
|
|
||||||
reader.close()
|
|
||||||
except ValueError as e:
|
|
||||||
return 'Invalid IP address provided: %s.' % ip_address
|
|
||||||
except IOError as e:
|
|
||||||
return 'Missing GeoLite2 database. Please reinstall from the ' \
|
|
||||||
'<a href="settings?install_geoip=true">Settings</a> page.'
|
|
||||||
except maxminddb.InvalidDatabaseError as e:
|
|
||||||
return 'Invalid GeoLite2 database. Please reinstall from the ' \
|
|
||||||
'<a href="settings?install_geoip=true">Settings</a> page.'
|
|
||||||
except geoip2.errors.AddressNotFoundError as e:
|
|
||||||
return '%s' % e
|
|
||||||
except Exception as e:
|
|
||||||
return 'Error: %s' % e
|
|
||||||
|
|
||||||
geo_info = {'continent': geo.continent.name,
|
|
||||||
'country': geo.country.name,
|
|
||||||
'region': geo.subdivisions.most_specific.name,
|
|
||||||
'city': geo.city.name,
|
|
||||||
'postal_code': geo.postal.code,
|
|
||||||
'timezone': geo.location.time_zone,
|
|
||||||
'latitude': geo.location.latitude,
|
|
||||||
'longitude': geo.location.longitude,
|
|
||||||
'accuracy': geo.location.accuracy_radius
|
|
||||||
}
|
|
||||||
|
|
||||||
return geo_info
|
|
||||||
|
|
||||||
|
|
||||||
def whois_lookup(ip_address):
|
def whois_lookup(ip_address):
|
||||||
|
|
||||||
nets = []
|
nets = []
|
||||||
|
|
|
@ -2942,11 +2942,7 @@ class WebInterface(object):
|
||||||
"newsletter_password": plexpy.CONFIG.NEWSLETTER_PASSWORD,
|
"newsletter_password": plexpy.CONFIG.NEWSLETTER_PASSWORD,
|
||||||
"newsletter_inline_styles": checked(plexpy.CONFIG.NEWSLETTER_INLINE_STYLES),
|
"newsletter_inline_styles": checked(plexpy.CONFIG.NEWSLETTER_INLINE_STYLES),
|
||||||
"newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR,
|
"newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR,
|
||||||
"win_sys_tray": checked(plexpy.CONFIG.WIN_SYS_TRAY),
|
"win_sys_tray": checked(plexpy.CONFIG.WIN_SYS_TRAY)
|
||||||
"maxmind_license_key": plexpy.CONFIG.MAXMIND_LICENSE_KEY,
|
|
||||||
"geoip_db": plexpy.CONFIG.GEOIP_DB,
|
|
||||||
"geoip_db_installed": plexpy.CONFIG.GEOIP_DB_INSTALLED,
|
|
||||||
"geoip_db_update_days": plexpy.CONFIG.GEOIP_DB_UPDATE_DAYS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs)
|
return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs)
|
||||||
|
@ -3178,36 +3174,6 @@ class WebInterface(object):
|
||||||
else:
|
else:
|
||||||
return {'result': 'error', 'message': 'Database backup failed.'}
|
return {'result': 'error', 'message': 'Database backup failed.'}
|
||||||
|
|
||||||
@cherrypy.expose
|
|
||||||
@cherrypy.tools.json_out()
|
|
||||||
@requireAuth(member_of("admin"))
|
|
||||||
@addtoapi()
|
|
||||||
def install_geoip_db(self, update=False, **kwargs):
|
|
||||||
""" Downloads and installs the GeoLite2 database """
|
|
||||||
|
|
||||||
update = helpers.bool_true(update)
|
|
||||||
|
|
||||||
result = helpers.install_geoip_db(update=update)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
return {'result': 'success', 'message': 'GeoLite2 database installed successful.', 'updated': result}
|
|
||||||
else:
|
|
||||||
return {'result': 'error', 'message': 'GeoLite2 database install failed.', 'updated': 0}
|
|
||||||
|
|
||||||
@cherrypy.expose
|
|
||||||
@cherrypy.tools.json_out()
|
|
||||||
@requireAuth(member_of("admin"))
|
|
||||||
@addtoapi()
|
|
||||||
def uninstall_geoip_db(self, **kwargs):
|
|
||||||
""" Uninstalls the GeoLite2 database """
|
|
||||||
|
|
||||||
result = helpers.uninstall_geoip_db()
|
|
||||||
|
|
||||||
if result:
|
|
||||||
return {'result': 'success', 'message': 'GeoLite2 database uninstalled successfully.'}
|
|
||||||
else:
|
|
||||||
return {'result': 'error', 'message': 'GeoLite2 database uninstall failed.'}
|
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
|
@ -5725,7 +5691,7 @@ class WebInterface(object):
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def get_geoip_lookup(self, ip_address='', **kwargs):
|
def get_geoip_lookup(self, ip_address='', **kwargs):
|
||||||
""" Get the geolocation info for an IP address. The GeoLite2 database must be installed.
|
""" Get the geolocation info for an IP address.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue