maybe this will be useful , just like some replacement to ganyremote. server edition .
scans media for yours BT devices;
run application if found some available devices.
set password for anyremote. This is useful to protect server
put this file to run every 1 minute in cron.
cat bluetooth.pl
PHP Code:
#!/usr/bin/perl
########################################
# By Aleksander Mischenko aka Mealstrom #
# mail: mischenko.mm[doggy]gmail[dot]com#
# Licence: GPL v3 :D #
# Version: 0.9 beta #
#########################################
#
#
#
# hcitool scan -- timeout 30 sec. Run it in console to get BT MAC
#
# list of processes to be runned or shutdown when BT device is in range
# %processes=(process1,parameters for proc1 , proc2...)
# allowed macs:
# @mac = ("mac1","mac2");
# TODO:
# remake match pattern for BT macs.
#Globals
#delete -password to access without it
%processes=("anyremote","-fe 5050 -f /usr/share/anyremote/cfg-data/Server-mode/all-in-one2.cfg -password -s bluetooth:19 > /dev/null &");
#change this for yours real BT macs
@mac =("00:XX:XX:XX:XX:XX","00:AA:A1:A2:A3:A4");
#change yours home directory
$password_file="/home/xxxxxxxxx/.anyRemote/password";
#change password for access
$password="XXX";
#check if there any allowed mac-address
sub bt_mac_check
{
my @btscan = `hcitool scan`;
#remake match pattern for multiline input
foreach $i(@btscan){
if ($i =~ m/\t(.*)\t/){
# if ($i =~ m/([0-9A-F]{2}:){5}[0-9A-F]{2}/i){
#mach mac address format
foreach (@_){if ($_ eq $1){return 1;}}
}
}
return 0;
}
#check if password is ne
sub passcheck
{
open (PASSWD, "< $password_file") || die("Could not open file!");
while (<PASSWD>) {
if ($_ ne $password){
return 1;
}
}
return 0;
close(PASSWD);
}
#set password for anyremote
sub passset
{
open (PASSWD, "> $password_file") || die("Could not open file!");
print PASSWD $password;
close (PASSWD);
}
if (passcheck){passset;}
$mac_check=bt_mac_check @mac;
#$mac_check=0;
print "maccheck = $mac_check\n";
while (($key, $value) = each (%processes)) {
if ($mac_check){
if (!`pgrep $key`) {
#print "Starting process $key ... \n";
`$key $value`;
}
}
else {
if (`pgrep $key`) {
#print "Process $key is running. So lets kill it ...\n";
`pkill $key`;
}
}
}
Bookmarks