Skip to content

Commit

Permalink
Add a way to toggle checking for IP2L updates, bumped cfg ver to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreeeee committed Dec 27, 2023
1 parent 6e261fa commit a6cc17b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 49 deletions.
3 changes: 3 additions & 0 deletions yokkaichi/IP2L_Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def create_last_updated_file(self) -> None:
f.write(str(round(time.time())))

def is_up_to_date(self) -> bool:
if not self.cfg.ip2location_check_for_updates:
return True

YEAR_INDEX: int = 0
MONTH_INDEX: int = 1

Expand Down
6 changes: 4 additions & 2 deletions yokkaichi/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .Printer import Printer
from .structs import CFG

CONFIG_VERSION = "3"
CONFIG_VERSION = "4"
# TODO: Bring this back to a separate file
SAMPLE_CFG = """
# This is an example configuration file for Yokkaichi.
Expand All @@ -20,7 +20,7 @@
# You can pass this without the file location and it will look for yokkaichi.toml in your current location.
# Do not comment any of the config's options, it will currently cause a crash
version = "3" # Changed for every change breaking config compatibility
version = "4" # Changed for every change breaking config compatibility
[platforms]
java = true
Expand Down Expand Up @@ -49,6 +49,7 @@
csv_filename = "IP2LOCATION-LITE-DB1.CSV"
bin_code = "DB11LITEBIN" # Avoid changing this
csv_code = "DB1LITECSV" # Avoid changing this
check_for_updates = true # Will Yokkaichi check for updates to the database every month. Highly recommended to leave it on!
cache = true # Enable for faster speed at the cost of RAM
""".strip()

Expand Down Expand Up @@ -101,6 +102,7 @@ def parse_cfg(cfg_location):
cfg.ip2location_db_csv = cfg_file["ip2location"]["csv_filename"]
cfg.ip2location_bin_code = cfg_file["ip2location"]["bin_code"]
cfg.ip2location_csv_code = cfg_file["ip2location"]["csv_code"]
cfg.ip2location_check_for_updates = cfg_file["ip2location"]["check_for_updates"]
cfg.ip2location_cache = cfg_file["ip2location"]["cache"]

return cfg
Expand Down
1 change: 1 addition & 0 deletions yokkaichi/structs/_CFG.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ class CFG:
ip2location_db_csv: str = field(default_factory=str)
ip2location_bin_code: str = field(default_factory=str)
ip2location_csv_code: str = field(default_factory=str)
ip2location_check_for_updates: bool = field(default_factory=bool)
ip2location_cache: bool = field(default_factory=bool)
51 changes: 4 additions & 47 deletions yokkaichi_tests/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,7 @@
from yokkaichi.structs import CFG

DEFAULT_CFG = """
version = "2"
[platforms]
java = true
bedrock = false
[platforms.additional]
java_query = false
[type]
masscan = true
ip_list = false
[type.options_masscan]
args = "--rate 5000"
[type.options_masscan.countries]
enabled = true
countries = ["US", "DE"]
[type.options_masscan.list]
enabled = true
list = "masscan_ips.txt"
[type.options_ip_list]
list = "ips.txt"
[scanner]
ports = "25564-25566,25569"
threads = 100
timeout = 3.0
offline_printing = "disabled"
output = "out.json"
[ip2location]
enabled = false
databases_location = "ip2location_dbs/"
bin_filename = "IP2LOCATION-LITE-DB11.BIN"
csv_filename = "IP2LOCATION-LITE-DB1.CSV"
bin_code = "DB11LITEBIN"
csv_code = "DB1LITECSV"
cache = true
"""

DEFAULT_CFG = """
version = "3"
version = "4"
[platforms]
java = true
Expand Down Expand Up @@ -84,6 +39,7 @@
csv_filename = "IP2LOCATION-LITE-DB1.CSV"
bin_code = "DB11LITEBIN"
csv_code = "DB1LITECSV"
check_for_updates = true
cache = true
"""

Expand Down Expand Up @@ -112,6 +68,7 @@ def default_cfg(x):
ip2location_db_csv="IP2LOCATION-LITE-DB1.CSV",
ip2location_bin_code="DB11LITEBIN",
ip2location_csv_code="DB1LITECSV",
ip2location_check_for_updates=True,
ip2location_cache=True,
)

Expand All @@ -122,7 +79,7 @@ def mockexit(x):

def fake_cfg(x):
cfg = DEFAULT_CFG
cfg = cfg.replace('version = "3"', 'version = "0"')
cfg = cfg.replace('version = "4"', 'version = "0"')
return tomllib.loads(cfg)

monkeypatch.setattr("builtins.exit", mockexit)
Expand Down

0 comments on commit a6cc17b

Please sign in to comment.