This may be one of those uses that most people wouldn't find too useful, but I thought I'd share the setup since it helped me to solve a problem that had stumped me for awhile.
There are various reasons one might want to push notifications from your home network to your mobile device (notifying of changes in your dynamic IP address, alerts from smart home sensors/smoke alarms/security alarms, etc.), and while there are some easy ways to do this using third-party services, I dislike solutions that rely on third parties too much.
So for this example, I check whether my ISP has changed my home IP address, and if it has, I push a notification to my cell phone in the form of a text file with the new IP address. For the Pine, I'm using the latest Debian image from here, with Tor installed:
Then, on my Android phone I have installed SSHelper, which I obtained via the f-droid repositories, but you can also install from the Play Store I believe. I also have installed Orbot, which I recommend getting from the official Guardian Project repository rather than the Play Store, though I believe it is also there.
To set up SSHelper to run as a hidden service, you will need to open the settings dialog in Orbot, and scroll down to the Hidden Service Hosting section, and check the box for Hidden Service Hosting. Click on Hidden Service Ports and pick whatever port you have selected in SSHelper (for this example I'm using the default, 2222). Next, you need to shut down Orbot and restart it so that it will generate your .onion address. Go into the hidden service settings again, click on the .onion hostname, and copy that address. You might want to write it down or save it as a text file since you'll need it later.
Next, on the Pine, attempt to access the Android phone using the .onion hostname:
Once you've confirmed this works, you need to set up the SSH server to use a keypair instead of password, so on the Pine type these two commands:
Type in the password when it prompts you, then exit once the devices finish the key exchange. Now, on the Android phone, enter the SSHelper settings and check the box Disable password logins.
Next, I wrote a perl script that checks with a public site and creates a text file containing the IP, as well as a log of prior IPs and when they changed:
Now, all that's left is to create the three files and set the script to run periodically via crontab:
I set the cronjob to run hourly at five past the hour (because why not?), but obviously anything would work:
Assuming everything went smoothly, you should have three files created in your SSH root directory: checked lets you know how recently it was checked, lastip should be the most recent IP address, and history should list each prior IP address.
As I indicated at the beginning, this particular script is just an example of one use, but once you have the SSH hidden service running, you can push any notifications or files you might want to that folder.
There are various reasons one might want to push notifications from your home network to your mobile device (notifying of changes in your dynamic IP address, alerts from smart home sensors/smoke alarms/security alarms, etc.), and while there are some easy ways to do this using third-party services, I dislike solutions that rely on third parties too much.
So for this example, I check whether my ISP has changed my home IP address, and if it has, I push a notification to my cell phone in the form of a text file with the new IP address. For the Pine, I'm using the latest Debian image from here, with Tor installed:
Code:
sudo apt-get install tor
Then, on my Android phone I have installed SSHelper, which I obtained via the f-droid repositories, but you can also install from the Play Store I believe. I also have installed Orbot, which I recommend getting from the official Guardian Project repository rather than the Play Store, though I believe it is also there.
To set up SSHelper to run as a hidden service, you will need to open the settings dialog in Orbot, and scroll down to the Hidden Service Hosting section, and check the box for Hidden Service Hosting. Click on Hidden Service Ports and pick whatever port you have selected in SSHelper (for this example I'm using the default, 2222). Next, you need to shut down Orbot and restart it so that it will generate your .onion address. Go into the hidden service settings again, click on the .onion hostname, and copy that address. You might want to write it down or save it as a text file since you'll need it later.
Next, on the Pine, attempt to access the Android phone using the .onion hostname:
Code:
torsocks ssh -p 2222 123456abcde.onion
Once you've confirmed this works, you need to set up the SSH server to use a keypair instead of password, so on the Pine type these two commands:
Code:
ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ''
torsocks ssh-copy-id -i ~/.ssh/id_dsa.pub -p 2222 12345abcdef.onion
Type in the password when it prompts you, then exit once the devices finish the key exchange. Now, on the Android phone, enter the SSHelper settings and check the box Disable password logins.
Next, I wrote a perl script that checks with a public site and creates a text file containing the IP, as well as a log of prior IPs and when they changed:
Code:
#!/usr/bin/perl -w
use strict;
my $nip;
my $now = localtime();
my $ipcheck = "http://ipecho.net/plain";
my $result = qx{curl --silent $ipcheck};
if($result =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
$nip = $1;
}
else { die "regex failed to match an IP: $!"; }
open(LAST, "<lastip") or die "Can't open lastip";
my $lastip = <LAST>;
close(LAST);
unless($lastip eq $nip) {
open(LAST, ">lastip") or die "Can't open lastip";
print LAST $nip;
close(LAST);
print qx{torsocks scp -P 2222 /home/pineuser/lastip 12345abcdef.onion:/sdcard/ipchecker/};
open(LOG, ">>history") or die "Can't open history";
print LOG "$nip\t[$now]\n";
close(LOG);
print qx{torsocks scp -P 2222 /home/pineuser/history 12345abcdef.onion:/sdcard/ipchecker/};
}
else {
open(CHECKED, ">checked") or die "Can't open checked";
print CHECKED $now;
close(CHECKED);
print qx{torsocks scp -P 2222 /home/pineuser/checked 12345abcdef.onion:/sdcard/ipchecker/};
}
Now, all that's left is to create the three files and set the script to run periodically via crontab:
Code:
touch lastip history checked
crontab -e
I set the cronjob to run hourly at five past the hour (because why not?), but obviously anything would work:
Code:
5 * * * * /home/pineuser/notifier.pl
Assuming everything went smoothly, you should have three files created in your SSH root directory: checked lets you know how recently it was checked, lastip should be the most recent IP address, and history should list each prior IP address.
As I indicated at the beginning, this particular script is just an example of one use, but once you have the SSH hidden service running, you can push any notifications or files you might want to that folder.