forked from extern/wg-meshconf
formatted code with black
This commit is contained in:
parent
bea7a4bbe7
commit
a08d831cc4
@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Name: Database Manager
|
Name: Database Manager
|
||||||
Dev: K4YT3X
|
Creator: K4YT3X
|
||||||
Date Created: July 19, 2020
|
Date Created: July 19, 2020
|
||||||
Last Modified: November 15, 2020
|
Last Modified: November 15, 2020
|
||||||
"""
|
"""
|
||||||
@ -63,7 +63,7 @@ class DatabaseManager:
|
|||||||
self.wireguard = WireGuard()
|
self.wireguard = WireGuard()
|
||||||
|
|
||||||
def read_database(self):
|
def read_database(self):
|
||||||
""" read database file into dict
|
"""read database file into dict
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: content of database file in dict format
|
dict: content of database file in dict format
|
||||||
@ -75,7 +75,7 @@ class DatabaseManager:
|
|||||||
return json.load(database_file)
|
return json.load(database_file)
|
||||||
|
|
||||||
def write_database(self, data: dict):
|
def write_database(self, data: dict):
|
||||||
""" dump data into database file
|
"""dump data into database file
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (dict): content of database
|
data (dict): content of database
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Name: wg-meshconf
|
Name: wg-meshconf
|
||||||
Dev: K4YT3X
|
Creator: K4YT3X
|
||||||
Date Created: July 19, 2020
|
Date Created: July 19, 2020
|
||||||
Last Modified: November 15, 2020
|
Last Modified: January 12, 2021
|
||||||
|
|
||||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
||||||
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
(C) 2018-2020 K4YT3X
|
(C) 2018-2021 K4YT3X
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# built-in imports
|
# built-in imports
|
||||||
@ -21,8 +21,7 @@ from .database_manager import DatabaseManager
|
|||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
""" parse CLI arguments
|
"""parse CLI arguments"""
|
||||||
"""
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="wg-meshconf", formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
prog="wg-meshconf", formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||||
)
|
)
|
||||||
@ -45,7 +44,9 @@ def parse_arguments():
|
|||||||
"--address", help="address of the server", action="append", required=True
|
"--address", help="address of the server", action="append", required=True
|
||||||
)
|
)
|
||||||
addpeer.add_argument("--endpoint", help="peer's public endpoint address")
|
addpeer.add_argument("--endpoint", help="peer's public endpoint address")
|
||||||
addpeer.add_argument("--allowedips", help="additional allowed IP addresses", action="append")
|
addpeer.add_argument(
|
||||||
|
"--allowedips", help="additional allowed IP addresses", action="append"
|
||||||
|
)
|
||||||
addpeer.add_argument("--privatekey", help="private key of server interface")
|
addpeer.add_argument("--privatekey", help="private key of server interface")
|
||||||
addpeer.add_argument("--listenport", help="port to listen on", default=51820)
|
addpeer.add_argument("--listenport", help="port to listen on", default=51820)
|
||||||
addpeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
addpeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
||||||
@ -68,7 +69,9 @@ def parse_arguments():
|
|||||||
updatepeer.add_argument("name", help="Name used to identify this node")
|
updatepeer.add_argument("name", help="Name used to identify this node")
|
||||||
updatepeer.add_argument("--address", help="address of the server", action="append")
|
updatepeer.add_argument("--address", help="address of the server", action="append")
|
||||||
updatepeer.add_argument("--endpoint", help="peer's public endpoint address")
|
updatepeer.add_argument("--endpoint", help="peer's public endpoint address")
|
||||||
updatepeer.add_argument("--allowedips", help="additional allowed IP addresses", action="append")
|
updatepeer.add_argument(
|
||||||
|
"--allowedips", help="additional allowed IP addresses", action="append"
|
||||||
|
)
|
||||||
updatepeer.add_argument("--privatekey", help="private key of server interface")
|
updatepeer.add_argument("--privatekey", help="private key of server interface")
|
||||||
updatepeer.add_argument("--listenport", help="port to listen on")
|
updatepeer.add_argument("--listenport", help="port to listen on")
|
||||||
updatepeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
updatepeer.add_argument("--fwmark", help="fwmark for outgoing packets")
|
||||||
@ -93,7 +96,9 @@ def parse_arguments():
|
|||||||
# showpeers prints a table of all peers and their configurations
|
# showpeers prints a table of all peers and their configurations
|
||||||
showpeers = subparsers.add_parser("showpeers")
|
showpeers = subparsers.add_parser("showpeers")
|
||||||
showpeers.add_argument(
|
showpeers.add_argument(
|
||||||
"name", help="Name of the peer to query", nargs="?",
|
"name",
|
||||||
|
help="Name of the peer to query",
|
||||||
|
nargs="?",
|
||||||
)
|
)
|
||||||
showpeers.add_argument(
|
showpeers.add_argument(
|
||||||
"--style",
|
"--style",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Name: WireGuard Python Bindings
|
Name: WireGuard Python Bindings
|
||||||
Dev: K4YT3X
|
Creator: K4YT3X
|
||||||
Date Created: October 11, 2019
|
Date Created: October 11, 2019
|
||||||
Last Modified: July 19, 2020
|
Last Modified: July 19, 2020
|
||||||
"""
|
"""
|
||||||
@ -13,7 +13,7 @@ import subprocess
|
|||||||
|
|
||||||
|
|
||||||
class WireGuard:
|
class WireGuard:
|
||||||
""" WireGuard utility controller
|
"""WireGuard utility controller
|
||||||
|
|
||||||
This class handles the interactions with the wg binary,
|
This class handles the interactions with the wg binary,
|
||||||
including:
|
including:
|
||||||
@ -35,7 +35,7 @@ class WireGuard:
|
|||||||
self.wg_binary = wg_binary
|
self.wg_binary = wg_binary
|
||||||
|
|
||||||
def genkey(self):
|
def genkey(self):
|
||||||
""" generate WG private key
|
"""generate WG private key
|
||||||
|
|
||||||
Generate a new wireguard private key via
|
Generate a new wireguard private key via
|
||||||
wg command.
|
wg command.
|
||||||
@ -51,7 +51,7 @@ class WireGuard:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def pubkey(self, privkey: str) -> str:
|
def pubkey(self, privkey: str) -> str:
|
||||||
""" convert WG private key into public key
|
"""convert WG private key into public key
|
||||||
|
|
||||||
Uses wg pubkey command to convert the wg private
|
Uses wg pubkey command to convert the wg private
|
||||||
key into a public key.
|
key into a public key.
|
||||||
@ -74,8 +74,7 @@ class WireGuard:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def genpsk(self):
|
def genpsk(self):
|
||||||
""" generate a random base64 PSK
|
"""generate a random base64 PSK"""
|
||||||
"""
|
|
||||||
return (
|
return (
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[str(self.wg_binary.absolute()), "genpsk"],
|
[str(self.wg_binary.absolute()), "genpsk"],
|
||||||
|
Loading…
Reference in New Issue
Block a user