This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·764 lines (679 loc) · 28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
#! /usr/bin/python2
# Importing Standard Libraries #
import fcntl
import getpass
import os
import re
import signal
import subprocess
import sys
import thread
import time
# Importing wxpython Libraries #
from wx import *
from wx import wizard as wiz
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
import wx.lib.mixins.listctrl as listmix
# Import personal files
from nonrootwebbrowser import OpenReportWindow
# Setting some base app information #
progVer = '0.9.2.5'
conf_dir = '/etc/netctl/'
status_dir = '/usr/lib/wifiz/'
license_dir = '/usr/share/licenses/wifiz/'
int_file = status_dir + 'interface.cfg'
iwconfig_file = status_dir + 'iwconfig.log'
iwlist_file = status_dir + 'iwlist.log'
pid_file = status_dir + 'program.pid'
img_loc = '/usr/share/wifiz/imgs/'
pid_number = os.getpid()
#print sys.argv
# do as we're told #
for arg in sys.argv:
if arg == '--help' or arg == '-h':
print "WiFiz; The netctl gui! \nNeeds to be root."
sys.exit(0)
if arg == '--version' or arg == '-v':
print "Your WiFiz version is " + progVer + "."
sys.exit(0)
if os.path.exists(status_dir):
pass
else:
subprocess.call("mkdir " + status_dir, shell=True)
# Lets make sure we're root as well #
euid = os.geteuid()
if euid != 0:
print ("WiFiz needs to be run as root, please sudo and try again. \n")
sys.exit(2)
if os.path.exists(pid_file):
# Allow only one instance #
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
print "We only allow one instance of WiFiz at a time for now."
sys.exit(1)
fp.write(str(pid_number) + "\n")
fp.flush()
else:
subprocess.call("touch " + pid_file, shell=True)
# Allow only one instance #
fp = open(pid_file, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
print "We only allow one instance of WiFiz at a time for now."
sys.exit(1)
fp.write(str(pid_number) + "\n")
fp.flush()
class Netctl(object):
"""Functions to control netctl"""
def __init__(self):
super(Netctl, self).__init__()
def start(self, network):
print "netctl:: start " + network
subprocess.call(["netctl", "start", network])
def stop(self, network):
print "netctl:: stop " + network
subprocess.call(["netctl", "stop", network])
def stopall(self):
print "netctl:: stop-all"
subprocess.call(["netctl", "stop-all"])
def restart(self, network):
print "netctl:: restart " + network
subprocess.call(["netctl", "restart", profile])
class InterfaceCtl(object):
"""Control the network interface"""
def __init__(self):
pass
def down(self, interface=""):
print "interface:: down: " + interface
subprocess.call(["ip", "link", "set", "down", "dev", interface])
def up(self, interface=""):
print "interface:: up: " + interface
subprocess.call(["ip", "link", "set", "up", "dev", interface])
# __main__ Class #
class WiFiz(wx.Frame):
def __init__(self, parent, title):
super(WiFiz, self).__init__(None, title="WiFiz",
style = wx.DEFAULT_FRAME_STYLE)
# init objs
self.InitUI()
self.TrayIcon = Icon(self, wx.Icon(img_loc + "APScan.png",
wx.BITMAP_TYPE_PNG), "WiFiz")
# init vars
self.scanning = False
self.netctl = Netctl()
self.APindex = 0
self.APList = AutoWidthListCtrl(self)
self.APList.setResizeColumn(0)
self.APList.InsertColumn(0, "SSID", width=150)
self.APList.InsertColumn(1, "Connection Strength", width=200)
self.APList.InsertColumn(2, "Security Type", width=150)
self.APList.InsertColumn(3, "Connected?", width=150)
# Get interface name: From file or from user.
self.UIDValue = GetInterface(self)
print self.UIDValue
self.SetSize((700,390))
self.Center()
# init processies
# Pre scan in BG
thread.start_new_thread(self.ScanWifi, (1,))
# set up InterfaceCtl class
self.interface = InterfaceCtl()
def InitUI(self):
# Set Icon
iconFile = img_loc + "logo.png"
mainIcon = wx.Icon(iconFile, wx.BITMAP_TYPE_PNG)
self.SetIcon(mainIcon)
# Menu Bar #
self.mainMenu = wx.MenuBar()
fileMenu = wx.Menu()
ScanAPs = fileMenu.Append(wx.ID_ANY, "Scan for New Networks",
"Scan for New Wireless Networks.")
fileMenu.AppendSeparator()
fileQuit = fileMenu.Append(wx.ID_ANY, "Close", "Minimize the program to the task area.")
fileExit = fileMenu.Append(wx.ID_EXIT, "Exit", "Exit the program completely.")
self.mainMenu.Append(fileMenu, "&File")
profilesMenu = wx.Menu()
profiles = os.listdir("/etc/netctl/")
# Iterate through profiles directory, and add to "Profiles" Menu #
for i in profiles:
if os.path.isfile("/etc/netctl/" + i):
profile = profilesMenu.Append(wx.ID_ANY, i)
self.Bind(wx.EVT_MENU, self.OnMConnect, profile)
self.mainMenu.Append(profilesMenu, "Profiles")
toolsMenu = wx.Menu()
cantCItem = toolsMenu.Append(wx.ID_ANY, "Can't Connect to Networks",
"If you can't connect to any networks, run this.")
editProfile = toolsMenu.Append(wx.ID_ANY, "Edit profiles",
"Manually edit profiles.")
self.mainMenu.Append(toolsMenu, "Tools")
helpMenu = wx.Menu()
helpItem = helpMenu.Append(wx.ID_HELP, "Help with WiFiz",
"Get help with WiFiz")
helpItem.Enable(False)
helpMenu.AppendSeparator()
reportIssue = helpMenu.Append(wx.ID_ANY, "Report an Issue...",
"Report a bug, or give a suggestion.")
helpMenu.AppendSeparator()
aboutItem = helpMenu.Append(wx.ID_ABOUT, "About WiFiz",
"About this program...")
self.mainMenu.Append(helpMenu, "&Help")
self.SetMenuBar(self.mainMenu)
# End Menu Bar #
# Create Popup Menu #
self.PopupMenu = wx.Menu()
popCon = self.PopupMenu.Append(wx.ID_ANY, "Connect to Network",
"Connect to selected network.")
popDCon = self.PopupMenu.Append(wx.ID_ANY, "Disconnect from Network",
"Disconnect from selected network.")
# Create Toolbar Buttons #
toolbar = self.CreateToolBar()
# newTool = toolbar.AddLabelTool(wx.ID_NEW, 'New',
# wx.ArtProvider.GetBitmap(wx.ART_NEW), wx.NullBitmap,
# wx.ITEM_NORMAL, 'New Connection')
ReScanAPs = toolbar.AddLabelTool(wx.ID_ANY, 'Scan',
wx.Bitmap(img_loc + 'APScan.png'), wx.NullBitmap,
wx.ITEM_NORMAL, 'Scan')
connectSe = toolbar.AddLabelTool(wx.ID_ANY, 'Connect',
wx.Bitmap(img_loc + 'connect.png'), wx.NullBitmap,
wx.ITEM_NORMAL, 'Connect')
dConnectSe = toolbar.AddLabelTool(wx.ID_ANY, 'Disconnect',
wx.Bitmap(img_loc + 'disconnect.png'), wx.NullBitmap,
wx.ITEM_NORMAL, 'Disconnect')
toolbar.AddSeparator()
quitTool = toolbar.AddLabelTool(wx.ID_EXIT, 'Quit',
wx.ArtProvider.GetBitmap(wx.ART_QUIT), wx.NullBitmap,
wx.ITEM_NORMAL, 'Quit')
toolbar.Realize()
# End Toolbar #
# Create Status Bar #
self.CreateStatusBar()
# End Status Bar #
# Binding Events #
self.Bind(wx.EVT_MENU, self.OnClose, fileQuit)
self.Bind(wx.EVT_TOOL, self.OnConnect, connectSe)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
self.Bind(wx.EVT_MENU, self.OnScan, ScanAPs)
self.Bind(wx.EVT_TOOL, self.OnScan, ReScanAPs)
# self.Bind(wx.EVT_TOOL, self.OnNew, newTool)
self.Bind(wx.EVT_TOOL, self.OnDConnect, dConnectSe)
self.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
self.Bind(wx.EVT_CONTEXT_MENU, self.OnConnect, popCon)
self.Bind(wx.EVT_CONTEXT_MENU, self.OnDConnect, popDCon)
self.Bind(wx.EVT_MENU, self.OnReport, reportIssue)
self.Bind(wx.EVT_MENU, self.OnCantConnect, cantCItem)
self.Bind(wx.EVT_MENU, self.onEditProf, editProfile)
self.Bind(wx.EVT_MENU, self.OnFullClose, fileExit)
# End Bindings #
def onEditProf(self, e):
if os.path.exists("/usr/bin/gedit"):
if self.APList.GetFirstSelected() == -1:
wx.MessageBox("You have to select a profile first!", "Please select profile.")
else:
index = str(self.getSelectedIndices()).strip('[]')
index = int(index)
item = self.APList.GetItem(index, 0)
nameofProfile = item.GetText()
subprocess.call("gedit " + (conf_dir + nameofProfile + "_wifiz"), shell="True")
else:
wx.MessageBox("To edit profiles, you need to have gedit installed. Please install gedit, and then retry.",
"Install gedit first.")
def OnCantConnect(self, e):
# This fixes an error where the interface stays up, but it disconnects
# from the network. Usually seems to happen after letting a computer
# (at least mine) go to sleep for a while.
netinterface = GetInterface(self)
self.netctl.stopall()
self.interface.down(netinterface)
# TODO rename this funct
def OnMConnect(self, profile):
# This figures out the profile we are trying to connect to by reading
# the just-recently-clicked profile
#item = self.mainMenu.FindItemById(e.GetId())
#profile = item.GetText()
netinterface = GetInterface(self)
self.interface.down(netinterface)
self.netctl.stopall()
self.netctl.start(profile)
def OnPref(self, e):
# Opens the preferences dialog... which is currently not functional
prefWindow = Preferences(self, wx.ID_ANY, title="Preferences")
prefWindow.CenterOnParent()
prefWindow.Show()
def OnEdit(self, e):
# Opens the edit window... which is currently not functional...
editWindow = EditProfile(None)
# TODO rename this section.
def OnConnect(self, e):
# TODO rewrite this section, we sould be grabbing this
# info from eleswhere.
# Here we start by getting the index of the row, then selected the name
# of the network, and getting the security
index = str(self.getSelectedIndices()).strip('[]')
index = int(index)
nmp = self.APList.GetItem(index, 0)
nameofProfile = nmp.GetText()
tos = self.APList.GetItem(index, 2)
typeofSecurity = tos.GetText()
typeofSecurity = str(typeofSecurity).strip()
typeofSecurity = typeofSecurity.lower()
# HACK TODO REMOVE
if typeofSecurity == open:
typeofSecurity = 'none'
# Here we get the filename of a current profile
filename = str(nameofProfile + u'_' + "wifiz").strip()
filename = filename.strip()
# We need to make this section optional
# TODO and move it out of here
print filename
if os.path.isfile(conf_dir + filename):
self.interface.down(self.UIDValue)
self.netctl.start(filename)
# Missing function TODO
if IsConnected():
wx.MessageBox("You are now connected to " +
str(nameofProfile) + ".", "Connected.")
else:
wx.MessageBox("There has been an error, please try again. "
"If it persists, please contact Cody Dostal at "
"[email protected].", "Error!")
else:
if str(typeofSecurity).strip() is not "none":
passw = wx.TextEntryDialog(self, "What is the password?",
"Password", "")
if passw.ShowModal() == wx.ID_OK:
network_key = passw.GetValue()
else:
print "Something went wrong getting the network password.\n"
network_key = None
else:
network_key = None
CreateConfig(nameofProfile, self.UIDValue, typeofSecurity, network_key)
try:
netinterface = GetInterface(self)
self.interface.down(netinterface)
self.netctl.start(filename)
wx.MessageBox("You are now connected to " +
str(nameofProfile).strip() + ".", "Connected.")
except:
wx.MessageBox("There has been an error, please try again. If"
" it persists, please contact Cody Dostal at "
"[email protected].", "Error!")
self.OnScan()
def getSelectedIndices(self, state = wx.LIST_STATE_SELECTED):
indices = []
lastFound = -1
while True:
index = self.APList.GetNextItem(
lastFound,
wx.LIST_NEXT_ALL,
state,
)
if index == -1:
break
else:
lastFound = index
indices.append( index )
return indices
def OnReport(self, e):
OpenReportWindow()
def OnShowPopup(self, e):
# Here we get the position of the mouse, and show the popup where we
# clicked... although I am not entirely sure if the popup
# connect/disconnect works, and I may be removing the popup.
x, y = e.GetPosition()
pos = self.APList.ScreenToClientXY(x, y)
self.APList.PopupMenu(self.PopupMenu, pos)
def OnDConnect(self, e):
# Here we start by getting the selected row, and then finding the name
# of the profile shutting down that relevant profile, and turning of
# the interface
index = str(self.getSelectedIndices()).strip('[]')
index = int(index)
item = self.APList.GetItem(index, 0)
nameofProfile = item.GetText()
self.netctl.stop(filename)
self.interface.down(self.UIDValue)
self.OnScan()
wx.MessageBox("You are now disconnected from " +
nameofProfile + ".", "Disconnected.")
def OnNew(self, e):
# Here we run the NewProfile wizard
newProf = NewProfile(parent=None)
def ScanWifi(self, e=None):
# Scan for access points
while self.scanning:
print "Scanning in progress, please hold!"
time.sleep(1)
self.interface.up(self.UIDValue)
print "Scanning:: " + self.UIDValue
self.scanning = True
output = str(subprocess.check_output("iwlist " + self.UIDValue +
" scan", shell=True))
f = open(iwlist_file, 'w')
f.write(output)
f.close()
print "Scanning:: Done"
self.scanning = False
self.OnScan(1)
def OnScan(self, e=None):
'''Process scan results.'''
# Clear APList
self.APList.DeleteAllItems()
self.APindex = 0
while self.scanning:
print "Scanning in progress, please hold!"
time.sleep(1)
# Open iwfile, if it's missing rescan now
try:
iwlist = open(iwlist_file, 'r').read()
except:
self.ScanWifi()
iwlist = open(iwlist_file, 'r').read()
# I'd rather use regex and get an array
ap_list = re.split(r'Cell \d\d -', iwlist)
# Split by access point
for ap in reversed(ap_list):
# Split by line
ap_data = re.split("\n+",ap)
for line in ap_data:
kv = re.split(":", line.strip())
if kv[0] == "ESSID":
self.APList.SetStringItem(self.APindex, 0,
kv[1].strip().replace('"', ""))
check = subprocess.check_output("netctl list | sed -n 's/^\* //p'", shell=True)
if kv[1].strip().replace('"', "") in check:
self.APList.SetStringItem(self.APindex, 3, "True")
else:
self.APList.SetStringItem(self.APindex, 3, "False")
if kv[0] == "Encryption key":
if kv[1] == "off":
encrypt = "Open"
file_encrypt = "none"
elif kv[1] == "on":
encrypt = "Probably WEP"
self.APList.SetStringItem(self.APindex, 2, encrypt)
elif "WPA" in line:
encrypt = "WPA"
self.APList.SetStringItem(self.APindex, 2, encrypt)
# TODO conver this line!
if "Quality" in line:
lines = "Line %s" % self.APindex
self.APList.InsertStringItem(self.APindex, lines)
self.APindex + 1
s = str(line)[28:33]
# Courtesy of gohu's iwlistparse.py, slightly modified.
# https://bbs.archlinux.org/viewtopic.php?id=88967
s3 = str(int(round(float(s[0])/float(s[3])*100))).rjust(3)+" %"
self.APList.SetStringItem(self.APindex, 1, s3)
# profiles = os.listdir("/etc/netctl/")
# if any(essid.strip() in s for s in profiles):
# profile = "wifiz-" + essid.strip()
# if os.path.isfile(conf_dir + profile):
# for line in open(conf_dir + profile):
# if "#preferred" in line:
# if "yes" in line:
# profile = profile
# else:
# pass
if e is None:
thread.start_new_thread(self.ScanWifi, (1,))
# TODO if atocnnt enabled DO
# try:
# self.AutoConnect()
# except:
# print "Auto connect failed!"
# else:
# pass
# TODO unworking
def AutoConnect(self, e):
try:
self.interface.down(self.UIDValue)
self.netctl.start(self.profile)
wx.MessageBox("You are now connected to "+str(self.profile).strip()
+ ".", "Connected.")
except:
wx.MessageBox("There has been an error, please try again. "
"If it persists, please contact Cody Dostal "
"at [email protected].", "Error!")
def OnClose(self, e):
self.Hide()
def OnFullClose(self, e):
open(iwlist_file, 'w').close()
sys.exit()
def OnAbout(self, e):
description = """WiFiz is a simple to use, frontend for NetCTL."""
license = open(license_dir + 'WiFiz.license', 'r').read()
info = wx.AboutDialogInfo()
info.SetIcon(wx.Icon(img_loc + 'aboutLogo.png', wx.BITMAP_TYPE_PNG))
info.SetName('WiFiz')
info.SetVersion(str(progVer))
info.SetDescription(description)
info.SetCopyright("(C) 2012 Cody Dostal (a.k.a. Pivotraze)")
info.SetWebSite("https://www.github.com/codywd")
info.SetLicense(license)
info.AddDeveloper('Cody Dostal')
info.AddDocWriter('Cody Dostal')
info.AddArtist('Sam Stuewe')
info.AddTranslator('Cody Dostal (English)')
wx.AboutBox(info)
# Taskbar Icon Class #
class Icon(wx.TaskBarIcon):
def __init__(self, parent, icon, tooltip):
wx.TaskBarIcon.__init__(self)
self.SetIcon(icon, tooltip)
self.parent = parent
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnLeftDClick)
self.CreateMenu()
print "Starting Tray"
def CreateMenu(self):
self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnPopup)
self.menu = wx.Menu()
topen = self.menu.Append(wx.ID_ANY, '&Open')
self.menu.Bind(wx.EVT_MENU, self.OnOpen, topen)
self.menu.AppendSeparator()
profiles = os.listdir("/etc/netctl/")
for i in profiles:
if os.path.isfile("/etc/netctl/" + i):
profile = self.menu.Append(wx.ID_ANY, i)
self.menu.Bind(wx.EVT_MENU, self.CallConnect, profile)
else:
pass
self.menu.AppendSeparator()
texit = self.menu.Append(wx.ID_EXIT, 'E&xit')
self.menu.Bind(wx.EVT_MENU, self.OnExit, texit)
def CallConnect(self, e):
item = self.menu.FindItemById(e.GetId())
profile = item.GetText()
self.parent.OnMConnect(profile)
def OnExit(self, e):
wx.CallAfter(self.Destroy)
self.parent.Destroy()
def OnOpen(self, e):
self.parent.Show()
def OnPopup(self, event):
self.PopupMenu(self.menu)
def OnLeftDClick(self, event):
if self.parent.IsIconized():
self.parent.Iconize(False)
if not self.parent.IsShown():
self.parent.Show(True)
self.parent.Raise()
else:
self.parent.Show(False)
# Class to manually create new network profile
class NewProfile(wx.Dialog):
def __init__(self, parent):
super(NewProfile, self).__init__(None)
self.InitUI()
def InitUI(self):
wizard = wx.wizard.Wizard(None, -1, "New Profile Wizard")
page1 = TitledPage(wizard, "Interface")
page1.Sizer.Add(wx.StaticText(page1, -1, "Please type the name of the"
" interface you will be \nusing to connect to the network. "
"Examples are \nwlan0, eth0, etc..."))
page1.Sizer.Add(wx.StaticText(page1, -1, ""))
intFaces = os.listdir("/sys/class/net")
for i in intFaces:
page1.Sizer.Add(wx.RadioButton(page1, -1, i))
page2 = TitledPage(wizard, "Connection Type")
page2.Sizer.Add(wx.StaticText(page2, -1,
"Please type the type of connection you will be using."))
page2.Sizer.Add(wx.StaticText(page2, -1, ""))
choiceWiFi = wx.RadioButton(page2, -1, "Wireless", style=wx.RB_GROUP)
choiceEth = wx.RadioButton(page2, -1, "Ethernet")
page2.Sizer.Add(choiceWiFi)
page2.Sizer.Add(choiceEth)
page3 = TitledPage(wizard, "Security Type")
page3.Sizer.Add(wx.StaticText(page3, -1,
"Please type the security type of the connection."))
page3.Sizer.Add(wx.StaticText(page3, -1, ""))
choiceWEP = wx.RadioButton(page3, -1, "WEP", style=wx.RB_GROUP)
choiceWPA = wx.RadioButton(page3, -1, "WPA/WPA2")
choiceNONE = wx.RadioButton(page3, -1, "None")
page3.Sizer.Add(choiceWEP)
page3.Sizer.Add(choiceWPA)
page3.Sizer.Add(choiceNONE)
page4 = TitledPage(wizard, "SSID")
page4.Sizer.Add(wx.StaticText(page4, -1,
"Please type the name of the network you wish to connect to."))
page4.Sizer.Add(wx.StaticText(page4, -1, ""))
SSIDV = wx.TextCtrl(page4)
page4.Sizer.Add(SSIDV, flag=wx.EXPAND)
SSID = SSIDV.GetValue()
page5 = TitledPage(wizard, "Security Key")
page5.Sizer.Add(wx.StaticText(page5, -1,
"Please type the password of the network you wish to connect to."))
page5.Sizer.Add(wx.StaticText(page5, -1, ""))
self.securePass = wx.TextCtrl(page5, style=wx.TE_PASSWORD)
page5.Sizer.Add(self.securePass, flag=wx.EXPAND)
self.password = self.securePass.GetValue()
page6 = TitledPage(wizard, "Hidden Network")
page6.Sizer.Add(wx.StaticText(page6, -1,
"Is the network hidden? If so, check the checkbox."))
page6.Sizer.Add(wx.StaticText(page6, -1, ""))
page6.Sizer.Add(wx.CheckBox(page6, -1, "Network is Hidden"))
wx.wizard.WizardPageSimple.Chain(page1, page2)
wx.wizard.WizardPageSimple.Chain(page2, page3)
wx.wizard.WizardPageSimple.Chain(page3, page4)
wx.wizard.WizardPageSimple.Chain(page4, page5)
wx.wizard.WizardPageSimple.Chain(page5, page6)
wizard.FitToPage(page1)
wizard.RunWizard(page1)
wizard.Destroy()
self.Bind(wiz.EVT_WIZARD_CANCEL, self.closeDialog)
self.Bind(wiz.EVT_WIZARD_FINISHED, self.saveProfile)
def saveProfile(self, e):
wx.MessageBox(self.interfaceName, self.interfaceName, wx.ID_OK)
wx.MessageBox(self.connectionType, self.connectionType, wx.ID_OK)
def closeDialog(self, e):
dial = wx.MessageDialog(None, "Are you sure you want to cancel?",
"Cancel?", wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
ret = dial.ShowModal()
if ref == wx.ID_YES:
self.Destroy()
else:
e.Veto()
# Class to control network list #
class AutoWidthListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
ListCtrlAutoWidthMixin.__init__(self)
# Class to do something #
class TitledPage(wiz.WizardPageSimple):
def __init__(self, parent, title):
wiz.WizardPageSimple.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
title = wx.StaticText(self, -1, title)
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
sizer.Add(title, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)
sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 5)
# Helper Functions #
# TODO return this to the main class
def GetInterface(wxobj):
if os.path.isfile(int_file):
f = open(int_file)
interface = f.readline()
f.close()
return str(interface).strip()
else:
wxobj.UID = wx.TextEntryDialog(wxobj, "What is your Interface Name? "
"(wlan0, wlp2s0)", "Wireless Interface", "")
if wxobj.UID.ShowModal() == wx.ID_OK:
# rename this var!! TODO
wxobj.UIDValue = wxobj.UID.GetValue()
# TODO error checking for null values
f = open(int_file, 'w')
f.write(wxobj.UIDValue)
f.close()
return wxobj.UIDValue
def CreateConfig(name, interface, security, key=None, ip='dhcp'):
print "Creating Config File!\n"
# TODO genertate better filename
filename = name + "_wifiz"
f = open(conf_dir + filename, "w")
f.write("Description='A profile generated by WiFiz for "+str(name)+"'\n" +
"Interface=" + str(interface) + "\n" +
"Connection=wireless\n" +
"Security=" + str(security) + "\n" +
"ESSID='" + str(name) + "'\n")
if key:
f.write(r"Key='" + key + "'\n")
else:
f.write(r'Key=None\n')
f.write("IP=dhcp\n")
f.close()
def IsConnected():
# If we are connected to a network, it lists it. Otherwise, it returns nothing.
check = subprocess.check_output("netctl list | sed -n 's/^\* //p'", shell=True)
print(check)
if check == b'':
print("False")
return False
else:
print("True")
return True
def cleanUp():
# Clean up time
fcntl.lockf(fp, fcntl.LOCK_UN)
fp.close()
os.unlink(pid_file)
# os.unlink(int_file) # I cant decide if we want to keep this file or
# or do something else with it?
try:
os.unlink(iwlist_file)
os.unlink(iwconfig_file)
except:
pass
def sigInt(signal, frame):
print "\nCTRL-C Caught, cleaning up..."
cleanUp()
print "done. BYE!"
sys.exit(0)
# Main Job #
def start():
netctl = Netctl()
interface = InterfaceCtl()
wxAppPid = os.fork()
if wxAppPid:
# We'll handle ctrl-c
signal.signal(signal.SIGINT, sigInt)
os.waitpid(wxAppPid,0)
print "Child died here\n"
cleanUp()
sys.exit(0)
else:
# Child mode
# Prepare app
app = wx.App(False)
print "Starting WiFiz"
WiFiz(None, title="WiFiz")
# Run app
app.MainLoop()
# If called as an app, run start
if __name__ == "__main__":
start()