Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
85787245
Commit
85787245
authored
Feb 21, 2019
by
Дмитрий Никулин
Committed by
Никита Ефремов
Apr 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add network configuration module
parent
e940ecd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
main.conf
configs/settingsd/main.conf
+2
-0
fmod_network.py
plugins/functions/fmod_network.py
+82
-0
No files found.
configs/settingsd/main.conf
View file @
85787245
...
...
@@ -32,3 +32,5 @@ enabled = yes
[
package_updates
]
enabled
=
yes
[
network
]
enabled
=
yes
plugins/functions/fmod_network.py
0 → 100644
View file @
85787245
# -*- coding: utf-8 -*-
import
socket
from
pyroute2
import
IPDB
from
pyroute2.netlink.rtnl.ifinfmsg
import
IFF_UP
from
ipaddress
import
IPv4Address
from
yaml
import
dump
from
settingsd
import
const
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
logger
import
settingsd.tools
as
tools
import
settingsd.tools.process
import
settingsd.tools.editors
##### Private constants #####
SERVICE_NAME
=
"network"
NETWORK_METHODS_NAMESPACE
=
"network"
NETWORK_SERVICES
=
{
'ssh'
:
(
22
,
),
'http'
:
(
80
,
443
),
'smtp'
:
(
25
,
465
,
587
)
}
##### Private classes #####
class
Network
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
NETWORK_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
dumpCurrentSettings
(
self
,
filename
):
settings
=
{}
settings
[
'hostname'
]
=
socket
.
gethostname
()
settings
[
'interfaces'
]
=
self
.
_dump_interfaces
()
settings
[
'dns'
]
=
self
.
_get_dns_servers
()
with
open
(
filename
,
'w+'
)
as
network_config
:
network_config
.
write
(
dump
(
settings
))
def
_dump_interfaces
(
self
):
interfaces
=
{}
with
IPDB
()
as
ipdb
:
for
interface
in
ipdb
.
interfaces
.
values
():
interfaces
[
interface
.
ifname
]
=
{
'enabled'
:
bool
(
interface
.
flags
&
IFF_UP
),
'address'
:
interface
.
ipaddr
[
0
][
'address'
],
'mask'
:
self
.
_prefix_to_netmask
(
interface
.
ipaddr
[
0
][
'prefixlen'
]),
'services'
:
{
service
:
False
for
service
in
NETWORK_SERVICES
}
}
return
interfaces
def
_get_dns_servers
(
self
):
with
open
(
'/etc/resolv.conf'
,
'r'
)
as
resolv_conf
:
return
[
line
.
split
(
' '
)[
1
]
for
line
in
resolv_conf
.
readlines
()
if
line
.
startswith
(
'nameserver'
)
]
def
_prefix_to_netmask
(
self
,
prefix
):
return
str
(
IPv4Address
(
(
0xffffffff
<<
(
32
-
prefix
))
&
0xffffffff
))
##### Public classes #####
class
Service
(
service
.
Service
)
:
### Public ###
def
initService
(
self
)
:
shared
.
Functions
.
addSharedObject
(
SERVICE_NAME
,
Network
(
SERVICE_NAME
,
self
))
### Private ###
@classmethod
def
serviceName
(
self
)
:
return
SERVICE_NAME
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