Initial commit

This commit is contained in:
Mira Kristipati 2024-08-02 14:26:21 -04:00
commit 5a16d7e9bf
4 changed files with 92 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.venv
.ruff_cache

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# Calliope
A monorepo for QoL stuff for adaptation

View file

@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
packages = [
(pkgs.python3.withPackages (python-pkgs: [
python-pkgs.pexpect
python-pkgs.icecream
python-pkgs.mypy
python-pkgs.ruff
]))
pkgs.openssh
];
}

74
reset-ise-passwd/main.py Executable file
View file

@ -0,0 +1,74 @@
#!/usr/bin/env python3
import argparse
import logging
import re
import sys
from logging import getLogger
from typing import List
import pexpect
def login(username: str, password: str) -> pexpect.spawn:
child = pexpect.spawn(
f"ssh -i /dev/null {username}@{addr}",
encoding="utf-8",
logfile=sys.stdout,
)
child.expect("password:")
child.sendline(password)
return child
def change_password(child: pexpect.spawn, old_password: str, new_password: str) -> None:
child.expect("password:")
child.sendline(old_password)
child.expect("[Nn]ew password:")
child.sendline(new_password)
child.expect("[Nn]ew password:")
child.sendline(new_password)
child.expect_list([re.compile("success"), re.compile(f"{username}#")])
logger.info("Changing password to %s", new_password)
def set_new_password_and_verify(
child: pexpect.spawn,
password: str,
new_password: str,
) -> pexpect.spawn:
change_password(child, password, new_password)
child = login(username, new_password)
child.expect(f"{username}#")
return child
if __name__ == "__main__":
logger = getLogger(__name__)
logger.level = logging.DEBUG
parser = argparse.ArgumentParser()
parser.add_argument("addr", help="IP address of the device")
parser.add_argument("username", help="Username of the device", default="admin")
parser.add_argument("password", help="Password of the device")
args = parser.parse_args()
username = args.username
password = args.password
addr = args.addr
try:
passwords: List[str] = [password] + [
"".join([f"{i}{j}" for i in password]) for j in range(4)
]
child = login(username, password)
new_password = passwords.pop()
child = set_new_password_and_verify(child, password, new_password)
while len(passwords):
password = new_password
child.sendline("password")
new_password = passwords.pop()
child = set_new_password_and_verify(child, password, new_password)
except Exception:
logger.exception("man idek anymore, file a bug")