From a312b3ad936317a3f96bac6039170ba6daf6a440 Mon Sep 17 00:00:00 2001 From: Arne Fitzenreiter Date: Sat, 16 Aug 2008 17:44:44 +0200 Subject: [PATCH] Add bluetooth.cgi only rfcomm/modem support yet --- config/menu/EX-bluetooth.menu | 5 + config/rootfiles/packages/bluez | 2 + html/cgi-bin/bluetooth.cgi | 187 +++++++++++++++++++++++++++++++ html/cgi-bin/wlanap.cgi | 0 src/initscripts/init.d/bluetooth | 43 ++++--- 5 files changed, 223 insertions(+), 14 deletions(-) create mode 100644 config/menu/EX-bluetooth.menu create mode 100644 html/cgi-bin/bluetooth.cgi mode change 100755 => 100644 html/cgi-bin/wlanap.cgi diff --git a/config/menu/EX-bluetooth.menu b/config/menu/EX-bluetooth.menu new file mode 100644 index 0000000000..b7f1728a59 --- /dev/null +++ b/config/menu/EX-bluetooth.menu @@ -0,0 +1,5 @@ + $subipfire->{'55.bluetooth'} = {'caption' => bluetooth, + 'uri' => '/cgi-bin/bluetooth.cgi', + 'title' => bluetooth, + 'enabled' => 1, + }; diff --git a/config/rootfiles/packages/bluez b/config/rootfiles/packages/bluez index 188292b4ba..470c1ccb62 100644 --- a/config/rootfiles/packages/bluez +++ b/config/rootfiles/packages/bluez @@ -1,3 +1,5 @@ +srv/web/ipfire/cgi-bin/bluetooth.cgi +var/ipfire/menu.d/EX-bluetooth.menu etc/rc.d/init.d/bluetooth etc/rc.d/rc3.d/S16bluetooth etc/rc.d/rc0.d/K84bluetooth diff --git a/html/cgi-bin/bluetooth.cgi b/html/cgi-bin/bluetooth.cgi new file mode 100644 index 0000000000..32bd8e8e07 --- /dev/null +++ b/html/cgi-bin/bluetooth.cgi @@ -0,0 +1,187 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### +# + +use strict; + +# enable only the following on debugging purpose +use warnings; +use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require '/var/ipfire/lang.pl'; +require '/var/ipfire/header.pl'; + +my $debug = 0; +my $i = 0; +my $errormessage = ''; +my $status_started = "$Lang::tr{'running'}"; +my $status_stopped = "$Lang::tr{'stopped'}"; + +# get rid of used only once warnings +my @onlyonce = ( $Header::colourgreen, $Header::colourred ); +undef @onlyonce; + +my %selected=(); +my %checked=(); +my %color = (); +my %mainsettings = (); + +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + +my %bluetoothsettings=(); +$bluetoothsettings{'PASSKEY_AGENT'} = 'on'; +$bluetoothsettings{'PWD'} = '12345'; +$bluetoothsettings{'RFCOMM0_BIND'} = 'off'; +$bluetoothsettings{'RFCOMM0_DEVICE'} = ''; +$bluetoothsettings{'RFCOMM0_CHANNEL'} = '1'; +$bluetoothsettings{'RFCOMM1_BIND'} = 'off'; +$bluetoothsettings{'RFCOMM1_DEVICE'} = ''; +$bluetoothsettings{'RFCOMM1_CHANNEL'} = '1'; + +&General::readhash("/var/ipfire/bluetooth/settings", \%bluetoothsettings); + +my %cgiparams=(); +$cgiparams{'ACTION'} = ''; +$cgiparams{'RUNNING'} = 'off'; +$cgiparams{'PASSKEY_AGENT'} = 'off'; +$cgiparams{'PWD'} = ''; +$cgiparams{'RFCOMM0_BIND'} = 'off'; +$cgiparams{'RFCOMM0_DEVICE'} = ''; +$cgiparams{'RFCOMM0_CHANNEL'} = ''; +$cgiparams{'RFCOMM1_BIND'} = 'off'; +$cgiparams{'RFCOMM1_DEVICE'} = ''; +$cgiparams{'RFCOMM1_CHANNEL'} = ''; + + +&Header::getcgihash(\%cgiparams); + +&Header::showhttpheaders(); + +if ( $cgiparams{'ACTION'} eq "$Lang::tr{'save'}" ){ + $bluetoothsettings{'PASSKEY_AGENT'} = $cgiparams{'PASSKEY_AGENT'}; + $bluetoothsettings{'PWD'} = $cgiparams{'PWD'}; + if ( (length($bluetoothsettings{'PWD'}) < 4) || (length($bluetoothsettings{'PWD'}) > 8) ){ + $errormessage .= "Invalid length in Passphrase. Must be between 4 and 8 characters.
"; + } + $bluetoothsettings{'RFCOMM0_BIND'} = $cgiparams{'RFCOMM0_BIND'}; + $bluetoothsettings{'RFCOMM1_BIND'} = $cgiparams{'RFCOMM1_BIND'}; + $bluetoothsettings{'RFCOMM0_DEVICE'} = $cgiparams{'RFCOMM0_DEVICE'}; + $bluetoothsettings{'RFCOMM1_DEVICE'} = $cgiparams{'RFCOMM1_DEVICE'}; + $bluetoothsettings{'RFCOMM0_CHANNEL'} = $cgiparams{'RFCOMM0_CHANNEL'}; + $bluetoothsettings{'RFCOMM1_CHANNEL'} = $cgiparams{'RFCOMM1_CHANNEL'}; + +# TODO: CHECK RFCOMM DEVICES + + if ( $errormessage eq '' ){ + &WriteConfig(); + system("/usr/local/bin/addonctrl bluetooth restart >/dev/null 2>&1") + } +} + +&Header::openpage('Bluetooth', 1, '', ''); +&Header::openbigbox('100%', 'left', '', $errormessage); +print "
"; + +if ( $errormessage ){ + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage\n"; + print " \n"; + &Header::closebox(); +} + + +# Found this usefull piece of code in BlockOutTraffic AddOn 8-) +# fwrules.cgi +############### +# DEBUG DEBUG +if ( $debug ){ + &Header::openbox('100%', 'left', 'DEBUG'); + my $debugCount = 0; + foreach my $line (sort keys %cgiparams) { + print "$line = '$cgiparams{$line}'
\n"; + $debugCount++; + } + print " Count: $debugCount\n"; + &Header::closebox(); +} +# DEBUG DEBUG +############### + + +my $checked_passkey_agent = ''; +my $checked_rfcomm0_bind = ''; +my $checked_rfcomm1_bind = ''; + +$checked_passkey_agent = "checked='checked'" if ( $bluetoothsettings{'PASSKEY_AGENT'} eq 'on' ); +$checked_rfcomm0_bind = "checked='checked'" if ( $bluetoothsettings{'RFCOMM0_BIND'} eq 'on' ); +$checked_rfcomm1_bind = "checked='checked'" if ( $bluetoothsettings{'RFCOMM1_BIND'} eq 'on' ); + +# +# Devices box +# +&Header::openbox('100%', 'left', "Bluetooth devices in range"); +print < +END +; +my $bluetooth_scan = `hcitool scan | grep -v "Scanning ..." | sed 's|:|-|g'`; + +print "
$bluetooth_scan
"; + +&Header::closebox(); + +# +# Bluetooth settings +# +&Header::openbox('100%', 'left', "Bluetooth Settings"); +print < +Passkey-Agent:  + Password:  +Bind rfcomm0:  + Device:  + Channel:  +Bind rfcomm1:  + Device:  + Channel:  + + +
+ + + + +
 
+END +; +&Header::closebox(); + +print ""; +&Header::closebigbox(); +&Header::closepage(); + + +sub WriteConfig{ + &General::writehash("/var/ipfire/bluetooth/settings", \%bluetoothsettings); +} + diff --git a/html/cgi-bin/wlanap.cgi b/html/cgi-bin/wlanap.cgi old mode 100755 new mode 100644 diff --git a/src/initscripts/init.d/bluetooth b/src/initscripts/init.d/bluetooth index 6ccd659add..e3ee1b130e 100644 --- a/src/initscripts/init.d/bluetooth +++ b/src/initscripts/init.d/bluetooth @@ -7,29 +7,45 @@ . /etc/sysconfig/rc . $rc_functions +eval $(/usr/local/bin/readhash /var/ipfire/bluetooth/settings) + case "$1" in start) boot_mesg "Starting Bluetooth daemon..." loadproc /usr/sbin/hcid sleep 1 + + if [ "$PASSKEY_AGENT" == "on" ]; then + boot_mesg "Starting Bluetooth passkey-agent..." + loadproc /usr/bin/passkey-agent --default $PWD & + fi + + if [ "$RFCOMM0_BIND" == "on" ]; then + boot_mesg "Bind rfcomm0 to cellphone/modem ${RFCOMM0_DEVICE//-/:}/$RFCOMM0_CHANNEL ..." + rfcomm bind /dev/rfcomm0 ${RFCOMM0_DEVICE//-/:} $RFCOMM0_CHANNEL + evaluate_retval + fi + if [ "$RFCOMM1_BIND" == "on" ]; then + boot_mesg "Bind rfcomm1 to cellphone/modem ${RFCOMM1_DEVICE//-/:}/${RFCOMM1_CHANNEL} ..." + rfcomm bind /dev/rfcomm1 ${RFCOMM1_DEVICE//-/:} $RFCOMM1_CHANNEL + evaluate_retval + fi + exit 0; - # The passkey-agent is only needed for pairing - #boot_mesg "Starting Bluetooth passkey-agent..." - #loadproc /usr/bin/passkey-agent --default 12345 & - - # Bind rfcomm to a blootooth cellphone/modem - #boot_mesg "Bind rfcomm0 to cellphone/modem..." - #rfcomm bind /dev/rfcomm0 00:11:22:33:44:55 1 - #evaluate_retval ;; stop) - #boot_mesg "Release rfcomm0..." - #rfcomm release rfcomm0 - #boot_mesg "Stopping Bluetooth passkey-agent..." - #killproc /usr/bin/passkey-agent + if [ -e /dev/rfcomm0 ]; then + boot_mesg "Release rfcomm0..." + rfcomm release rfcomm0 + fi + if [ -e /dev/rfcomm1 ]; then + boot_mesg "Release rfcomm1..." + rfcomm release rfcomm1 + fi boot_mesg "Stopping Bluetooth daemon..." killproc /usr/sbin/hcid + exit 0; ;; restart) @@ -41,8 +57,7 @@ case "$1" in status) statusproc /usr/sbin/hcid statusproc /usr/bin/passkey-agent - - ;; + ;; *) echo "Usage: $0 {start|stop|restart|status}" -- 2.39.5