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
40773897
Commit
40773897
authored
4 years ago
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write the fucking config files
parent
d540f952
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
8 deletions
+101
-8
fuswim
fuswim
+101
-8
No files found.
fuswim
View file @
40773897
...
...
@@ -16,7 +16,7 @@ except:
boot
=
False
auto
=
False
NETPATH
=
'/etc/fuswi
n
/networks'
NETPATH
=
'/etc/fuswi
m
/networks'
class
colors
:
ENDC
=
'
\033
[m'
...
...
@@ -99,6 +99,18 @@ def checkYN(res, default='N'):
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
):
p
=
"/"
.
join
([
NETPATH
,
net
])
conf
=
{
...
...
@@ -121,6 +133,9 @@ def read_netconf(net):
k
,
v
=
line
.
split
(
":"
,
1
)
if
k
in
[
'auto'
,
'dhcp'
]:
v
=
checkYN
(
v
)
if
k
==
'gw'
:
if
not
validateIP
(
v
):
v
=
checkYN
(
v
)
conf
[
k
]
=
v
conf
[
'saved'
]
=
True
return
conf
...
...
@@ -129,6 +144,29 @@ def read_netconf(net):
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
):
for
process
in
psutil
.
process_iter
():
...
...
@@ -181,12 +219,61 @@ def fuckquit(fuck):
def
insertNetwork
(
net
):
print_msg
(
"Give me the fucking data for the network "
+
net
[
'Name'
])
pwd
=
input
(
"PASSWORD: "
)
dhcp
=
checkYN
(
input
(
"DHCP? <Y|n>: "
),
default
=
'Y'
)
if
net
[
'Name'
]
==
''
:
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
:
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
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
'boot'
:
...
...
@@ -336,8 +423,14 @@ while not EXIT:
elif
SM
==
"preconnect"
:
if
not
selected
[
'conf'
][
'saved'
]:
insertNetwork
(
selected
)
SM
=
"connect"
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"
elif
SM
==
"remove"
:
print
(
"
\n
FOR FUCK SAKE, are you too lazy to do a rm by hand in "
+
NETPATH
+
"?
\n
"
)
...
...
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