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 | # - contain only atlassian ip ranges | ||||||
| atlassian = true | 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) | # herrbischoff - it's a GitHub repository (https://github.com/herrbischoff/country-ip-blocks) | ||||||
| # + absoutely free | # + absoutely free | ||||||
| # + updated hourly | # + updated hourly | ||||||
|  | @ -65,13 +59,13 @@ ip2l_download_token = ip2location_TOKEN | ||||||
| # - access to updates only by paid subscription | # - access to updates only by paid subscription | ||||||
| ip2l_database_code = DB1CIDR | 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 the benefits of other sources | ||||||
| # + all lists ready to use | # + all lists ready to use | ||||||
| # - you need account | # - you need account | ||||||
| githmptoday = true | wwwhmptoday = true | ||||||
| githmptoday_user = username | wwwhmptoday_user = username | ||||||
| githmptoday_pass = password | wwwhmptoday_pass = password | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| [enable-gateway] | [enable-gateway] | ||||||
|  | @ -83,9 +77,6 @@ dev-wg1 = true | ||||||
| 
 | 
 | ||||||
| [via-192.168.0.1] | [via-192.168.0.1] | ||||||
| # List of CIDR. Only CIDR with the TRUE value will be used. | # 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. | # If different sources contain the same cidr, use the path part to define your preference. | ||||||
| ipv4/via-192.168.0.1.cidr = true | ipv4/via-192.168.0.1.cidr = true | ||||||
| ipv4/atlassian.cidr = true | ipv4/atlassian.cidr = true | ||||||
|  | @ -96,9 +87,6 @@ ipv4/private.cidr | ||||||
| 
 | 
 | ||||||
| [dev-wg1] | [dev-wg1] | ||||||
| # List of CIDR. Only CIDR with the TRUE value will be used. | # 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. | # If different sources contain the same cidr, use the path part to define your preference. | ||||||
| ipv4/dev-wg1.cidr = true | ipv4/dev-wg1.cidr = true | ||||||
| ipv4/public.cidr = true | ipv4/public.cidr = true | ||||||
|  |  | ||||||
							
								
								
									
										97
									
								
								my_route.py
									
									
									
									
									
								
							
							
						
						
									
										97
									
								
								my_route.py
									
									
									
									
									
								
							|  | @ -300,10 +300,10 @@ class Route(Connect): | ||||||
|             apply_counter = 0 |             apply_counter = 0 | ||||||
|             gways_counter = 0 |             gways_counter = 0 | ||||||
|             files_counter = 0 |             files_counter = 0 | ||||||
|             commands_list = [] |  | ||||||
|             for gw, cidr_apply in self._gw.items(): |             for gw, cidr_apply in self._gw.items(): | ||||||
|                 gways_counter += 1 |                 gways_counter += 1 | ||||||
|                 for cidr in cidr_apply: |                 for cidr in cidr_apply: | ||||||
|  |                     local_logger = logging.getLogger(cidr) | ||||||
|                     for cidr_file in cidr_current: |                     for cidr_file in cidr_current: | ||||||
|                         if cidr in cidr_file: |                         if cidr in cidr_file: | ||||||
|                             with open(cidr_file, mode='r', encoding='utf-8') as file: |                             with open(cidr_file, mode='r', encoding='utf-8') as file: | ||||||
|  | @ -317,16 +317,10 @@ class Route(Connect): | ||||||
|                                         pass |                                         pass | ||||||
|                                     else: |                                     else: | ||||||
|                                         command = ['ip', 'ro', action, route, gw_type, gw_name] |                                         command = ['ip', 'ro', action, route, gw_type, gw_name] | ||||||
|                                         commands_list.append({'cidr': cidr, 'command': command}) |                                     local_logger.info(msg=' '.join(command)) | ||||||
| 
 |                                     if not imitate: | ||||||
|             if action == 'delete': |                                         if self.__cmd(command=command) == 0: | ||||||
|                 commands_list = reversed(commands_list) |                                             apply_counter += 1 | ||||||
|             for command in commands_list: |  | ||||||
|                 local_logger = logging.getLogger(command['cidr']) |  | ||||||
|                 local_logger.info(msg=' '.join(command['command'])) |  | ||||||
|                 if not imitate: |  | ||||||
|                     if self.__cmd(command=command['command']) == 0: |  | ||||||
|                         apply_counter += 1 |  | ||||||
| 
 | 
 | ||||||
|             local_logger = logging.getLogger(logger_alias) |             local_logger = logging.getLogger(logger_alias) | ||||||
|             local_logger.info(msg="" |             local_logger.info(msg="" | ||||||
|  | @ -432,12 +426,6 @@ class Route(Connect): | ||||||
|                     force_download=force_download, |                     force_download=force_download, | ||||||
|                     logger_alias=logger_alias |                     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': |             elif name == 'atlassian': | ||||||
|                 return self.__update_source_atlassian( |                 return self.__update_source_atlassian( | ||||||
|                     db_root_path=db_root_path, |                     db_root_path=db_root_path, | ||||||
|  | @ -458,8 +446,8 @@ class Route(Connect): | ||||||
|                     force_download=force_download, |                     force_download=force_download, | ||||||
|                     logger_alias=logger_alias |                     logger_alias=logger_alias | ||||||
|                     ) |                     ) | ||||||
|             elif name == 'githmptoday': |             elif name == 'wwwhmptoday': | ||||||
|                 return self.__update_source_githmptoday( |                 return self.__update_source_wwwhmptoday( | ||||||
|                     db_root_path=db_root_path, |                     db_root_path=db_root_path, | ||||||
|                     download_user=download_user, |                     download_user=download_user, | ||||||
|                     download_pass=download_pass, |                     download_pass=download_pass, | ||||||
|  | @ -670,63 +658,6 @@ class Route(Connect): | ||||||
|             return True |             return True | ||||||
|         return False |         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( |     def __update_source_herrbischoff( | ||||||
|         self, |         self, | ||||||
|         db_root_path: str, |         db_root_path: str, | ||||||
|  | @ -915,7 +846,7 @@ class Route(Connect): | ||||||
|                 remove(db_source_file) |                 remove(db_source_file) | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|     def __update_source_githmptoday( |     def __update_source_wwwhmptoday( | ||||||
|         self, |         self, | ||||||
|         db_root_path: str, |         db_root_path: str, | ||||||
|         download_user: str, |         download_user: str, | ||||||
|  | @ -924,7 +855,7 @@ class Route(Connect): | ||||||
|         logger_alias: str = inspect.stack()[0].function |         logger_alias: str = inspect.stack()[0].function | ||||||
|         ) -> bool: |         ) -> bool: | ||||||
|         local_logger = logging.getLogger(logger_alias) |         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'): |             if not path.exists(db_root_path + sep + 'sources'): | ||||||
|                 force_download = True |                 force_download = True | ||||||
|             if force_download: |             if force_download: | ||||||
|  | @ -1093,12 +1024,12 @@ if __name__ == "__main__": | ||||||
|             enable_sources['ip2location']['db_source_code'] = ( |             enable_sources['ip2location']['db_source_code'] = ( | ||||||
|                 conf_sources.data['ip2l_database_code'] |                 conf_sources.data['ip2l_database_code'] | ||||||
|                 ) |                 ) | ||||||
|         if 'githmptoday' in enable_sources: |         if 'wwwhmptoday' in enable_sources: | ||||||
|             enable_sources['githmptoday']['download_user'] = ( |             enable_sources['wwwhmptoday']['download_user'] = ( | ||||||
|                 conf_sources.data['githmptoday_user'] |                 conf_sources.data['wwwhmptoday_user'] | ||||||
|                 ) |                 ) | ||||||
|             enable_sources['githmptoday']['download_pass'] = ( |             enable_sources['wwwhmptoday']['download_pass'] = ( | ||||||
|                 conf_sources.data['githmptoday_pass'] |                 conf_sources.data['wwwhmptoday_pass'] | ||||||
|                 ) |                 ) | ||||||
| 
 | 
 | ||||||
|     logging.basicConfig( |     logging.basicConfig( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user