Skip to content

Commit

Permalink
Add Changed Key detection to key menu function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pack3tL0ss committed Sep 17, 2019
1 parent 18557bd commit e0f26db
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/PyConsolePi/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import socket
import subprocess
import shlex
import threading
import requests
import time
Expand Down Expand Up @@ -363,7 +364,28 @@ def get_config(var):
return var_out

def bash_command(cmd):
subprocess.run(['/bin/bash', '-c', cmd])
result = subprocess.run(['/bin/bash', '-c', cmd], stderr=subprocess.PIPE)
if result.returncode != 0:
if 'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!' in result.stderr.decode('UTF-8'):
print('\n\n{}'.format(result.stderr.decode('UTF-8')))
while True:
try:
choice = input('\nDo you want to remove the old host key and re-attempt the connection (y/n)? ')
if choice.lower() in ['y', 'yes']:
result = result.stderr.decode('UTF-8').replace('ERROR: ', '')
_cmd = shlex.split(result.split('remove with:\r\n')[1].split('\r\n')[0])
subprocess.run(_cmd)
print('\n')
subprocess.run(['/bin/bash', '-c', cmd])
break
elif choice.lower() in ['n', 'no']:
break
else:
print("\n!!! Invalid selection, please try again.\n")
except (KeyboardInterrupt, EOFError):
break
except ValueError:
print("\n!! Invalid selection, please try again.\n")


def is_valid_ipv4_address(address):
Expand Down

0 comments on commit e0f26db

Please sign in to comment.