]>
Commit | Line | Data |
---|---|---|
a312b3ad AF |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | # | |
22 | ||
23 | use strict; | |
24 | ||
25 | # enable only the following on debugging purpose | |
26 | use warnings; | |
27 | use CGI::Carp 'fatalsToBrowser'; | |
28 | ||
29 | require '/var/ipfire/general-functions.pl'; | |
30 | require '/var/ipfire/lang.pl'; | |
31 | require '/var/ipfire/header.pl'; | |
32 | ||
33 | my $debug = 0; | |
34 | my $i = 0; | |
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>"; | |
38 | ||
39 | # get rid of used only once warnings | |
40 | my @onlyonce = ( $Header::colourgreen, $Header::colourred ); | |
41 | undef @onlyonce; | |
42 | ||
43 | my %selected=(); | |
44 | my %checked=(); | |
45 | my %color = (); | |
46 | my %mainsettings = (); | |
47 | ||
48 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
49 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
50 | ||
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'; | |
60 | ||
61 | &General::readhash("/var/ipfire/bluetooth/settings", \%bluetoothsettings); | |
62 | ||
63 | my %cgiparams=(); | |
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'} = ''; | |
74 | ||
75 | ||
76 | &Header::getcgihash(\%cgiparams); | |
77 | ||
78 | &Header::showhttpheaders(); | |
79 | ||
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 />"; | |
85 | } | |
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'}; | |
92 | ||
93 | # TODO: CHECK RFCOMM DEVICES | |
94 | ||
95 | if ( $errormessage eq '' ){ | |
96 | &WriteConfig(); | |
97 | system("/usr/local/bin/addonctrl bluetooth restart >/dev/null 2>&1") | |
98 | } | |
99 | } | |
100 | ||
101 | &Header::openpage('Bluetooth', 1, '', ''); | |
102 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
103 | print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>"; | |
104 | ||
105 | if ( $errormessage ){ | |
106 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
107 | print "<class name='base'>$errormessage\n"; | |
108 | print " </class>\n"; | |
109 | &Header::closebox(); | |
110 | } | |
111 | ||
112 | ||
113 | # Found this usefull piece of code in BlockOutTraffic AddOn 8-) | |
114 | # fwrules.cgi | |
115 | ############### | |
116 | # DEBUG DEBUG | |
117 | if ( $debug ){ | |
118 | &Header::openbox('100%', 'left', 'DEBUG'); | |
119 | my $debugCount = 0; | |
120 | foreach my $line (sort keys %cgiparams) { | |
121 | print "$line = '$cgiparams{$line}'<br />\n"; | |
122 | $debugCount++; | |
123 | } | |
124 | print " Count: $debugCount\n"; | |
125 | &Header::closebox(); | |
126 | } | |
127 | # DEBUG DEBUG | |
128 | ############### | |
129 | ||
130 | ||
131 | my $checked_passkey_agent = ''; | |
132 | my $checked_rfcomm0_bind = ''; | |
133 | my $checked_rfcomm1_bind = ''; | |
134 | ||
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' ); | |
138 | ||
139 | # | |
140 | # Devices box | |
141 | # | |
142 | &Header::openbox('100%', 'left', "Bluetooth devices in range"); | |
143 | print <<END | |
144 | <table width='100%'> | |
145 | END | |
146 | ; | |
147 | my $bluetooth_scan = `hcitool scan | grep -v "Scanning ..." | sed 's|:|-|g'`; | |
148 | ||
149 | print "<table width='80%'><td bgcolor='${Header::colourblue}'><font color='white'><pre>$bluetooth_scan</pre></font></td></table>"; | |
150 | ||
151 | &Header::closebox(); | |
152 | ||
153 | # | |
154 | # Bluetooth settings | |
155 | # | |
156 | &Header::openbox('100%', 'left', "Bluetooth Settings"); | |
157 | print <<END | |
158 | <table width='100%'> | |
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> | |
167 | ||
168 | </table> | |
169 | <hr /><table width='100%'> | |
170 | <tr> | |
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> | |
173 | </tr> | |
174 | </table> | |
175 | END | |
176 | ; | |
177 | &Header::closebox(); | |
178 | ||
179 | print "</form>"; | |
180 | &Header::closebigbox(); | |
181 | &Header::closepage(); | |
182 | ||
183 | ||
184 | sub WriteConfig{ | |
185 | &General::writehash("/var/ipfire/bluetooth/settings", \%bluetoothsettings); | |
186 | } | |
187 |