mirror of
https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git
synced 2025-09-03 05:02:40 +02:00
SSH Control script (#1711)
This commit is contained in:
2
firmware_mod/config/autostart/dropbear
Executable file
2
firmware_mod/config/autostart/dropbear
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/system/sdcard/controlscripts/dropbear
|
66
firmware_mod/controlscripts/dropbear
Executable file
66
firmware_mod/controlscripts/dropbear
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
PIDFILE="/run/dropbear.pid"
|
||||
|
||||
if [ ! -d /system/sdcard/root/.ssh ]; then
|
||||
mkdir /system/sdcard/root/.ssh
|
||||
fi
|
||||
|
||||
if [ ! -f /root/.ssh/authorized_keys ]; then
|
||||
touch /root/.ssh/authorized_keys
|
||||
fi
|
||||
|
||||
if [ ! -f /system/sdcard/config/ssh.conf ]; then
|
||||
cp /system/sdcard/config/ssh.conf.dist /system/sdcard/config/ssh.conf
|
||||
fi
|
||||
|
||||
if [ ! -f /system/bin/scp ]; then
|
||||
ln -s /system/sdcard/bin/dropbearmulti /system/bin/scp
|
||||
fi
|
||||
|
||||
if [ ! -f /var/log/lastlog ]; then
|
||||
touch /var/log/lastlog 2>/dev/null
|
||||
fi
|
||||
|
||||
source /system/sdcard/config/ssh.conf
|
||||
|
||||
status()
|
||||
{
|
||||
pid="$(cat "$PIDFILE" 2>/dev/null)"
|
||||
if [ "$pid" ]; then
|
||||
# Prints PID: $pid if exists and returns 0(no error) else returns 1(error condition)
|
||||
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
|
||||
fi
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
if [ "$(status)" != "" ]; then
|
||||
echo "A Dropbear sever is already running, please stop it or reboot"
|
||||
else
|
||||
echo "Starting Dropbear Server"
|
||||
|
||||
if [ "$ssh_password" = "off" ]; then
|
||||
/system/sdcard/bin/dropbearmulti dropbear -s -R -p $ssh_port
|
||||
else
|
||||
/system/sdcard/bin/dropbearmulti dropbear -R -p $ssh_port
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
pid="$(cat "$PIDFILE" 2>/dev/null)"
|
||||
if [ "$pid" ]; then
|
||||
kill "$pid"
|
||||
rm "$PIDFILE" 1> /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
start
|
||||
else
|
||||
case $1 in start|stop|status)
|
||||
$1
|
||||
;;
|
||||
esac
|
||||
fi
|
@@ -197,33 +197,6 @@ else
|
||||
insmod /system/sdcard/driver/sensor_jxf23.ko data_interface=2 pwdn_gpio=-1 reset_gpio=18 sensor_gpio_func=0
|
||||
fi
|
||||
|
||||
## Start SSH Server:
|
||||
## Check for .ssh folder, create if not present
|
||||
if [ ! -d /system/sdcard/root/.ssh ]; then
|
||||
mkdir /system/sdcard/root/.ssh
|
||||
echo "Created .ssh directory" >> $LOGPATH
|
||||
fi
|
||||
|
||||
if [ ! -f /root/.ssh/authorized_keys ]; then
|
||||
touch /root/.ssh/authorized_keys
|
||||
echo "Created authorized_keys file" >> $LOGPATH
|
||||
fi
|
||||
|
||||
if [ ! -f $CONFIGPATH/ssh.conf ]; then
|
||||
cp $CONFIGPATH/ssh.conf.dist $CONFIGPATH/ssh.conf
|
||||
fi
|
||||
|
||||
chmod 600 -R /root/.ssh
|
||||
source $CONFIGPATH/ssh.conf
|
||||
ln -s /system/sdcard/bin/dropbearmulti /system/bin/scp
|
||||
touch /var/log/lastlog 2>/dev/null
|
||||
if [ "$ssh_password" = "off" ]; then
|
||||
dropbear_status=$(/system/sdcard/bin/dropbearmulti dropbear -s -R -p $ssh_port)
|
||||
else
|
||||
dropbear_status=$(/system/sdcard/bin/dropbearmulti dropbear -R -p $ssh_port)
|
||||
fi
|
||||
echo "dropbear: $dropbear_status" >> $LOGPATH
|
||||
|
||||
## Create a certificate for the webserver
|
||||
if [ ! -f $CONFIGPATH/lighttpd.pem ]; then
|
||||
export OPENSSL_CONF=$CONFIGPATH/openssl.cnf
|
||||
|
@@ -13,7 +13,7 @@ echo ""
|
||||
if [ -n "$F_cmd" ]; then
|
||||
case "$F_cmd" in
|
||||
get_services)
|
||||
services="auto-night-detection debug-on-osd ftp_server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup telegram-bot timelapse"
|
||||
services="auto-night-detection debug-on-osd ftp_server mdns-responder mqtt-control mqtt-status onvif-srvd recording rtsp sound-on-startup dropbear telegram-bot timelapse"
|
||||
for service in $services ; do
|
||||
echo "${service}#:#$(test -f /run/${service}.pid && echo 'started' || echo 'stopped')#:#$(test -f /system/sdcard/config/autostart/${service} && echo 'true' || echo 'false')#:#false"
|
||||
done
|
||||
|
@@ -96,6 +96,12 @@ if [ -n "$F_cmd" ]; then
|
||||
echo "<p>Changing SSH key to: $ssh_key</p>"
|
||||
echo "$ssh_key" > /system/sdcard/root/.ssh/authorized_keys
|
||||
fi
|
||||
|
||||
if [ -n ${F_ssh_key} ] || [ -n ${F_ssh_password} ] || [ -n ${F_ssh_port} ]; then
|
||||
echo "Re"
|
||||
/system/sdcard/controlscripts/dropbear stop
|
||||
/system/sdcard/controlscripts/dropbear start
|
||||
fi
|
||||
if [ -n ${F_connect_timeout} ]; then
|
||||
F_connect_timeout=$(echo "$F_connect_timeout" | sed 's/+/ /g')
|
||||
connect_timeout=$(printf '%b' "${F_connect_timeout//%/\\x}")
|
||||
|
@@ -269,6 +269,7 @@ function autoStartService(action,serviceName) {
|
||||
//Friendly names for known services
|
||||
var serviceFriendlyNames = {
|
||||
"auto-night-detection": "Auto Night Detection",
|
||||
"dropbear": "SSH Server",
|
||||
"debug-on-osd": "Debug on OSD",
|
||||
"ftp_server": "FTP Server",
|
||||
"mdns-responder": "mDNSResponder",
|
||||
|
@@ -78,7 +78,7 @@
|
||||
<input id="ssh_port" class="w3-input" type="number">
|
||||
<br />
|
||||
<input id="ssh_password" class="w3-check w3-theme" type="checkbox" checked="checked" />
|
||||
<label for="ssh_password">Allow SSH password login? (restart required)</label>
|
||||
<label for="ssh_password">Allow SSH password login?</label>
|
||||
<br />
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user