2 # -*- coding: utf-8 -*-
4 # A utility for managing WiFi profiles on GNU/Linux.
6 # Copyright (C) 2004-2005 Ahmad Baitalmal <ahmad@baitalmal.com>
7 # Copyright (C) 2005 Nicolas Brouard <nicolas.brouard@mandrake.org>
8 # Copyright (C) 2005-2009 Brian Elliott Finley <brian@thefinleys.com>
9 # Copyright (C) 2006 David Decotigny <com.d2@free.fr>
10 # Copyright (C) 2006 Simon Gerber <gesimu@gmail.com>
11 # Copyright (C) 2006-2007 Joey Hurst <jhurst@lucubrate.org>
12 # Copyright (C) 2006, 2009 Ante Karamatic <ivoks@ubuntu.com>
13 # Copyright (C) 2009-2010,2014 Sean Robinson <robinson@tuxfamily.org>
14 # Copyright (C) 2010 Prokhor Shuchalov <p@shuchalov.ru>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; version 2 of the License.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License in LICENSE.GPL for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to:
27 # Free Software Foundation, Inc.
28 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30 # http://wifi-radar.tuxfamily.org/
32 # See CREDITS file for more contributors.
33 # See HISTORY file for, well, changes.
35 # NOTE: Remove the '-OO' from '#!/usr/bin/python -OO' in the first line to
36 # turn on console debugging.
39 from __future__
import print_function
, unicode_literals
41 # Set up a logging framework as early as possible.
43 logger
= logging
.getLogger('wifiradar')
44 generic_formatter
= logging
.Formatter(
45 fmt
='%(asctime)s.%(msecs)d %(levelname)s %(name)s: %(message)s',
46 datefmt
='%Y-%m-%d %H:%M:%S')
47 consoleLogHandler
= logging
.StreamHandler()
48 consoleLogHandler
.setFormatter(generic_formatter
)
49 logger
.addHandler(consoleLogHandler
)
50 # Start permissive and raise the level later.
52 logger
.setLevel(logging
.DEBUG
)
58 import wifiradar
.config
59 from wifiradar
.misc
import _
, WIFI_RADAR_VERSION
60 import wifiradar
.gui
.g2
as ui
61 import wifiradar
.gui
.g2
.transients
as transients
64 # Where the conf file should live could be different for your distro. Please change
65 # at install time with "make install sysconfdir=/etc/wifi-radar" or similar. -BEF-
67 CONF_FILE
= '/etc/wifi-radar/wifi-radar.conf'
69 #os.environ['LC_MESSAGES'] = 'C'
71 # Load our conf file and known profiles
72 # These default values may get overridden by values found in the conf file.
73 config_general
= { # The network interface you use.
74 # Specify 'auto_detect' as the interface to make wifi-radar automatically detect your wireless card.
75 'interface': 'auto_detect',
76 # How long should the scan for access points last?
78 # You may set this to true for cards that require a 'commit' command with iwconfig
79 'commit_required': 'False',
80 # You may set this to true for cards that require the interface to be brought up first
81 'ifup_required': 'False',
82 # set the location and verbosity of the log file
83 'logfile': '/var/log/wifi-radar.log',
85 # Set the location of several important programs
86 'iwlist_command': '/sbin/iwlist',
87 'iwconfig_command': '/sbin/iwconfig',
88 'ifconfig_command': '/sbin/ifconfig',
89 'route_command': '/sbin/route',
90 'auto_profile_order': '[]',
91 'version': WIFI_RADAR_VERSION
}
93 config_dhcp
= { # DHCP client
94 'command': '/sbin/dhcpcd',
95 # How long to wait for an IP addr from DHCP server
97 # Arguments to use with DHCP client on connect
98 'args': '-D -o -i dhcp_client -t %(timeout)s',
99 # Argument to use with DHCP client on disconnect
101 # The file where DHCP client PID is written
102 'pidfile': '/etc/dhcpc/dhcpcd-%(interface)s.pid' }
104 config_wpa
= { # WPA Supplicant
105 'command': '/usr/sbin/wpa_supplicant',
106 # Arguments to use with WPA Supplicant on connect
107 'args': '-B -i %(interface)s -c %(configuration)s -D %(driver)s -P %(pidfile)s',
108 # Arguments to use with WPA Supplicant on disconnect
110 # Where the WPA Supplicant config file can be found
111 'configuration': '/etc/wpa_supplicant.conf',
112 # Driver to use with WPA Supplicant
114 # The file where WPA Supplicant PID is written
115 'pidfile': '/var/run/wpa_supplicant.pid' }
117 # initialize config, with default values
118 config
= wifiradar
.config
.ConfigFileManager(CONF_FILE
)
119 config
.set_section('GENERAL', config_general
)
120 config
.set_section('DHCP', config_dhcp
)
121 config
.set_section('WPA', config_wpa
)
123 if not os
.path
.isfile(CONF_FILE
):
124 config
.set_bool_opt('GENERAL', 'new_file', True)
126 if not os
.access(CONF_FILE
, os
.R_OK
):
127 print("Can't open {FILE}".format(FILE
=CONF_FILE
))
128 print('Are you root?')
132 except (NameError, SyntaxError) as e
:
133 error_message
= _('A configuration file from a pre-2.0 version '
134 'of WiFi Radar was found at {FILE}.\n\nWiFi Radar v2.0.x does '
135 'not read configuration files from previous versions. ')
136 if isinstance(e
, NameError):
137 error_message
+= _('Because {FILE} may contain information '
138 'that you might wish to use when configuring WiFi Radar '
139 '{VERSION}, rename this file and run the program again.')
140 elif isinstance(e
, SyntaxError):
141 error_message
+= _('The old configuration file is probably '
142 'empty and can be removed. Rename {FILE} if you want '
143 'to be very careful. After removing or renaming '
144 '{FILE}, run this program again.')
145 error_message
= error_message
.format(FILE
=CONF_FILE
,
146 VERSION
=WIFI_RADAR_VERSION
)
147 error_dlg
= transients
.ErrorDialog(None, error_message
)
149 logger
.critical(error_message
)
153 logger
.setLevel(self
.config
.get_opt_as_int('GENERAL', 'loglevel'))
156 ####################################################################################################
157 # Make so we can be imported
158 if __name__
== '__main__':
159 if len(sys
.argv
) > 1 and (sys
.argv
[1] == '--version' or sys
.argv
[1] == '-v'):
160 print(_('WiFi Radar version {VERSION}').format(VERSION
=WIFI_RADAR_VERSION
))
161 elif len(sys
.argv
) > 1 and (sys
.argv
[1] == '--help' or sys
.argv
[1] == '-h'):
162 print(_('WiFi Radar version {VERSION}\n'
163 'For help, check man pages for wifi-radar and '
165 'or visit http://wifi-radar.tuxfamily.org/').format(
166 VERSION
=WIFI_RADAR_VERSION
))
168 wifiradar
.Main(config
)