diff --git a/API.md b/API.md index 50eab662..8ad58846 100644 --- a/API.md +++ b/API.md @@ -1722,6 +1722,10 @@ Returns: ``` +### install_geoip_db +Downloads and installs the GeoLite2 database + + ### notify Send a notification using PlexPy. @@ -1844,6 +1848,10 @@ Returns: ``` +### uninstall_geoip_db +Uninstalls the GeoLite2 database + + ### update Check for PlexPy updates on Github. diff --git a/data/interfaces/default/configuration_table.html b/data/interfaces/default/configuration_table.html index 0e4b0c06..b7da81a3 100644 --- a/data/interfaces/default/configuration_table.html +++ b/data/interfaces/default/configuration_table.html @@ -52,7 +52,7 @@ DOCUMENTATION :: END GeoLite2 Database: % if plexpy.CONFIG.GEOIP_DB: - ${plexpy.CONFIG.GEOIP_DB} | Reinstall / Update + ${plexpy.CONFIG.GEOIP_DB} | Reinstall / Update | Uninstall % else: Click here to install the GeoLite2 database. % endif @@ -107,5 +107,12 @@ DOCUMENTATION :: END var url = 'install_geoip_db'; confirmAjaxCall(url, msg, 'Installing GeoLite2 database.', getConfigurationTable); }); + + $("#uninstall_geoip_db").click(function () { + var msg = 'Are you sure you want to uninstall the GeoLite2 database?

' + + 'You will not be able to lookup IP address geolocation info.'; + var url = 'uninstall_geoip_db'; + confirmAjaxCall(url, msg, 'Uninstalling GeoLite2 database.', getConfigurationTable); + }); }); \ No newline at end of file diff --git a/plexpy/helpers.py b/plexpy/helpers.py index a36d99c8..28142e92 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -577,6 +577,19 @@ def install_geoip_db(): return True +def uninstall_geoip_db(): + logger.debug(u"PlexPy Helpers :: Uninstalling the GeoLite2 database...") + try: + os.remove(plexpy.CONFIG.GEOIP_DB) + plexpy.CONFIG.__setattr__('GEOIP_DB', '') + plexpy.CONFIG.write() + except Exception as e: + logger.error(u"PlexPy Helpers :: Failed to uninstall the GeoLite2 database: %s" % e) + return False + + logger.debug(u"PlexPy Helpers :: GeoLite2 database uninstalled successfully.") + return True + def geoip_lookup(ip_address): if not plexpy.CONFIG.GEOIP_DB: return 'GeoLite2 database not installed. Please install from the ' \ diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 4ff7eeaf..538d361c 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2802,15 +2802,30 @@ class WebInterface(object): @cherrypy.expose @cherrypy.tools.json_out() @requireAuth(member_of("admin")) + @addtoapi() def install_geoip_db(self): - """ Downloads and installs the GeoIP database """ + """ Downloads and installs the GeoLite2 database """ result = helpers.install_geoip_db() if result: - return {'result': 'success', 'message': 'GeoIP database installed successful.'} + return {'result': 'success', 'message': 'GeoLite2 database installed successful.'} else: - return {'result': 'error', 'message': 'GeoIP database install failed.'} + return {'result': 'error', 'message': 'GeoLite2 database install failed.'} + + @cherrypy.expose + @cherrypy.tools.json_out() + @requireAuth(member_of("admin")) + @addtoapi() + def uninstall_geoip_db(self): + """ 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 @requireAuth(member_of("admin"))