3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
misc.RenameProcess('wicd-cli')
26
if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0):
29
from dbus.mainloop.glib import DBusGMainLoop
30
DBusGMainLoop(set_as_default=True)
32
bus = dbus.SystemBus()
34
daemon = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon'),
36
wireless = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wireless'),
37
'org.wicd.daemon.wireless')
38
wired = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/wired'),
39
'org.wicd.daemon.wired')
40
config = dbus.Interface(bus.get_object('org.wicd.daemon', '/org/wicd/daemon/config'),
41
'org.wicd.daemon.config')
42
except dbus.DBusException:
43
print 'Error: Could not connect to the daemon. Please make sure it is running.'
46
parser = optparse.OptionParser()
48
parser.add_option('--network', '-n', type='int', default=-1)
49
parser.add_option('--network-property', '-p')
50
parser.add_option('--set-to', '-s')
51
parser.add_option('--name', '-m')
53
parser.add_option('--scan', '-S', default=False, action='store_true')
54
parser.add_option('--save', '-w', default=False, action='store_true')
55
parser.add_option('--list-networks', '-l', default=False, action='store_true')
56
parser.add_option('--network-details', '-d', default=False, action='store_true')
57
parser.add_option('--disconnect', '-x', default=False, action='store_true')
58
parser.add_option('--connect', '-c', default=False, action='store_true')
59
parser.add_option('--list-encryption-types', '-e', default=False, action='store_true')
60
# short options for these two aren't great.
61
parser.add_option('--wireless', '-y', default=False, action='store_true')
62
parser.add_option('--wired', '-z', default=False, action='store_true')
63
parser.add_option('--load-profile', '-o', default=False, action='store_true')
65
options, arguments = parser.parse_args()
69
if not (options.wireless or options.wired):
70
print "Please use --wireless or --wired to specify " + \
71
"the type of connection to operate on."
74
def is_valid_wireless_network_id(network_id):
75
if not (network_id >= 0 \
76
and network_id < wireless.GetNumberOfNetworks()):
77
print 'Invalid wireless network identifier.'
80
def is_valid_wired_network_id(network_id):
81
num = len(wired.GetWiredProfileList())
82
if not (network_id < num and \
84
print 'Invalid wired network identifier.'
87
def is_valid_wired_network_profile(profile_name):
88
if not profile_name in wired.GetWiredProfileList():
89
print 'Profile of that name does not exist.'
92
if options.scan and options.wireless:
97
if options.load_profile and options.wired:
98
is_valid_wired_network_profile(options.name)
99
config.ReadWiredNetworkProfile(options.name)
102
if options.list_networks:
104
print '#\tBSSID\t\t\tChannel\tESSID'
105
for network_id in range(0, wireless.GetNumberOfNetworks()):
106
print '%s\t%s\t%s\t%s' % (network_id,
107
wireless.GetWirelessProperty(network_id, 'bssid'),
108
wireless.GetWirelessProperty(network_id, 'channel'),
109
wireless.GetWirelessProperty(network_id, 'essid'))
111
print '#\tProfile name'
113
for profile in wired.GetWiredProfileList():
114
print '%s\t%s' % (id, profile)
118
if options.network_details:
120
if options.network >= 0:
121
is_valid_wireless_network_id(options.network)
122
network_id = options.network
124
network_id = wireless.GetCurrentNetworkID(0)
125
is_valid_wireless_network_id(network_id)
126
# we're connected to a network, print IP
127
print "IP: %s" % wireless.GetWirelessIP(0)
129
print "Essid: %s" % wireless.GetWirelessProperty(network_id, "essid")
130
print "Bssid: %s" % wireless.GetWirelessProperty(network_id, "bssid")
131
if wireless.GetWirelessProperty(network_id, "encryption"):
132
print "Encryption: On"
133
print "Encryption Method: %s" % \
134
wireless.GetWirelessProperty(network_id, "encryption_method")
136
print "Encryption: Off"
137
print "Quality: %s" % wireless.GetWirelessProperty(network_id, "quality")
138
print "Mode: %s" % wireless.GetWirelessProperty(network_id, "mode")
139
print "Channel: %s" % wireless.GetWirelessProperty(network_id, "channel")
140
print "Bit Rates: %s" % wireless.GetWirelessProperty(network_id, "bitrates")
145
if options.network_property:
146
options.network_property = option.network_property.lower()
148
if options.network >= 0:
149
is_valid_wireless_network_id(options.network)
150
network_id = options.network
152
network_id = wireless.GetCurrentNetworkID(0)
153
is_valid_wireless_network_id(network_id)
154
if not options.set_to:
155
print wireless.GetWirelessProperty(network_id, options.network_property)
157
wireless.SetWirelessProperty(network_id, \
158
options.network_property, options.set_to)
160
if not options.set_to:
161
print wired.GetWiredProperty(options.network_property)
163
wired.SetWiredProperty(options.network_property, options.set_to)
166
if options.disconnect:
169
if wireless.GetCurrentNetworkID(0) > -1:
170
print "Disconnecting from %s on %s" % (wireless.GetCurrentNetwork(0),
171
wireless.DetectWirelessInterface())
173
if wired.CheckPluggedIn():
174
print "Disconnecting from wired connection on %s" % wired.DetectWiredInterface()
178
if options.wireless and options.network > -1:
179
is_valid_wireless_network_id(options.network)
180
name = wireless.GetWirelessProperty(options.network, 'essid')
181
encryption = wireless.GetWirelessProperty(options.network, 'enctype')
182
print "Connecting to %s with %s on %s" % (name, encryption,
183
wireless.DetectWirelessInterface())
184
wireless.ConnectWireless(options.network)
186
check = lambda: wireless.CheckIfWirelessConnecting()
187
message = lambda: wireless.CheckWirelessConnectingMessage()
189
print "Connecting to wired connection on %s" % wired.DetectWiredInterface()
192
check = lambda: wired.CheckIfWiredConnecting()
193
message = lambda: wired.CheckWiredConnectingMessage()
195
# update user on what the daemon is doing
200
# avoid a race condition where status is updated to "done" after the
204
print "%s..." % next.replace("_", " ")
209
# pretty print optional and required properties
210
def str_properties(prop):
214
return ', '.join("%s (%s)" % (x[0], x[1].replace("_", " ")) for x in type['required'])
216
if options.wireless and options.list_encryption_types:
217
et = misc.LoadEncryptionMethods()
218
# print 'Installed encryption templates:'
219
print '%s\t%-20s\t%s' % ('#', 'Name', 'Description')
222
print '%s\t%-20s\t%s' % (id, type['type'], type['name'])
223
print ' Req: %s' % str_properties(type['required'])
225
# don't print optionals (yet)
226
#print ' Opt: %s' % str_properties(type['optional'])
230
if options.save and options.network > -1:
232
is_valid_wireless_network_id(options.network)
233
config.SaveWirelessNetworkProfile(options.network)
235
config.SaveWiredNetworkProfile(options.name)
239
print "No operations performed."