generated from pavel.muhortov/template-python
Compare commits
No commits in common. "8b2b1d3de012e51260751badb3d006b2a2eb94e3" and "75b65f85c03c0904fad6bd24a38b01dcdfda230c" have entirely different histories.
8b2b1d3de0
...
75b65f85c0
|
@ -34,12 +34,6 @@ amazon = true
|
|||
# - contain only atlassian ip ranges
|
||||
atlassian = true
|
||||
#
|
||||
# antifilter - it's a parsed RKN block list (https://antifilter.network/download/ipsmart.lst)
|
||||
# + absoutely free
|
||||
# + simple parsing
|
||||
# - it's necessary only in Russia
|
||||
antifilter = true
|
||||
#
|
||||
# herrbischoff - it's a GitHub repository (https://github.com/herrbischoff/country-ip-blocks)
|
||||
# + absoutely free
|
||||
# + updated hourly
|
||||
|
@ -65,13 +59,13 @@ ip2l_download_token = ip2location_TOKEN
|
|||
# - access to updates only by paid subscription
|
||||
ip2l_database_code = DB1CIDR
|
||||
#
|
||||
# githmptoday - it's compilation from all other sources (https://git.hmp.today/pavel.muhortov/my_route.db)
|
||||
# wwwhmptoday - it's compilation from all other sources (https://git.hmp.today/pavel.muhortov/my_route.db)
|
||||
# + all the benefits of other sources
|
||||
# + all lists ready to use
|
||||
# - you need account
|
||||
githmptoday = true
|
||||
githmptoday_user = username
|
||||
githmptoday_pass = password
|
||||
wwwhmptoday = true
|
||||
wwwhmptoday_user = username
|
||||
wwwhmptoday_pass = password
|
||||
|
||||
|
||||
[enable-gateway]
|
||||
|
@ -83,9 +77,6 @@ dev-wg1 = true
|
|||
|
||||
[via-192.168.0.1]
|
||||
# List of CIDR. Only CIDR with the TRUE value will be used.
|
||||
# The order of the entries is important:
|
||||
# - the "add" action applies entries from top to bottom,
|
||||
# - the "del" action applies entries from bottom to top.
|
||||
# If different sources contain the same cidr, use the path part to define your preference.
|
||||
ipv4/via-192.168.0.1.cidr = true
|
||||
ipv4/atlassian.cidr = true
|
||||
|
@ -96,9 +87,6 @@ ipv4/private.cidr
|
|||
|
||||
[dev-wg1]
|
||||
# List of CIDR. Only CIDR with the TRUE value will be used.
|
||||
# The order of the entries is important:
|
||||
# - the "add" action applies entries from top to bottom,
|
||||
# - the "del" action applies entries from bottom to top.
|
||||
# If different sources contain the same cidr, use the path part to define your preference.
|
||||
ipv4/dev-wg1.cidr = true
|
||||
ipv4/public.cidr = true
|
||||
|
|
93
my_route.py
93
my_route.py
|
@ -300,10 +300,10 @@ class Route(Connect):
|
|||
apply_counter = 0
|
||||
gways_counter = 0
|
||||
files_counter = 0
|
||||
commands_list = []
|
||||
for gw, cidr_apply in self._gw.items():
|
||||
gways_counter += 1
|
||||
for cidr in cidr_apply:
|
||||
local_logger = logging.getLogger(cidr)
|
||||
for cidr_file in cidr_current:
|
||||
if cidr in cidr_file:
|
||||
with open(cidr_file, mode='r', encoding='utf-8') as file:
|
||||
|
@ -317,15 +317,9 @@ class Route(Connect):
|
|||
pass
|
||||
else:
|
||||
command = ['ip', 'ro', action, route, gw_type, gw_name]
|
||||
commands_list.append({'cidr': cidr, 'command': command})
|
||||
|
||||
if action == 'delete':
|
||||
commands_list = reversed(commands_list)
|
||||
for command in commands_list:
|
||||
local_logger = logging.getLogger(command['cidr'])
|
||||
local_logger.info(msg=' '.join(command['command']))
|
||||
local_logger.info(msg=' '.join(command))
|
||||
if not imitate:
|
||||
if self.__cmd(command=command['command']) == 0:
|
||||
if self.__cmd(command=command) == 0:
|
||||
apply_counter += 1
|
||||
|
||||
local_logger = logging.getLogger(logger_alias)
|
||||
|
@ -432,12 +426,6 @@ class Route(Connect):
|
|||
force_download=force_download,
|
||||
logger_alias=logger_alias
|
||||
)
|
||||
elif name == 'antifilter':
|
||||
return self.__update_source_antifilter(
|
||||
db_root_path=db_root_path,
|
||||
force_download=force_download,
|
||||
logger_alias=logger_alias
|
||||
)
|
||||
elif name == 'atlassian':
|
||||
return self.__update_source_atlassian(
|
||||
db_root_path=db_root_path,
|
||||
|
@ -458,8 +446,8 @@ class Route(Connect):
|
|||
force_download=force_download,
|
||||
logger_alias=logger_alias
|
||||
)
|
||||
elif name == 'githmptoday':
|
||||
return self.__update_source_githmptoday(
|
||||
elif name == 'wwwhmptoday':
|
||||
return self.__update_source_wwwhmptoday(
|
||||
db_root_path=db_root_path,
|
||||
download_user=download_user,
|
||||
download_pass=download_pass,
|
||||
|
@ -670,63 +658,6 @@ class Route(Connect):
|
|||
return True
|
||||
return False
|
||||
|
||||
def __update_source_antifilter(
|
||||
self,
|
||||
db_root_path: str,
|
||||
force_download: bool = False,
|
||||
logger_alias: str = inspect.stack()[0].function
|
||||
) -> bool:
|
||||
local_logger = logging.getLogger(logger_alias)
|
||||
if Do.args_valid(locals(), self.__update_source_antifilter.__annotations__):
|
||||
db_source_url = "https://antifilter.network/download/ipsmart.lst"
|
||||
db_source_name = "antifilter"
|
||||
db_source_root = db_root_path + sep + "sources" + sep + db_source_name
|
||||
db_source_file = db_source_root + sep + "ipsmart.lst"
|
||||
db_source_cidr_root = db_source_root + sep + "cidr"
|
||||
|
||||
|
||||
if not path.exists(db_source_file):
|
||||
force_download = True
|
||||
if force_download:
|
||||
if not self.__download_db(
|
||||
url=db_source_url,
|
||||
dst=db_source_file,
|
||||
logger_alias=logger_alias
|
||||
):
|
||||
return False
|
||||
|
||||
|
||||
with open(db_source_file, mode='r', encoding='utf-8') as db_source_raw:
|
||||
db_source_data = db_source_raw.read().splitlines()
|
||||
db_parsed_data_ipv4 = []
|
||||
db_parsed_data_ipv6 = []
|
||||
for item in db_source_data:
|
||||
if not ":" in item:
|
||||
db_parsed_data_ipv4.append(item)
|
||||
else:
|
||||
db_parsed_data_ipv6.append(item)
|
||||
|
||||
makedirs(db_source_cidr_root + sep + "ipv4", exist_ok=True)
|
||||
db_source_cidr_ipv4_file = (""
|
||||
+ db_source_cidr_root + sep + "ipv4"
|
||||
+ sep + db_source_name + ".cidr"
|
||||
)
|
||||
with open(db_source_cidr_ipv4_file, mode='w+', encoding='utf-8') as cidr_dump:
|
||||
cidr_dump.write('\n'.join(db_parsed_data_ipv4))
|
||||
local_logger.info(msg=db_source_cidr_ipv4_file + ' saved')
|
||||
|
||||
makedirs(db_source_cidr_root + sep + "ipv6", exist_ok=True)
|
||||
db_source_cidr_ipv6_file = (""
|
||||
+ db_source_cidr_root + sep + "ipv6"
|
||||
+ sep + db_source_name + ".cidr"
|
||||
)
|
||||
with open(db_source_cidr_ipv6_file, mode='w+', encoding='utf-8') as cidr_dump:
|
||||
cidr_dump.write('\n'.join(db_parsed_data_ipv6))
|
||||
local_logger.info(msg=db_source_cidr_ipv6_file + ' saved')
|
||||
|
||||
return True
|
||||
return False
|
||||
|
||||
def __update_source_herrbischoff(
|
||||
self,
|
||||
db_root_path: str,
|
||||
|
@ -915,7 +846,7 @@ class Route(Connect):
|
|||
remove(db_source_file)
|
||||
return False
|
||||
|
||||
def __update_source_githmptoday(
|
||||
def __update_source_wwwhmptoday(
|
||||
self,
|
||||
db_root_path: str,
|
||||
download_user: str,
|
||||
|
@ -924,7 +855,7 @@ class Route(Connect):
|
|||
logger_alias: str = inspect.stack()[0].function
|
||||
) -> bool:
|
||||
local_logger = logging.getLogger(logger_alias)
|
||||
if Do.args_valid(locals(), self.__update_source_githmptoday.__annotations__):
|
||||
if Do.args_valid(locals(), self.__update_source_wwwhmptoday.__annotations__):
|
||||
if not path.exists(db_root_path + sep + 'sources'):
|
||||
force_download = True
|
||||
if force_download:
|
||||
|
@ -1093,12 +1024,12 @@ if __name__ == "__main__":
|
|||
enable_sources['ip2location']['db_source_code'] = (
|
||||
conf_sources.data['ip2l_database_code']
|
||||
)
|
||||
if 'githmptoday' in enable_sources:
|
||||
enable_sources['githmptoday']['download_user'] = (
|
||||
conf_sources.data['githmptoday_user']
|
||||
if 'wwwhmptoday' in enable_sources:
|
||||
enable_sources['wwwhmptoday']['download_user'] = (
|
||||
conf_sources.data['wwwhmptoday_user']
|
||||
)
|
||||
enable_sources['githmptoday']['download_pass'] = (
|
||||
conf_sources.data['githmptoday_pass']
|
||||
enable_sources['wwwhmptoday']['download_pass'] = (
|
||||
conf_sources.data['wwwhmptoday_pass']
|
||||
)
|
||||
|
||||
logging.basicConfig(
|
||||
|
|
Loading…
Reference in New Issue
Block a user