From 82a40aa2b37b4ce2501e42eebbe683eb0a441ec9 Mon Sep 17 00:00:00 2001 From: remittor Date: Sat, 17 Sep 2022 13:15:38 +0300 Subject: [PATCH] Add new menu "Install permanent SSH" --- data/ssh_install.sh | 16 +++++++++++++ data/ssh_patch.sh | 15 ++++++++++++ data/ssh_uninstall.sh | 8 +++++++ install_ssh.py | 53 +++++++++++++++++++++++++++++++++++++++++++ menu.py | 4 ++-- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 data/ssh_install.sh create mode 100644 data/ssh_patch.sh create mode 100644 data/ssh_uninstall.sh create mode 100644 install_ssh.py diff --git a/data/ssh_install.sh b/data/ssh_install.sh new file mode 100644 index 0000000..b2e0823 --- /dev/null +++ b/data/ssh_install.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$( grep 'ssh_patch.sh' /etc/crontabs/root )" != "" ]; then + sh /tmp/ssh_uninstall.sh +fi + +mv -f /tmp/ssh_patch.sh /etc/crontabs/ +chmod +x /etc/crontabs/ssh_patch.sh + +nvram set ssh_en=1 +nvram commit + +grep -v "/etc/crontabs/ssh_patch.sh" /etc/crontabs/root > /etc/crontabs/root.new; +echo "*/1 * * * * /etc/crontabs/ssh_patch.sh >/dev/null 2>&1" >> /etc/crontabs/root.new +mv /etc/crontabs/root.new /etc/crontabs/root +/etc/init.d/cron restart diff --git a/data/ssh_patch.sh b/data/ssh_patch.sh new file mode 100644 index 0000000..2567622 --- /dev/null +++ b/data/ssh_patch.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +[ -e "/tmp/ssh_patch.log" ] && return 0 + +HAVE_PATCH=$( grep '= "release"' /etc/init.d/dropbear ) +if [ -z "$HAVE_PATCH" ]; then + return 0 +fi + +sed -i 's/= "release"/= "XXXXXX"/g' /etc/init.d/dropbear + +/etc/init.d/dropbear enable +/etc/init.d/dropbear restart + +echo "ssh enabled" > /tmp/ssh_patch.log diff --git a/data/ssh_uninstall.sh b/data/ssh_uninstall.sh new file mode 100644 index 0000000..3958c2c --- /dev/null +++ b/data/ssh_uninstall.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +grep -v "/etc/crontabs/ssh_patch.sh" /etc/crontabs/root > /etc/crontabs/root.new; +mv /etc/crontabs/root.new /etc/crontabs/root +/etc/init.d/cron restart + +rm -f /etc/crontabs/ssh_patch.sh + diff --git a/install_ssh.py b/install_ssh.py new file mode 100644 index 0000000..c62c4d3 --- /dev/null +++ b/install_ssh.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys + +sys.path.append(os.path.dirname(os.path.abspath(__file__))) +import gateway +from gateway import die + + +gw = gateway.Gateway() + +fn_dir = 'data/' +fn_local = 'data/ssh_patch.sh' +fn_remote = '/tmp/ssh_patch.sh' +fn_local_i = 'data/ssh_install.sh' +fn_remote_i = '/tmp/ssh_install.sh' +fn_local_u = 'data/ssh_uninstall.sh' +fn_remote_u = '/tmp/ssh_uninstall.sh' + +action = 'install' +if len(sys.argv) > 1: + if sys.argv[1].startswith('u') or sys.argv[1].startswith('r'): + action = 'uninstall' + +if action == 'install': + gw.upload(fn_local, fn_remote) + gw.upload(fn_local_i, fn_remote_i) + +gw.upload(fn_local_u, fn_remote_u) + +print("All files uploaded!") +''' +if action == 'install': + gw.ssh_close() + import passw + gw = gateway.Gateway() + if not gw.ping(): + die('SSH not active!') +''' + +print("Run scripts...") +if action == 'install': + gw.run_cmd("sh " + fn_remote_i) +else: + gw.run_cmd("sh " + fn_remote_u) + +gw.run_cmd("rm -f " + fn_remote) +gw.run_cmd("rm -f " + fn_remote_i) +gw.run_cmd("rm -f " + fn_remote_u) + +print("Ready! The SSH patch installed.") diff --git a/menu.py b/menu.py index 1c44858..7c896e7 100644 --- a/menu.py +++ b/menu.py @@ -56,7 +56,7 @@ def menu2_show(): print(' 4 - Create a backup of the specified partition') print(' 5 - Uninstall EN/RU languages') print(' 6 - Set kernel boot address') - print(' 7 - ') + print(' 7 - Install permanent SSH') print(' 8 - __test__') print(' 9 - [[ Reboot device ]]') print(' 0 - Return to main menu') @@ -68,7 +68,7 @@ def menu2_process(id): if id == 4: return [ "create_backup.py", "part" ] if id == 5: return [ "install_lang.py", "uninstall" ] if id == 6: return "activate_boot.py" - if id == 7: return None + if id == 7: return "install_ssh.py" if id == 8: return "test.py" if id == 9: return "reboot.py" if id == 0: return "__menu1"