mirror of
https://github.com/k4yt3x/wg-meshconf.git
synced 2024-11-25 09:03:11 +01:00
added support for optional peer attributes, added __main__
This commit is contained in:
parent
6673a6d2f6
commit
559a51393b
14
wg_meshconf/__main__.py
Normal file
14
wg_meshconf/__main__.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: wg-meshconf __main__
|
||||
Creator: K4YT3X
|
||||
Date Created: May 21, 2021
|
||||
Last Modified: May 21, 2021
|
||||
"""
|
||||
|
||||
from .wg_meshconf import main
|
||||
|
||||
# launch the main function if it is not imported as a package
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -60,6 +60,10 @@ PEER_ATTRIBUTES = [
|
||||
"PersistentKeepalive",
|
||||
]
|
||||
|
||||
PEER_OPTIONAL_ATTRIBUTES = [
|
||||
"PersistentKeepalive",
|
||||
]
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
def __init__(self, database_path: pathlib.Path):
|
||||
@ -95,6 +99,7 @@ class DatabaseManager:
|
||||
Endpoint: str = None,
|
||||
AllowedIPs: list = None,
|
||||
ListenPort: int = None,
|
||||
PersistentKeepalive: int = None,
|
||||
FwMark: str = None,
|
||||
PrivateKey: str = None,
|
||||
DNS: str = None,
|
||||
@ -133,6 +138,7 @@ class DatabaseManager:
|
||||
Endpoint: str = None,
|
||||
AllowedIPs: list = None,
|
||||
ListenPort: int = None,
|
||||
PersistentKeepalive: int = None,
|
||||
FwMark: str = None,
|
||||
PrivateKey: str = None,
|
||||
DNS: str = None,
|
||||
@ -303,3 +309,9 @@ class DatabaseManager:
|
||||
else:
|
||||
allowed_ips = ", ".join(database["peers"][p]["Address"])
|
||||
config.write("AllowedIPs = {}\n".format(allowed_ips))
|
||||
|
||||
for key in PEER_OPTIONAL_ATTRIBUTES:
|
||||
if database["peers"][p].get(key) is not None:
|
||||
config.write(
|
||||
"{} = {}\n".format(key, database["peers"][p][key])
|
||||
)
|
||||
|
@ -4,7 +4,7 @@
|
||||
Name: wg-meshconf
|
||||
Creator: K4YT3X
|
||||
Date Created: July 19, 2020
|
||||
Last Modified: January 12, 2021
|
||||
Last Modified: May 21, 2021
|
||||
|
||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
||||
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
@ -52,6 +52,7 @@ def parse_arguments():
|
||||
)
|
||||
addpeer.add_argument("--privatekey", help="private key of server interface")
|
||||
addpeer.add_argument("--listenport", help="port to listen on", default=51820)
|
||||
addpeer.add_argument("--persistentkeepalive", help="set persistent keepalive interval")
|
||||
addpeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
||||
addpeer.add_argument("--dns", help="server interface DNS servers")
|
||||
addpeer.add_argument("--mtu", help="server interface MTU")
|
||||
@ -77,6 +78,7 @@ def parse_arguments():
|
||||
)
|
||||
updatepeer.add_argument("--privatekey", help="private key of server interface")
|
||||
updatepeer.add_argument("--listenport", help="port to listen on")
|
||||
updatepeer.add_argument("--persistentkeepalive", help="set persistent keepalive interval")
|
||||
updatepeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
||||
updatepeer.add_argument("--dns", help="server interface DNS servers")
|
||||
updatepeer.add_argument("--mtu", help="server interface MTU")
|
||||
@ -129,7 +131,7 @@ def parse_arguments():
|
||||
"--output",
|
||||
help="configuration file output directory",
|
||||
type=pathlib.Path,
|
||||
default=pathlib.Path(__file__).parent.absolute() / "output",
|
||||
default=pathlib.Path.cwd() / "output",
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
@ -149,6 +151,7 @@ def main():
|
||||
args.endpoint,
|
||||
args.allowedips,
|
||||
args.listenport,
|
||||
args.persistentkeepalive,
|
||||
args.fwmark,
|
||||
args.privatekey,
|
||||
args.dns,
|
||||
@ -168,6 +171,7 @@ def main():
|
||||
args.endpoint,
|
||||
args.allowedips,
|
||||
args.listenport,
|
||||
args.persistentkeepalive,
|
||||
args.fwmark,
|
||||
args.privatekey,
|
||||
args.dns,
|
||||
@ -195,8 +199,3 @@ def main():
|
||||
"No command specified\nUse wg-meshconf --help to see available commands",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
# launch the main function if it is not imported as a package
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user