Write the fucking config files

parent d540f952
...@@ -16,7 +16,7 @@ except: ...@@ -16,7 +16,7 @@ except:
boot=False boot=False
auto=False auto=False
NETPATH='/etc/fuswin/networks' NETPATH='/etc/fuswim/networks'
class colors: class colors:
ENDC = '\033[m' ENDC = '\033[m'
...@@ -99,6 +99,18 @@ def checkYN(res, default='N'): ...@@ -99,6 +99,18 @@ def checkYN(res, default='N'):
return False return False
def validateIP(ip):
if not ip:
return False
ipparts = ip.split(".")
if len(ipparts) == 4:
for number in ipparts:
if int(number) > 255 or int(number) < 0:
return False
return True
return False
def read_netconf(net): def read_netconf(net):
p="/".join([NETPATH, net]) p="/".join([NETPATH, net])
conf = { conf = {
...@@ -121,6 +133,9 @@ def read_netconf(net): ...@@ -121,6 +133,9 @@ def read_netconf(net):
k, v = line.split(":", 1) k, v = line.split(":", 1)
if k in ['auto', 'dhcp']: if k in ['auto', 'dhcp']:
v=checkYN(v) v=checkYN(v)
if k=='gw':
if not validateIP(v):
v=checkYN(v)
conf[k] = v conf[k] = v
conf['saved'] = True conf['saved'] = True
return conf return conf
...@@ -129,6 +144,29 @@ def read_netconf(net): ...@@ -129,6 +144,29 @@ def read_netconf(net):
return conf return conf
def write_netconf(net, nconf):
p="/".join([NETPATH, net])
with open(p, 'w') as f:
for k in nconf.keys():
if k!='saved':
if k == 'gw':
if not validateIP(nconf[k]):
f.write('gw:n\n')
else:
f.write('gw:'+nconf[k]+"\n")
elif k in ['auto', 'dhcp']:
v='n'
if nconf[k]:
v='y'
f.write(k+':'+v+'\n')
else:
f.write(k+':'+str(nconf[k])+'\n')
f.close()
sys.exit(0)
return True
def kill_proc(name, ops=False): def kill_proc(name, ops=False):
for process in psutil.process_iter(): for process in psutil.process_iter():
...@@ -181,11 +219,60 @@ def fuckquit(fuck): ...@@ -181,11 +219,60 @@ def fuckquit(fuck):
def insertNetwork(net): def insertNetwork(net):
print_msg("Give me the fucking data for the network "+net['Name'])
pwd = input("PASSWORD: ") if net['Name'] == '':
dhcp = checkYN(input("DHCP? <Y|n>: "), default='Y') return False
print_msg("Give me the fucking data for the network "+net['Name']+"\n\n")
pwd = input("Enter the fucking PASSWORD: ")
dhcp = checkYN(input("Is this fucking wifi having a DHCP? <Y|n>: "), default='Y')
errnum = 0
net['conf']['psk'] = pwd
net['conf']['dhcp'] = dhcp
if not dhcp: if not dhcp:
ip = input("IP") ip = None
while not validateIP(ip) and errnum < 5:
if ip != None:
print_error(" ARE YOU KIDDING ME? That't not an IP address! ")
errnum = errnum+1
ip = input(" So, what's your fucking IP address? ")
if errnum >= 5:
return False
net['conf']['ip'] = ip
mask = None
while not validateIP(mask) and errnum < 5:
if mask != None:
print_error(" ARE YOU KITTING ME? That's doesn't seems to be a mask! ")
errnum = errnum+1
mask = input(" Good boy, now, tell me your fucking netmask too: ")
if errnum >= 5:
return False
net['conf']['nmask'] = mask
gw = None
while not validateIP(gw) and gw != 'n' and errnum < 5:
if gw != None:
print_error(" ARE YOU KITTING ME? Enter a fucking GW address or n for none!! ")
errnum = errnum+1
gw = input(" Finally we are there, what's your fucking GW address? ( you can type n if no gateway ): ")
if errnum >= 5:
return False
if not validateIP(gw):
gw = checkYN(gw)
net['conf']['gw'] = gw
autoc = checkYN(input(" Do you fucking want to connect automatically to this network? <Y|n|Fuck Yeah!|fuck no!> "), default='y')
net['conf']['auto'] = autoc
if not write_netconf(net['Name'], net['conf']):
print_error(" FUCK! I CANT WRITE THE CONFIG FILE FOR THIS FUCKING NETWORK!!! ")
time.sleep(2)
# XXX Should we return False
return True
...@@ -336,7 +423,13 @@ while not EXIT: ...@@ -336,7 +423,13 @@ while not EXIT:
elif SM=="preconnect": elif SM=="preconnect":
if not selected['conf']['saved']: if not selected['conf']['saved']:
insertNetwork(selected) if insertNetwork(selected):
SM="connect"
else:
print_error(" FUCK, it seems i can't add this fucking network ")
time.sleep(1)
SM="main"
else:
SM="connect" SM="connect"
elif SM=="remove": elif SM=="remove":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment