net-pos: make api_url configurable

now its possible tzo set an own api_url in config:

[main.plugins.net-pos]
enabled = true
api_key = "test"
api_url = "https://location.services.my-own.com/v1/geolocate?key={api}"
This commit is contained in:
xenDE 2020-01-18 17:35:54 +01:00 committed by GitHub
parent 0764304be9
commit 9339ecb2fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,18 +7,18 @@ import time
import pwnagotchi.plugins as plugins import pwnagotchi.plugins as plugins
from pwnagotchi.utils import StatusFile from pwnagotchi.utils import StatusFile
MOZILLA_API_URL = 'https://location.services.mozilla.com/v1/geolocate?key={api}'
class NetPos(plugins.Plugin): class NetPos(plugins.Plugin):
__author__ = 'zenzen san' __author__ = 'zenzen san'
__version__ = '2.0.2' __version__ = '2.0.3'
__license__ = 'GPL3' __license__ = 'GPL3'
__description__ = """Saves a json file with the access points with more signal __description__ = """Saves a json file with the access points with more signal
whenever a handshake is captured. whenever a handshake is captured.
When internet is available the files are converted in geo locations When internet is available the files are converted in geo locations
using Mozilla LocationService """ using Mozilla LocationService """
API_URL = 'https://location.services.mozilla.com/v1/geolocate?key={api}'
def __init__(self): def __init__(self):
self.report = StatusFile('/root/.net_pos_saved', data_format='json') self.report = StatusFile('/root/.net_pos_saved', data_format='json')
self.skip = list() self.skip = list()
@ -29,9 +29,11 @@ class NetPos(plugins.Plugin):
if 'api_key' not in self.options or ('api_key' in self.options and not self.options['api_key']): if 'api_key' not in self.options or ('api_key' in self.options and not self.options['api_key']):
logging.error("NET-POS: api_key isn't set. Can't use mozilla's api.") logging.error("NET-POS: api_key isn't set. Can't use mozilla's api.")
return return
if 'api_url' in self.options:
self.API_URL = self.options['api_url']
self.ready = True self.ready = True
logging.info("net-pos plugin loaded.") logging.info("net-pos plugin loaded.")
logging.debug(f"net-pos: use api_url: {self.API_URL}");
def _append_saved(self, path): def _append_saved(self, path):
to_save = list() to_save = list()
@ -124,7 +126,7 @@ class NetPos(plugins.Plugin):
return netpos return netpos
def _get_geo_data(self, path, timeout=30): def _get_geo_data(self, path, timeout=30):
geourl = MOZILLA_API_URL.format(api=self.options['api_key']) geourl = self.API_URL.format(api=self.options['api_key'])
try: try:
with open(path, "r") as json_file: with open(path, "r") as json_file: