Add URL config check
This commit is contained in:
parent
d357351651
commit
78d2e22e58
1 changed files with 71 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from sys import exit
|
from sys import exit
|
||||||
from os.path import join, exists
|
from os.path import join, exists
|
||||||
|
|
||||||
|
@ -40,7 +42,7 @@ class INIParser(object):
|
||||||
filtered_strings = [section.get(k) for key, section in self.config.items()
|
filtered_strings = [section.get(k) for key, section in self.config.items()
|
||||||
for k in section if k in BlacklistFilter.blacklisted_strings]
|
for k in section if k in BlacklistFilter.blacklisted_strings]
|
||||||
self.filtered_strings = list(filter(None, filtered_strings))
|
self.filtered_strings = list(filter(None, filtered_strings))
|
||||||
|
|
||||||
for handler in self.logger.handlers:
|
for handler in self.logger.handlers:
|
||||||
handler.addFilter(BlacklistFilter(set(self.filtered_strings)))
|
handler.addFilter(BlacklistFilter(set(self.filtered_strings)))
|
||||||
|
|
||||||
|
@ -66,12 +68,34 @@ class INIParser(object):
|
||||||
self.logger.error('Config file missing (varken.ini) in %s', self.data_folder)
|
self.logger.error('Config file missing (varken.ini) in %s', self.data_folder)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
def url_check(self, url=None):
|
||||||
|
url_check = url
|
||||||
|
|
||||||
|
regex = re.compile(
|
||||||
|
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
|
||||||
|
r'localhost|' #localhost...
|
||||||
|
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
|
||||||
|
r'(?::\d+)?' # optional port
|
||||||
|
r'(?:/?|[/?]\S+)$', re.IGNORECASE
|
||||||
|
)
|
||||||
|
|
||||||
|
valid = re.match(regex, url_check) is not None
|
||||||
|
if not valid:
|
||||||
|
self.logger.error('%s is invalid! URL must host/IP and port if not 80 or 443. ie. localhost:8080', url_check)
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
self.logger.debug('%s is a vlaid URL in the config', url_check)
|
||||||
|
return url_check
|
||||||
|
|
||||||
def parse_opts(self):
|
def parse_opts(self):
|
||||||
self.read_file()
|
self.read_file()
|
||||||
# Parse InfluxDB options
|
# Parse InfluxDB options
|
||||||
url = self.config.get('influxdb', 'url')
|
url = self.config.get('influxdb', 'url')
|
||||||
|
|
||||||
port = self.config.getint('influxdb', 'port')
|
port = self.config.getint('influxdb', 'port')
|
||||||
|
|
||||||
username = self.config.get('influxdb', 'username')
|
username = self.config.get('influxdb', 'username')
|
||||||
|
|
||||||
password = self.config.get('influxdb', 'password')
|
password = self.config.get('influxdb', 'password')
|
||||||
|
|
||||||
self.influx_server = InfluxServer(url, port, username, password)
|
self.influx_server = InfluxServer(url, port, username, password)
|
||||||
|
@ -83,29 +107,40 @@ class INIParser(object):
|
||||||
for server_id in self.sonarr_enabled:
|
for server_id in self.sonarr_enabled:
|
||||||
sonarr_section = 'sonarr-' + str(server_id)
|
sonarr_section = 'sonarr-' + str(server_id)
|
||||||
try:
|
try:
|
||||||
url = self.config.get(sonarr_section, 'url')
|
url = self.url_check(self.config.get(sonarr_section, 'url'))
|
||||||
|
|
||||||
apikey = self.config.get(sonarr_section, 'apikey')
|
apikey = self.config.get(sonarr_section, 'apikey')
|
||||||
|
|
||||||
scheme = 'https://' if self.config.getboolean(
|
scheme = 'https://' if self.config.getboolean(
|
||||||
sonarr_section, 'ssl') else 'http://'
|
sonarr_section, 'ssl') else 'http://'
|
||||||
|
|
||||||
verify_ssl = self.config.getboolean(
|
verify_ssl = self.config.getboolean(
|
||||||
sonarr_section, 'verify_ssl')
|
sonarr_section, 'verify_ssl')
|
||||||
|
|
||||||
if scheme != 'https://':
|
if scheme != 'https://':
|
||||||
verify_ssl = False
|
verify_ssl = False
|
||||||
|
|
||||||
queue = self.config.getboolean(sonarr_section, 'queue')
|
queue = self.config.getboolean(sonarr_section, 'queue')
|
||||||
|
|
||||||
missing_days = self.config.getint(
|
missing_days = self.config.getint(
|
||||||
sonarr_section, 'missing_days')
|
sonarr_section, 'missing_days')
|
||||||
|
|
||||||
future_days = self.config.getint(
|
future_days = self.config.getint(
|
||||||
sonarr_section, 'future_days')
|
sonarr_section, 'future_days')
|
||||||
|
|
||||||
missing_days_run_seconds = self.config.getint(
|
missing_days_run_seconds = self.config.getint(
|
||||||
sonarr_section, 'missing_days_run_seconds')
|
sonarr_section, 'missing_days_run_seconds')
|
||||||
|
|
||||||
future_days_run_seconds = self.config.getint(
|
future_days_run_seconds = self.config.getint(
|
||||||
sonarr_section, 'future_days_run_seconds')
|
sonarr_section, 'future_days_run_seconds')
|
||||||
|
|
||||||
queue_run_seconds = self.config.getint(
|
queue_run_seconds = self.config.getint(
|
||||||
sonarr_section, 'queue_run_seconds')
|
sonarr_section, 'queue_run_seconds')
|
||||||
|
|
||||||
server = SonarrServer(server_id, scheme + url, apikey, verify_ssl, missing_days,
|
server = SonarrServer(server_id, scheme + url, apikey, verify_ssl, missing_days,
|
||||||
missing_days_run_seconds, future_days, future_days_run_seconds,
|
missing_days_run_seconds, future_days, future_days_run_seconds,
|
||||||
queue, queue_run_seconds)
|
queue, queue_run_seconds)
|
||||||
|
|
||||||
self.sonarr_servers.append(server)
|
self.sonarr_servers.append(server)
|
||||||
except configparser.NoOptionError as e:
|
except configparser.NoOptionError as e:
|
||||||
self.radarr_enabled = False
|
self.radarr_enabled = False
|
||||||
|
@ -119,19 +154,27 @@ class INIParser(object):
|
||||||
for server_id in self.radarr_enabled:
|
for server_id in self.radarr_enabled:
|
||||||
radarr_section = 'radarr-' + str(server_id)
|
radarr_section = 'radarr-' + str(server_id)
|
||||||
try:
|
try:
|
||||||
url = self.config.get(radarr_section, 'url')
|
url = self.url_check(self.config.get(radarr_section, 'url'))
|
||||||
|
|
||||||
apikey = self.config.get(radarr_section, 'apikey')
|
apikey = self.config.get(radarr_section, 'apikey')
|
||||||
|
|
||||||
scheme = 'https://' if self.config.getboolean(
|
scheme = 'https://' if self.config.getboolean(
|
||||||
radarr_section, 'ssl') else 'http://'
|
radarr_section, 'ssl') else 'http://'
|
||||||
|
|
||||||
verify_ssl = self.config.getboolean(
|
verify_ssl = self.config.getboolean(
|
||||||
radarr_section, 'verify_ssl')
|
radarr_section, 'verify_ssl')
|
||||||
|
|
||||||
if scheme != 'https://':
|
if scheme != 'https://':
|
||||||
verify_ssl = False
|
verify_ssl = False
|
||||||
|
|
||||||
queue = self.config.getboolean(radarr_section, 'queue')
|
queue = self.config.getboolean(radarr_section, 'queue')
|
||||||
|
|
||||||
queue_run_seconds = self.config.getint(
|
queue_run_seconds = self.config.getint(
|
||||||
radarr_section, 'queue_run_seconds')
|
radarr_section, 'queue_run_seconds')
|
||||||
|
|
||||||
get_missing = self.config.getboolean(
|
get_missing = self.config.getboolean(
|
||||||
radarr_section, 'get_missing')
|
radarr_section, 'get_missing')
|
||||||
|
|
||||||
get_missing_run_seconds = self.config.getint(
|
get_missing_run_seconds = self.config.getint(
|
||||||
radarr_section, 'get_missing_run_seconds')
|
radarr_section, 'get_missing_run_seconds')
|
||||||
|
|
||||||
|
@ -150,18 +193,25 @@ class INIParser(object):
|
||||||
for server_id in self.tautulli_enabled:
|
for server_id in self.tautulli_enabled:
|
||||||
tautulli_section = 'tautulli-' + str(server_id)
|
tautulli_section = 'tautulli-' + str(server_id)
|
||||||
try:
|
try:
|
||||||
url = self.config.get(tautulli_section, 'url')
|
url = self.url_check(self.config.get(tautulli_section, 'url'))
|
||||||
|
|
||||||
fallback_ip = self.config.get(
|
fallback_ip = self.config.get(
|
||||||
tautulli_section, 'fallback_ip')
|
tautulli_section, 'fallback_ip')
|
||||||
|
|
||||||
apikey = self.config.get(tautulli_section, 'apikey')
|
apikey = self.config.get(tautulli_section, 'apikey')
|
||||||
|
|
||||||
scheme = 'https://' if self.config.getboolean(
|
scheme = 'https://' if self.config.getboolean(
|
||||||
tautulli_section, 'ssl') else 'http://'
|
tautulli_section, 'ssl') else 'http://'
|
||||||
|
|
||||||
verify_ssl = self.config.getboolean(
|
verify_ssl = self.config.getboolean(
|
||||||
tautulli_section, 'verify_ssl')
|
tautulli_section, 'verify_ssl')
|
||||||
|
|
||||||
if scheme != 'https://':
|
if scheme != 'https://':
|
||||||
verify_ssl = False
|
verify_ssl = False
|
||||||
|
|
||||||
get_activity = self.config.getboolean(
|
get_activity = self.config.getboolean(
|
||||||
tautulli_section, 'get_activity')
|
tautulli_section, 'get_activity')
|
||||||
|
|
||||||
get_activity_run_seconds = self.config.getint(
|
get_activity_run_seconds = self.config.getint(
|
||||||
tautulli_section, 'get_activity_run_seconds')
|
tautulli_section, 'get_activity_run_seconds')
|
||||||
|
|
||||||
|
@ -180,20 +230,28 @@ class INIParser(object):
|
||||||
for server_id in self.ombi_enabled:
|
for server_id in self.ombi_enabled:
|
||||||
ombi_section = 'ombi-' + str(server_id)
|
ombi_section = 'ombi-' + str(server_id)
|
||||||
try:
|
try:
|
||||||
url = self.config.get(ombi_section, 'url')
|
url = self.url_check(self.config.get(ombi_section, 'url'))
|
||||||
|
|
||||||
apikey = self.config.get(ombi_section, 'apikey')
|
apikey = self.config.get(ombi_section, 'apikey')
|
||||||
|
|
||||||
scheme = 'https://' if self.config.getboolean(
|
scheme = 'https://' if self.config.getboolean(
|
||||||
ombi_section, 'ssl') else 'http://'
|
ombi_section, 'ssl') else 'http://'
|
||||||
|
|
||||||
verify_ssl = self.config.getboolean(
|
verify_ssl = self.config.getboolean(
|
||||||
ombi_section, 'verify_ssl')
|
ombi_section, 'verify_ssl')
|
||||||
|
|
||||||
if scheme != 'https://':
|
if scheme != 'https://':
|
||||||
verify_ssl = False
|
verify_ssl = False
|
||||||
|
|
||||||
request_type_counts = self.config.getboolean(
|
request_type_counts = self.config.getboolean(
|
||||||
ombi_section, 'get_request_type_counts')
|
ombi_section, 'get_request_type_counts')
|
||||||
|
|
||||||
request_type_run_seconds = self.config.getint(
|
request_type_run_seconds = self.config.getint(
|
||||||
ombi_section, 'request_type_run_seconds')
|
ombi_section, 'request_type_run_seconds')
|
||||||
|
|
||||||
request_total_counts = self.config.getboolean(
|
request_total_counts = self.config.getboolean(
|
||||||
ombi_section, 'get_request_total_counts')
|
ombi_section, 'get_request_total_counts')
|
||||||
|
|
||||||
request_total_run_seconds = self.config.getint(
|
request_total_run_seconds = self.config.getint(
|
||||||
ombi_section, 'request_total_run_seconds')
|
ombi_section, 'request_total_run_seconds')
|
||||||
|
|
||||||
|
@ -212,17 +270,24 @@ class INIParser(object):
|
||||||
for firewall_id in self.ciscoasa_enabled:
|
for firewall_id in self.ciscoasa_enabled:
|
||||||
ciscoasa_section = 'ciscoasa-' + str(firewall_id)
|
ciscoasa_section = 'ciscoasa-' + str(firewall_id)
|
||||||
try:
|
try:
|
||||||
url = self.config.get(ciscoasa_section, 'url')
|
url = self.url_check(self.config.get(ciscoasa_section, 'url'))
|
||||||
|
|
||||||
username = self.config.get(ciscoasa_section, 'username')
|
username = self.config.get(ciscoasa_section, 'username')
|
||||||
|
|
||||||
password = self.config.get(ciscoasa_section, 'password')
|
password = self.config.get(ciscoasa_section, 'password')
|
||||||
|
|
||||||
scheme = 'https://' if self.config.getboolean(
|
scheme = 'https://' if self.config.getboolean(
|
||||||
ciscoasa_section, 'ssl') else 'http://'
|
ciscoasa_section, 'ssl') else 'http://'
|
||||||
|
|
||||||
verify_ssl = self.config.getboolean(
|
verify_ssl = self.config.getboolean(
|
||||||
ciscoasa_section, 'verify_ssl')
|
ciscoasa_section, 'verify_ssl')
|
||||||
|
|
||||||
if scheme != 'https://':
|
if scheme != 'https://':
|
||||||
verify_ssl = False
|
verify_ssl = False
|
||||||
|
|
||||||
outside_interface = self.config.get(
|
outside_interface = self.config.get(
|
||||||
ciscoasa_section, 'outside_interface')
|
ciscoasa_section, 'outside_interface')
|
||||||
|
|
||||||
get_bandwidth_run_seconds = self.config.getint(
|
get_bandwidth_run_seconds = self.config.getint(
|
||||||
ciscoasa_section, 'get_bandwidth_run_seconds')
|
ciscoasa_section, 'get_bandwidth_run_seconds')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue