]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/bluetooth.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 # enable only the following on debugging purpose
27 use CGI
::Carp
'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require '/var/ipfire/lang.pl';
31 require '/var/ipfire/header.pl';
35 my $errormessage = '';
36 my $status_started = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
37 my $status_stopped = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
39 # get rid of used only once warnings
40 my @onlyonce = ( $Header::colourgreen
, $Header::colourred
);
46 my %mainsettings = ();
48 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
49 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
51 my %bluetoothsettings=();
52 $bluetoothsettings{'PASSKEY_AGENT'} = 'on';
53 $bluetoothsettings{'PWD'} = '12345';
54 $bluetoothsettings{'RFCOMM0_BIND'} = 'off';
55 $bluetoothsettings{'RFCOMM0_DEVICE'} = '';
56 $bluetoothsettings{'RFCOMM0_CHANNEL'} = '1';
57 $bluetoothsettings{'RFCOMM1_BIND'} = 'off';
58 $bluetoothsettings{'RFCOMM1_DEVICE'} = '';
59 $bluetoothsettings{'RFCOMM1_CHANNEL'} = '1';
61 &General
::readhash
("/var/ipfire/bluetooth/settings", \
%bluetoothsettings);
64 $cgiparams{'ACTION'} = '';
65 $cgiparams{'RUNNING'} = 'off';
66 $cgiparams{'PASSKEY_AGENT'} = 'off';
67 $cgiparams{'PWD'} = '';
68 $cgiparams{'RFCOMM0_BIND'} = 'off';
69 $cgiparams{'RFCOMM0_DEVICE'} = '';
70 $cgiparams{'RFCOMM0_CHANNEL'} = '';
71 $cgiparams{'RFCOMM1_BIND'} = 'off';
72 $cgiparams{'RFCOMM1_DEVICE'} = '';
73 $cgiparams{'RFCOMM1_CHANNEL'} = '';
76 &Header
::getcgihash
(\
%cgiparams);
78 &Header
::showhttpheaders
();
80 if ( $cgiparams{'ACTION'} eq "$Lang::tr{'save'}" ){
81 $bluetoothsettings{'PASSKEY_AGENT'} = $cgiparams{'PASSKEY_AGENT'};
82 $bluetoothsettings{'PWD'} = $cgiparams{'PWD'};
83 if ( (length($bluetoothsettings{'PWD'}) < 4) || (length($bluetoothsettings{'PWD'}) > 8) ){
84 $errormessage .= "Invalid length in Passphrase. Must be between 4 and 8 characters.<br />";
86 $bluetoothsettings{'RFCOMM0_BIND'} = $cgiparams{'RFCOMM0_BIND'};
87 $bluetoothsettings{'RFCOMM1_BIND'} = $cgiparams{'RFCOMM1_BIND'};
88 $bluetoothsettings{'RFCOMM0_DEVICE'} = $cgiparams{'RFCOMM0_DEVICE'};
89 $bluetoothsettings{'RFCOMM1_DEVICE'} = $cgiparams{'RFCOMM1_DEVICE'};
90 $bluetoothsettings{'RFCOMM0_CHANNEL'} = $cgiparams{'RFCOMM0_CHANNEL'};
91 $bluetoothsettings{'RFCOMM1_CHANNEL'} = $cgiparams{'RFCOMM1_CHANNEL'};
93 # TODO: CHECK RFCOMM DEVICES
95 if ( $errormessage eq '' ){
97 system("/usr/local/bin/addonctrl bluetooth restart >/dev/null 2>&1")
101 &Header
::openpage
('Bluetooth', 1, '', '');
102 &Header
::openbigbox
('100%', 'left', '', $errormessage);
103 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
105 if ( $errormessage ){
106 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
107 print "<class name='base'>$errormessage\n";
108 print " </class>\n";
113 # Found this usefull piece of code in BlockOutTraffic AddOn 8-)
118 &Header
::openbox
('100%', 'left', 'DEBUG');
120 foreach my $line (sort keys %cgiparams) {
121 print "$line = '$cgiparams{$line}'<br />\n";
124 print " Count: $debugCount\n";
131 my $checked_passkey_agent = '';
132 my $checked_rfcomm0_bind = '';
133 my $checked_rfcomm1_bind = '';
135 $checked_passkey_agent = "checked='checked'" if ( $bluetoothsettings{'PASSKEY_AGENT'} eq 'on' );
136 $checked_rfcomm0_bind = "checked='checked'" if ( $bluetoothsettings{'RFCOMM0_BIND'} eq 'on' );
137 $checked_rfcomm1_bind = "checked='checked'" if ( $bluetoothsettings{'RFCOMM1_BIND'} eq 'on' );
142 &Header
::openbox
('100%', 'left', "Bluetooth devices in range");
147 my $bluetooth_scan = `hcitool scan | grep -v "Scanning ..." | sed 's|:|-|g'`;
149 print "<table width='80%'><td bgcolor='${Header::colourblue}'><font color='white'><pre>$bluetooth_scan</pre></font></td></table>";
156 &Header
::openbox
('100%', 'left', "Bluetooth Settings");
159 <tr><td width='25%' class='base'>Passkey-Agent: </td><td class='base'><input type='checkbox' name='PASSKEY_AGENT' $checked_passkey_agent /></td>
160 <td width='25%' class='base'>Password: </td><td class='base'><input type='text' name='PWD' size='8' value='$bluetoothsettings{'PWD'}' /></td></tr>
161 <tr><td width='25%' class='base'>Bind rfcomm0: </td><td class='base' colspan='3'><input type='checkbox' name='RFCOMM0_BIND' $checked_rfcomm0_bind />
162 Device: <input type='text' name='RFCOMM0_DEVICE' size='17' value='$bluetoothsettings{'RFCOMM0_DEVICE'}' />
163 Channel: <input type='text' name='RFCOMM0_CHANNEL' size='1' value='$bluetoothsettings{'RFCOMM0_CHANNEL'}' /></td></tr>
164 <tr><td width='25%' class='base'>Bind rfcomm1: </td><td class='base' colspan='3'><input type='checkbox' name='RFCOMM1_BIND' $checked_rfcomm1_bind />
165 Device: <input type='text' name='RFCOMM1_DEVICE' size='17' value='$bluetoothsettings{'RFCOMM1_DEVICE'}' />
166 Channel: <input type='text' name='RFCOMM1_CHANNEL' size='1' value='$bluetoothsettings{'RFCOMM1_CHANNEL'}' /></td></tr>
169 <hr /><table width='100%'>
171 <td width='55%' class='base' valign='top'> </td>
172 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
180 &Header
::closebigbox
();
181 &Header
::closepage
();
185 &General
::writehash
("/var/ipfire/bluetooth/settings", \
%bluetoothsettings);