Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old update checks, Pacu uses pip #380

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pacu/last_update.txt

This file was deleted.

52 changes: 0 additions & 52 deletions pacu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from pacu.core import lib
from pacu.core.lib import session_dir
from datetime import datetime

try:
import jq # type: ignore
Expand Down Expand Up @@ -465,54 +464,6 @@ def fetch_data(self, data: List[str], module: str, args: str, force=False) -> bo
self.exec_module(['exec', module])
return True

def check_for_updates(self):
TIME_FORMAT = '%Y-%m-%d'
UPDATE_CYCLE = 7 # Days
UPDATE_INFO_PATH = lib.home_dir()/'update_info.json'
LAST_UPDATE_PATH = lib.pacu_dir()/'last_update.txt'
UPDATE_MSG = '''Pacu has a new version available! Clone it from GitHub to receive the updates.
git clone https://github.com/RhinoSecurityLabs/pacu.git'''

with open(LAST_UPDATE_PATH, 'r') as f:
local_last_update = f.read().rstrip()

datetime_now = datetime.now()
datetime_local = datetime.strptime(local_last_update, TIME_FORMAT)

datetime_last_check = datetime.min
latest_cached = datetime.min

# update_info.json structure:
# { 'last_check':'YYYY-MM-DD', 'latest_cached':'YYYY-MM-DD'}
# Create a update_info.json if not exist
update_info = {}
if os.path.isfile(UPDATE_INFO_PATH):
with open(UPDATE_INFO_PATH, 'r') as f:
update_info = json.load(f)
datetime_last_check = datetime.strptime(update_info['last_check'], TIME_FORMAT)
latest_cached = datetime.strptime(update_info['latest_cached'], TIME_FORMAT)

# Check upstream
if (datetime_now - datetime_last_check).days >= UPDATE_CYCLE:
latest_update = requests.get(
'https://raw.githubusercontent.com/RhinoSecurityLabs/pacu/master/pacu/last_update.txt').text.rstrip()
latest = datetime.strptime(latest_update, TIME_FORMAT)

update_info['latest_cached'] = latest.strftime(TIME_FORMAT)
update_info['last_check'] = datetime_now.strftime(TIME_FORMAT)
with open(UPDATE_INFO_PATH, 'w') as f:
json.dump(update_info, f)

if datetime_local < latest:
print(UPDATE_MSG)
return True
# Local check
elif datetime_local < latest_cached:
print(datetime_local, latest_cached)
print(UPDATE_MSG)
return True
return False

def key_info(self, alias='') -> Union[Dict[str, Any], bool]:
""" Return the set of information stored in the session's active key
or the session's key with a specified alias, as a dictionary. """
Expand Down Expand Up @@ -1889,8 +1840,6 @@ def run_gui(self) -> None:
self.initialize_tab_completion()
display_pacu_help()

self.check_for_updates()

idle_ready = True

self.check_user_agent()
Expand Down Expand Up @@ -1976,7 +1925,6 @@ def run(self) -> None:
exit()
self.run_cli(args)
elif any([args.list_modules, args.pacu_help, args.module_info]):
self.check_for_updates()
self.run_cli(args)
else:
self.run_gui()
Expand Down
105 changes: 0 additions & 105 deletions tests/test_pacu_update.py

This file was deleted.