Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rM-self-serve committed Apr 20, 2023
1 parent be57df9 commit 40e0eaf
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 213 deletions.
104 changes: 73 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,118 @@
# WebInterface-OnBoot

> bash-hack branch
This simple program will convince the ReMarkable Tablet to start the web interface after booting without the usb cord being plugged in. It can then be reached internally at 10.11.99.1:80 without the usb cord.
This simple program will convince the ReMarkable Tablet to start the web interface after booting without the usb cable being plugged in. Eliminates the need to switch on the web interface setting after connecting the usb cable. Also useful for clients that leverage the web interface for file operations, namely access over [wifi](https://github.com/rM-self-serve/webinterface-wifi).


## Xochitl Version Compatibility

Tested from v1.9 to v3.3.2-beta on rM1
Tested from v1.9 to v3.3.2 on rM1

- ✅ <= v2.14
- ✅ >= v2.15 - Requires simple binary hack, see below

### Type the following commands after ssh'ing into the ReMarkable Tablet

## Maintain Internal Web Interface Accessibility

> Only needed for software clients that leverage the web interface
The web interface server will continue running on 10.11.99.1:80 even if the usb cable is disconnected, meaning it can still be used for file uploads/downloads. The only way it will stop running is if switched off in the settings. Disconnecting the usb cable will remove the ip address from the usb0 network interface, making the web interface inaccessible. Use the following program to ensure the ip stays set and the web interface is internally accessible at 10.11.99.1:80.

https://github.com/rM-self-serve/webinterface-persist-ip


### Type the following commands after ssh'ing into the ReMarkable Tablet

## Install

`wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/bash-hack/install-webint-ob.sh && bash install-webint-ob.sh`
`$ wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/master/install-webint-ob.sh && bash install-webint-ob.sh`

## Remove

`wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/bash-hack/remove-webint-ob.sh && bash remove-webint-ob.sh`
`$ wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/master/remove-webint-ob.sh && bash remove-webint-ob.sh`

## Use

To use the application, run:
### To use webinterface-onboot, run:

- `systemctl enable --now webinterface-onboot`
`$ systemctl enable --now webinterface-onboot`

Each time webinterface-onboot is enabled, the web-interface setting will need to be enabled within the settings menu via a cord sometime between when the device was turned on and before it is turned off. After that, the web interface will be running and internally accessible on 10.11.99.1:80 every time the device is started.
> the web interface will start the next time the device does, and every time after
### To stop using webinterface-onboot, run:

## How Does it Work?

If the field 'WebInterfaceEnabled' is set to 'true' in /etc/remarkable.conf, xochitl will see if the 'usb0' network interface has an ip address and run the web-interface website on that ip address if so.

Thus, before xochitl starts:
- set WebInterfaceEnabled=true in /etc/remarkable.conf
- set the usb0 interface ip address to 10.11.99.1/32
`$ systemctl disable --now webinterface-onboot`

The actual web-interface website will continue running on 10.11.99.1:80 even if the usb0 interface does not have the 10.11.99.1 ip address. Disconnecting the usb cord will automatically remove the 10.11.99.1 ip from the usb0 interface, so this program runs in an infinite loop and will ensure the ip stays set.
## Binary Hack for Xochitl >= v2.15

> :warning: Not tested on the Remarkable Tablet 2, though the rM2 xochitl binaries were successfully converted/reverted; decompilation seems to suggest testing is safe and the hack will work fine
## Binary Hack for >= 2.15
> This will force the web interface to use the usb0 network interface even if the usb1 network interface is connected to your device
> :warning: Not tested on the Remarkable Tablet 2
The provided functionality to apply/revert the hack will first create a backup of xochitl, then a temporary file in which the strings of the binary are changed. If the temporary file is successfully converted, it will replace the xochitl binary in /usr/bin/.

The provided functions to apply/revert the hack will first create a backup of xochitl, then a temporary file in which the strings of the binary are changed. If the temporary file is successfully converted, it will replace the xochitl binary in /usr/bin/.

### Apply Hack

This will only need to be done once unless you upgrade.
This will only need to be done once, unless you upgrade:

`$ webinterface-onboot --apply-hack`

- `webinterface-onboot --apply-hack`

### Revert Hack

Try to restore from backup or reverse hack.
Restore from backup or reverse hack:

`$ webinterface-onboot --revert-hack`


- `webinterface-onboot --revert-hack`
## How Does it Work?

### Definitions

web interface:
- the server/website that runs on 10.11.99.1:80 and allows file uploads/downloads

usb0/usb1 network interface:
- the device within the tablet that handles the ethernet connection

### Webinterface-Onboot

When xochitl starts, it determines whether or not it should run the web interface. It will first check that the field 'WebInterfaceEnabled' is set to 'true' in /home/root/.config/remarkable/xochitl.conf. If so, it then checks if the usb0 network interface has an ip address. If so, it will run the web interface on that ip address.

Thus, before xochitl starts:
- set WebInterfaceEnabled=true in /home/root/.config/remarkable/xochitl.conf
- give the usb0 network interface the ip address 10.11.99.1/32

### Info
> Versions >= v2.15 also require the usb0 network interface to be connected to a computer, so we need the...
### Binary Hack

All the hack does to the xochitl binary:

- change the string 'usb0' to 'usbF'
- change the string 'usb1' to 'usb0'
- change the string 'usb0' to 'usbF'
- change the string 'usb1' to 'usb0'

The strings 'usb0' and 'usb1' only occur once in the binary and appear only to be used within the function that decides on which network interface the web interface website should be started on.

Since we are changing hard-coded strings in the binary, the code that uses these strings will roughly be changed from:

```
primary_interface = QNetworkInterface::interfaceFromName('usb0')
fallback_interface = QNetworkInterface::interfaceFromName('usb1')
```

To:

```
primary_interface = QNetworkInterface::interfaceFromName('usbF')
fallback_interface = QNetworkInterface::interfaceFromName('usb0')
```

Without the hack, xochitl will check to see that the primary network interface, usb0, **has an ip address and is connected to a computer** in order to start the web interface on that ip address. If those conditions are not satisfied, xochitl will fallback to checking the usb1 network interface. But for the fallback interface, xochitl **only checks for an ip address** in order to start the web interface, **not if it is connected to a computer**.

The strings 'usb0' and 'usb1' appear only to be used when deciding on which network interface the web-interface website will be started on.
We can give the usb0 network interface an ip address at any time, but we can not fake the connection to the computer as it is deduced by the network interface's operational state. This means that without the cable plugged in, the conditions necessary to start the web interface on the primary network interface, usb0, can never be satisfied. Though, this also means that if the usb0 network interface was to be evaluated as the fallback interface, we could give it an ip address to satisfy the conditions necessary to start the web interface. This is what we'll do!

Without the hack, xochitl will check to see that the 'usb0' interface has an ip address and is connected to a device in order to start the web-interface. If not it will fallback to the 'usb1' interface, but then only check for an ip address in order to start the web-interface.
In order to evaluate the usb0 network interface as the fallback network interface, all we need to do is change the string 'usb1' to 'usb0' within the xochitl binary.

If the interface name string, i.e. 'usb0', is changed in the binary, xochitl will look for a network interface with that new name instead. Since webinterface-onboot ensures that the 'usb0' interface always has an ip address, we can change the 'usb1' string to 'usb0' so that the 'usb0' interface is the fallback and only needs an ip for the web-interface to start on it. I am not quite sure of the function of the 'usb1' interface, so I changed the inital occurance of 'usb0' to 'usbF', so that xochitl can not find the network interface and will always fallback to 'usb0'. It may be wiser to leave the intial occurance of 'usb0' as 'usb0'.
I am not quite sure what the function of the usb1 network interface is, so the hack changes the initial occurrence of 'usb0' to 'usbF' so that xochitl can not find the primary network interface and will always fallback to usb0, and so that there will be only one occurrence of the string 'usb0' in the binary. It may be wiser to leave the initial occurrence of the string 'usb0' as 'usb0', or change it to 'usb1'.

121 changes: 90 additions & 31 deletions install-webint-ob.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
#!/usr/bin/env bash
# Copyright (c) 2023 rM-self-serve
# SPDX-License-Identifier: MIT

# webinterface_onboot_sha256sum='5072b216774f2ca24ac0933d4633a6e2d64e5b7426bcbcac48f74cc56f9c3ab0'
# service_file_sha256sum='224fe11abdc0bd332c9946ffda3fe38687038dbf4bd65982b88815ab90f5a8cf'
webinterface_onboot_sha256sum='47d712800b01bea60281d8eadf6ca0f47e1c55309c68a5e0b2c2dde33728492f'
service_file_sha256sum='57d7f1f6ebe7bfccf435c11b12e4bec1f58f72f1a7af963e5e58e626f241ccf6'

release='v1.1.0'

installfile='./install-webint-ob.sh'
pkgname='webinterface-onboot'
localbin='/home/root/.local/bin'
binfile="${localbin}/webinterface-onboot"
servicefile='/lib/systemd/system/webinterface-onboot.service'
binfile="${localbin}/${pkgname}"
servicefile="/lib/systemd/system/${pkgname}.service"

remove_installfile() {
read -r -p "Would you like to remove installation script? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
printf "Exiting installer and removing script\n"
[[ -f $installfile ]] && rm $installfile
;;
*)
printf "Exiting installer and leaving script\n"
;;
esac
}

printf "\nwebinterface-onboot\n"
printf "\nEnable the web interface on boot\n"
printf "This program will be installed in %s\n" "${localbin}"
printf "%s will be added to the path in ~/.bashrc if necessary\n" "${localbin}"
echo ''
echo "$pkgname"
echo ''
echo "Enable the web interface on boot"
echo ''
echo "This program will be installed in ${localbin}"
echo "${localbin} will be added to the path in ~/.bashrc if necessary"

read -r -p "Would you like to continue with installation? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
printf "Installing webinterface-onboot\n"
echo "Installing ${pkgname}"
;;
*)
printf "Exiting installer and removing script\n"
[[ -f $installfile ]] && rm $installfile
remove_installfile
exit
;;
esac
Expand All @@ -32,37 +52,76 @@ case :$PATH: in
*) echo "PATH=\"${localbin}:\$PATH\"" >>/home/root/.bashrc ;;
esac

function sha_fail() {
echo "sha256sum did not pass, error downloading webinterface-onboot"
pkg_sha_check() {
if sha256sum -c <(echo "$webinterface_onboot_sha256sum $binfile") >/dev/null 2>&1; then
return 0
else
return 1
fi
}

srvc_sha_check() {
if sha256sum -c <(echo "$service_file_sha256sum $servicefile") >/dev/null 2>&1; then
return 0
else
return 1
fi
}

sha_fail() {
echo "sha256sum did not pass, error downloading ${pkgname}"
echo "Exiting installer and removing installed files"
[[ -f $binfile ]] && rm $binfile
[[ -f $installfile ]] && rm $installfile
[[ -f $servicefile ]] && rm $servicefile
remove_installfile
exit
}

[[ -f $binfile ]] && rm $binfile
wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/bash-hack/webinterface-onboot \
-P $localbin
need_bin=true
if [ -f $binfile ]; then
if pkg_sha_check; then
need_bin=false
echo "Already have the right version of ${pkgname}"
else
rm $binfile
fi
fi
if [ "$need_bin" = true ]; then
wget "https://github.com/rM-self-serve/${pkgname}/releases/download/${release}/${pkgname}" \
-P "$binfile"

# if ! sha256sum -c <(echo "$webinterface_onboot_sha256sum $binfile") >/dev/null 2>&1; then
# sha_fail
# fi
if ! pkg_sha_check; then
sha_fail
fi

chmod +x $localbin/webinterface-onboot
chmod +x "${localbin}/${pkgname}"
fi

[[ -f $servicefile ]] && rm $servicefile
wget https://raw.githubusercontent.com/rM-self-serve/webinterface-onboot/bash-hack/webinterface-onboot.service \
-P /lib/systemd/system
need_service=true
if [ -f $servicefile ]; then
if srvc_sha_check; then
need_service=false
echo "Already have the right version of ${pkgname}"
else
rm $servicefile
fi
fi
if [ "$need_service" = true ]; then
wget "https://github.com/rM-self-serve/${pkgname}/releases/download/${release}/${pkgname}" \
-P "$servicefile"

# if ! sha256sum -c <(echo "$service_file_sha256sum $servicefile") >/dev/null 2>&1; then
# sha_fail
# fi
if ! srvc_sha_check; then
sha_fail
fi
fi

systemctl daemon-reload

printf '\nFinished installing webinterface-onboot, removing install script\n\n'
printf 'To auto start the application after restarting the device, run:\n'
printf 'systemctl enable --now webinterface-onboot\n\n'
echo ""
echo "Finished installing ${pkgname}, removing install script"
echo ""
echo "To use ${pkgname}, run:"
echo ""
echo "systemctl enable --now ${pkgname}"

[[ -f $installfile ]] && rm $installfile
remove_installfile
38 changes: 29 additions & 9 deletions remove-webint-ob.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
#!/usr/bin/env bash
# Copyright (c) 2023 rM-self-serve
# SPDX-License-Identifier: MIT

pkgname='webinterface-onboot'
removefile='./remove-webint-ob.sh'
localbin='/home/root/.local/bin'
binfile="${localbin}/${pkgname}"
servicefile="/lib/systemd/system/${pkgname}.service"

printf "\nRemove webinterface-onboot\n"
remove_removefile() {
read -r -p "Would you like to remove uninstallation script? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
echo "Exiting installer and removing script"
[[ -f $removefile ]] && rm $removefile
;;
*)
echo "Exiting installer and leaving script"
;;
esac
}

echo ''
echo "Remove ${pkgname}"
echo ''
echo "This will not remove the /home/root/.local/bin directory nor the path in .bashrc"
echo "This will not revert the hack nor remove backup files generated by the hack."
echo "Run 'webinterface-onboot --status' to see if the hack needs reverting or if backups exist."
echo ''

read -r -p "Would you like to continue with removal? [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
echo "Removing webinterface-onboot"
;;
echo "Removing ${pkgname}"
;;
*)
echo "exiting removal"
[[ -f $removefile ]] && rm $removefile
exit
;;
echo "Exiting removal"
remove_removefile
exit
;;
esac

[[ -f $binfile ]] && rm $binfile
Expand All @@ -34,6 +54,6 @@ fi

[[ -f $servicefile ]] && rm $servicefile

[[ -f $removefile ]] && rm $removefile
echo "Successfully removed ${pkgname}"

echo "Successfully removed webinterface-onboot"
remove_removefile
Loading

0 comments on commit 40e0eaf

Please sign in to comment.