]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
Add bluetooth.cgi only rfcomm/modem support yet
authorArne Fitzenreiter <arne_f@ipfire.org>
Sat, 16 Aug 2008 15:44:44 +0000 (17:44 +0200)
committerArne Fitzenreiter <arne_f@ipfire.org>
Sat, 16 Aug 2008 15:44:44 +0000 (17:44 +0200)
config/menu/EX-bluetooth.menu [new file with mode: 0644]
config/rootfiles/packages/bluez
html/cgi-bin/bluetooth.cgi [new file with mode: 0644]
html/cgi-bin/wlanap.cgi [changed mode: 0755->0644]
src/initscripts/init.d/bluetooth

diff --git a/config/menu/EX-bluetooth.menu b/config/menu/EX-bluetooth.menu
new file mode 100644 (file)
index 0000000..b7f1728
--- /dev/null
@@ -0,0 +1,5 @@
+    $subipfire->{'55.bluetooth'} = {'caption' => bluetooth,
+                                 'uri' => '/cgi-bin/bluetooth.cgi',
+                                 'title' => bluetooth,
+                                 'enabled' => 1,
+                                 };
index 188292b4baf05cac6ea7a57ba3077004038c1545..470c1ccb6237502bf51c675b71cb8b8b5e7b76e4 100644 (file)
@@ -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 (file)
index 0000000..32bd8e8
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+#
+
+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 = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
+my $status_stopped = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
+
+# 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.<br />";
+       }
+       $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 "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
+
+if ( $errormessage ){
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<class name='base'>$errormessage\n";
+       print "&nbsp;</class>\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}'<br />\n";
+               $debugCount++;
+       }
+       print "&nbsp;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
+<table width='100%'>
+END
+;
+my $bluetooth_scan = `hcitool scan | grep -v "Scanning ..." | sed 's|:|-|g'`;
+
+print "<table width='80%'><td bgcolor='${Header::colourblue}'><font color='white'><pre>$bluetooth_scan</pre></font></td></table>";
+
+&Header::closebox();
+
+#
+# Bluetooth settings
+#
+&Header::openbox('100%', 'left', "Bluetooth Settings");
+print <<END
+<table width='100%'>
+<tr><td width='25%' class='base'>Passkey-Agent:&nbsp;</td><td class='base'><input type='checkbox' name='PASSKEY_AGENT' $checked_passkey_agent /></td>
+    <td width='25%' class='base'>Password:&nbsp;</td><td class='base'><input type='text' name='PWD' size='8' value='$bluetoothsettings{'PWD'}' /></td></tr>
+<tr><td width='25%' class='base'>Bind rfcomm0:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='RFCOMM0_BIND' $checked_rfcomm0_bind />
+    Device:&nbsp; <input type='text' name='RFCOMM0_DEVICE' size='17' value='$bluetoothsettings{'RFCOMM0_DEVICE'}' />
+    Channel:&nbsp; <input type='text' name='RFCOMM0_CHANNEL' size='1' value='$bluetoothsettings{'RFCOMM0_CHANNEL'}' /></td></tr>
+<tr><td width='25%' class='base'>Bind rfcomm1:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='RFCOMM1_BIND' $checked_rfcomm1_bind />
+    Device:&nbsp; <input type='text' name='RFCOMM1_DEVICE' size='17' value='$bluetoothsettings{'RFCOMM1_DEVICE'}' />
+    Channel:&nbsp; <input type='text' name='RFCOMM1_CHANNEL' size='1' value='$bluetoothsettings{'RFCOMM1_CHANNEL'}' /></td></tr>
+
+</table>
+<hr /><table width='100%'>
+<tr>
+<td width='55%' class='base' valign='top'>&nbsp;</td>
+<td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
+</tr>
+</table>
+END
+;
+&Header::closebox();
+
+print "</form>";
+&Header::closebigbox();
+&Header::closepage();
+
+
+sub WriteConfig{
+       &General::writehash("/var/ipfire/bluetooth/settings", \%bluetoothsettings);
+}
+
old mode 100755 (executable)
new mode 100644 (file)
index 6ccd659addb790dfe91ff0b34710fb2def0673b5..e3ee1b130e27af11576db5994bf3bcbb02ac2228 100644 (file)
@@ -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}"