Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fuswim
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sysadmin
fuswim
Commits
1a3c9514
Commit
1a3c9514
authored
3 years ago
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Maybe is working!
parent
40773897
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
18 deletions
+56
-18
fuswim
fuswim
+56
-18
No files found.
fuswim
View file @
1a3c9514
...
@@ -99,6 +99,9 @@ def checkYN(res, default='N'):
...
@@ -99,6 +99,9 @@ def checkYN(res, default='N'):
return
False
return
False
def
netmaskToBit
(
nmask
):
return
str
(
sum
(
bin
(
int
(
x
))
.
count
(
'1'
)
for
x
in
mask
.
split
(
'.'
)))
def
validateIP
(
ip
):
def
validateIP
(
ip
):
if
not
ip
:
if
not
ip
:
return
False
return
False
...
@@ -146,6 +149,7 @@ def read_netconf(net):
...
@@ -146,6 +149,7 @@ def read_netconf(net):
def
write_netconf
(
net
,
nconf
):
def
write_netconf
(
net
,
nconf
):
p
=
"/"
.
join
([
NETPATH
,
net
])
p
=
"/"
.
join
([
NETPATH
,
net
])
try
:
with
open
(
p
,
'w'
)
as
f
:
with
open
(
p
,
'w'
)
as
f
:
for
k
in
nconf
.
keys
():
for
k
in
nconf
.
keys
():
if
k
!=
'saved'
:
if
k
!=
'saved'
:
...
@@ -163,10 +167,31 @@ def write_netconf(net, nconf):
...
@@ -163,10 +167,31 @@ def write_netconf(net, nconf):
else
:
else
:
f
.
write
(
k
+
':'
+
str
(
nconf
[
k
])
+
'
\n
'
)
f
.
write
(
k
+
':'
+
str
(
nconf
[
k
])
+
'
\n
'
)
f
.
close
()
f
.
close
()
sys
.
exit
(
0
)
except
:
return
False
return
True
return
True
WPAHEAD
=
"""# needed for wpa_gui to work
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
# needed to allow wpa_gui to alter the configuration
update_config=1
"""
def
create_wpacfile
(
cfile
,
selected
):
# XXX Not all the world is WPA-PSK compatible. And the rest...
# should we try to create a better config?
#
with
open
(
cfile
,
'w'
)
as
f
:
f
.
write
(
WPAHEAD
)
f
.
write
(
"
\n
network={
\n
"
)
f
.
write
(
" ssid=
\"
"
+
selected
[
'Name'
]
+
"
\"\n
"
)
f
.
write
(
" scan_ssid=1
\n
"
)
f
.
write
(
" key_mgmt=WPA-PSK
\n
"
)
f
.
write
(
" psk=
\"
"
+
selected
[
'conf'
][
'psk'
]
+
"
\"\n
"
)
f
.
write
(
"}
\n
"
)
f
.
close
()
def
kill_proc
(
name
,
ops
=
False
):
def
kill_proc
(
name
,
ops
=
False
):
for
process
in
psutil
.
process_iter
():
for
process
in
psutil
.
process_iter
():
...
@@ -177,10 +202,13 @@ def kill_proc(name, ops=False):
...
@@ -177,10 +202,13 @@ def kill_proc(name, ops=False):
else
:
else
:
process
.
kill
()
process
.
kill
()
def
start_wpa
(
interface
):
def
start_wpa
(
interface
,
conf
=
False
):
kill_proc
(
"dhclient"
,
interface
)
kill_proc
(
"dhclient"
,
interface
)
kill_proc
(
"wpa_supplicant"
,
interface
)
kill_proc
(
"wpa_supplicant"
,
interface
)
sh
(
"/sbin/wpa_supplicant -s -B -P /run/wpa_supplicant."
+
interface
+
".pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant"
)
adds
=
''
if
conf
:
adds
=
' -c '
+
conf
sh
(
"/sbin/wpa_supplicant -s -B -P /run/wpa_supplicant."
+
interface
+
".pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant"
+
adds
)
def
show_fuck_list
(
nets
):
def
show_fuck_list
(
nets
):
...
@@ -380,6 +408,16 @@ while not EXIT:
...
@@ -380,6 +408,16 @@ while not EXIT:
elif
SM
==
"connect"
:
elif
SM
==
"connect"
:
done
=
False
done
=
False
if
selected
:
if
selected
:
cfile
=
'/tmp/wpa.'
+
interface
+
'.conf'
create_wpacfile
(
cfile
,
selected
)
start_wpa
(
interface
,
cfile
)
if
selected
[
'conf'
][
'dhcp'
]:
sh
(
"dhclient "
+
interface
)
else
:
sh
(
"ip address add "
+
selected
[
'conf'
][
'ip'
]
+
"/"
+
netmaskToBit
(
selected
[
'conf'
][
'nmask'
])
+
" dev "
+
interface
)
sh
(
"ip link set "
+
interface
+
" up"
)
if
selected
[
'conf'
][
'gw'
]:
sh
(
"ip route add default via "
+
selected
[
'conf'
][
'gw'
]
+
" dev "
+
interface
)
done
=
True
done
=
True
else
:
else
:
print_error
(
"FUCK, Are you asking me to connect but you didn't select successfully any network???"
)
print_error
(
"FUCK, Are you asking me to connect but you didn't select successfully any network???"
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment