1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 20:38:00 +01:00

Added ICS support, but commented it out so we can release

This commit is contained in:
compwiz18
2007-07-07 20:09:37 +00:00
parent abfc61431f
commit 6bece259a3
4 changed files with 54 additions and 17 deletions

View File

@@ -242,9 +242,9 @@ class ConnectionWizard(dbus.service.Object):
#end function GetNumberOfNetworks
@dbus.service.method('org.wicd.daemon.wireless')
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused):
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics):
print 'attempting to create ad-hoc network...'
self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused)
self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused,ics)
#end function CreateAdHocNetwork
@dbus.service.method('org.wicd.daemon.wireless')
@@ -258,7 +258,7 @@ class ConnectionWizard(dbus.service.Object):
print 'setting automatically reconnect when connection drops'
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","auto_reconnect",value)
config.set("Settings","auto_reconnect",int(value))
config.write(open(self.app_conf,"w"))
self.auto_reconnect = value
#end function SetAutoReconnect
@@ -481,7 +481,7 @@ class ConnectionWizard(dbus.service.Object):
print 'setting always show wired interface'
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","always_show_wired_interface",value)
config.set("Settings","always_show_wired_interface",int(value))
config.write(open(self.app_conf,"w"))
self.always_show_wired_interface = value

27
gui.py
View File

@@ -125,6 +125,7 @@ language['auto_reconnect'] = _('Automatically reconnect on connection loss')
language['create_adhoc_network'] = _('Create an Ad-Hoc Network')
language['essid'] = _('ESSID')
language['use_wep_encryption'] = _('Use Encryption (WEP only)')
language['use_ics'] = _('Activate Internet Connection Sharing')
language['0'] = _('0')
language['1'] = _('1')
@@ -376,16 +377,13 @@ class NetworkEntry(gtk.Expander):
ipAddress = self.txtIP.get_text() #for easy typing :)
netmask = self.txtNetmask
gateway = self.txtGateway
if ipAddress != None: #make sure the is an IP in the box
if ipAddress.count('.') == 3: #make sure the IP can be parsed
ipNumbers = ipAddress.split('.') #split it up
if not '' in ipNumbers: #make sure the IP isn't something like 127..0.1
if stringToNone(gateway.get_text()) == None: #make sure the gateway box is blank
#fill it in with a .1 at the end
gateway.set_text('.'.join(ipNumbers[0:3]) + '.1')
ip_parts = misc.IsValidIP(ipAddress)
if ip_parts:
if stringToNone(gateway.get_text()) == None: #make sure the gateway box is blank
#fill it in with a .1 at the end
gateway.set_text('.'.join(ip_parts[0:3]) + '.1')
if stringToNone(netmask.get_text()) == None: #make sure the netmask is blank
if stringToNone(netmask.get_text()) == None: #make sure the netmask is blank
netmask.set_text('255.255.255.0') #fill in the most common one
@@ -701,6 +699,7 @@ class appGui:
gobject.timeout_add(100,self.pulse_progress_bar)
def create_adhoc_network(self,widget=None):
'''shows a dialog that creates a new adhoc network'''
#create a new adhoc network here.
print 'create adhoc network'
dialog = gtk.Dialog(title=language['create_adhoc_network'], flags = gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2))
@@ -708,13 +707,14 @@ class appGui:
dialog.set_size_request(400,-1)
self.useEncryptionCheckbox = gtk.CheckButton(language['use_wep_encryption'])
self.useEncryptionCheckbox.set_active(False)
self.useEncryptionCheckbox.show()
ipEntry = LabelEntry(language['ip'] + ':')
essidEntry = LabelEntry(language['essid'] + ':')
channelEntry = LabelEntry(language['channel'] + ':')
self.keyEntry = LabelEntry(language['key'] + ':')
self.keyEntry.set_auto_hidden(True)
self.keyEntry.set_sensitive(False)
self.keyEntry.entry.set_visibility(False)
useICSCheckbox = gtk.CheckButton(language['use_ics'])
self.useEncryptionCheckbox.connect("toggled",self.toggleEncryptionCheck)
channelEntry.entry.set_text('3')
@@ -727,11 +727,14 @@ class appGui:
dialog.vbox.pack_start(essidEntry)
dialog.vbox.pack_start(ipEntry)
dialog.vbox.pack_start(channelEntry)
dialog.vbox.pack_start(useICSCheckbox)
dialog.vbox.pack_start(vboxA)
dialog.vbox.set_spacing(5)
dialog.show_all()
useICSCheckbox.hide() #this isn't quite ready yet
response = dialog.run()
if response == 1:
wireless.CreateAdHocNetwork(essidEntry.entry.get_text(),channelEntry.entry.get_text(),ipEntry.entry.get_text(),"WEP",self.keyEntry.entry.get_text(),self.useEncryptionCheckbox.get_active())
wireless.CreateAdHocNetwork(essidEntry.entry.get_text(),channelEntry.entry.get_text(),ipEntry.entry.get_text(),"WEP",self.keyEntry.entry.get_text(),self.useEncryptionCheckbox.get_active(),False) #useICSCheckbox.get_active())
dialog.destroy()
def toggleEncryptionCheck(self,widget=None):

View File

@@ -22,6 +22,14 @@ def Run(cmd,include_std_error=False):
input,out_err = os.popen4( cmd, 'r')
return out_err.read()
def IsValidIP(ip):
if ip != None: #make sure there is an IP
if ip.count('.') == 3: #make sure the IP can be parsed (or at least it has the proper dots)
ipNumbers = ip.split('.') #split it up
if not '' in ipNumbers: #make sure the IP isn't something like 127..0.1
return ipNumbers
return False
def PromptToStartDaemon():
gksudo_args = ['gksudo', '--message', 'Wicd needs to access your computer\'s network cards.','--','./daemon.py']
os.spawnvpe(os.P_NOWAIT, 'gksudo', gksudo_args, os.environ)

View File

@@ -379,7 +379,7 @@ class Wireless:
ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)',re.S)
return misc.RunRegex(ip_pattern,output)
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused):
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics):
misc.Run("killall dhclient dhclient3 wpa_supplicant") #remove wpa_supplicant, as it can cause the connection to revert to
#previous networks...
misc.Run('ifconfig ' + self.wireless_interface + ' down')
@@ -389,8 +389,33 @@ class Wireless:
#Right now it just assumes you're using WEP
if encused == True:
misc.Run('iwconfig ' + self.wireless_interface + ' key ' + key)
misc.Run('ifconfig ' + self.wireless_interface + ' up')
misc.Run('ifconfig ' + self.wireless_interface + ' inet ' + ip)
#also just assume that the netmask is 255.255.255.0, it simplifies ICS
misc.Run('ifconfig ' + self.wireless_interface + ' netmask 255.255.255.0')
ip_parts = misc.IsValidIP(ip)
if ics and ip_parts:
#set up internet connection sharing here
#flush the forward tables
misc.Run('iptables -F FORWARD')
misc.Run('iptables -N fw-interfaces')
misc.Run('iptables -N fw-open')
misc.Run('iptables -F fw-interfaces')
misc.Run('iptables -F fw-open')
misc.Run('iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu')
misc.Run('iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT')
misc.Run('iptables -A FORWARD -j fw-interfaces ')
misc.Run('iptables -A FORWARD -j fw-open ')
misc.Run('iptables -A FORWARD -j REJECT --reject-with icmp-host-unreachable')
misc.Run('iptables -P FORWARD DROP')
misc.Run('iptables -A fw-interfaces -i ' + self.wireless_interface + ' -j ACCEPT')
basic_ip = '.'.join(ip_parts[0:3]) + '.0' #not sure that basic_ip is a good name
misc.Run('iptables -t nat -A POSTROUTING -s ' + basic_ip + '/255.255.255.0 -o ' + self.wired_interface + ' -j MASQUERADE')
misc.Run('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable routing
#end function CreateAdHocNetwork
def DetectWirelessInterface(self):
@@ -546,3 +571,4 @@ class Wired:
self.lock.release()
self.IsConnecting = False
#end function run