Descriptions added in wg_func-py

This commit is contained in:
Désiré Werner Menrath 2024-09-22 17:17:02 +02:00
parent 7e461db7a9
commit 9899395cf9
2 changed files with 87 additions and 7 deletions

View File

@ -4,10 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again&#10;now works">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/wg_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_main.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -494,7 +493,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1726959423800</updated> <updated>1726959423800</updated>
</task> </task>
<option name="localTasksCounter" value="46" /> <task id="LOCAL-00046" summary="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again&#10;now works">
<option name="closed" value="true" />
<created>1727015078922</created>
<option name="number" value="00046" />
<option name="presentableId" value="LOCAL-00046" />
<option name="project" value="LOCAL" />
<updated>1727015078922</updated>
</task>
<option name="localTasksCounter" value="47" />
<servers /> <servers />
</component> </component>
<component name="UnknownFeatures"> <component name="UnknownFeatures">
@ -535,7 +542,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="columnconfigure on all widgets set" />
<MESSAGE value="little fixes a &quot; &quot; to ' '" /> <MESSAGE value="little fixes a &quot; &quot; to ' '" />
<MESSAGE value="add class FileHandle,&#10;add Label to show autoconnect Tunnel&#10;disable checkbox when Listbox is empty or no select Tunnel" /> <MESSAGE value="add class FileHandle,&#10;add Label to show autoconnect Tunnel&#10;disable checkbox when Listbox is empty or no select Tunnel" />
<MESSAGE value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" /> <MESSAGE value="add if question and add autoconnect, autoconnect_var to class Filehandle in box_set no finish!" />
@ -560,6 +566,33 @@
<MESSAGE value="chown Export File to 1000:1000" /> <MESSAGE value="chown Export File to 1000:1000" />
<MESSAGE value="add rename Label rename works" /> <MESSAGE value="add rename Label rename works" />
<MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" /> <MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" />
<option name="LAST_COMMIT_MESSAGE" value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again" /> <MESSAGE value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again&#10;now works" />
<option name="LAST_COMMIT_MESSAGE" value="add con_to_dict in import for write PreSharedKey in .key File to warning if tunnel has already been imported and delete that the key is deleted again&#10;now works" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/wg_func.py</url>
<line>135</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/wg_func.py</url>
<line>194</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/wg_func.py</url>
<line>72</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/wg_func.py</url>
<line>343</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component> </component>
</project> </project>

View File

@ -16,6 +16,9 @@ _u = Path.read_text(Path('/tmp/_u'))
def msg_window(img_w, img_i, w_title, w_txt): def msg_window(img_w, img_i, w_title, w_txt):
""" """
Function for different message windows for the user. with 4 arguments to be passed.
To create messages with your own images, icons, and titles. As an alternative to Python Messagebox.
Paths to images must be specified: r'/usr/share/icons/wp-icons/64/info.png'
img_w = Image for Tk Window img_w = Image for Tk Window
img_i = Image for Icon img_i = Image for Icon
w_title = Windows Title w_title = Windows Title
@ -46,6 +49,9 @@ def msg_window(img_w, img_i, w_title, w_txt):
class GreenLabel: class GreenLabel:
"""
Show the active tunnel in green in the label
"""
def __init__(self): def __init__(self):
self.StrVar = None self.StrVar = None
self.lb_tunnel = None self.lb_tunnel = None
@ -65,6 +71,9 @@ class GreenLabel:
class StartStopBTN: class StartStopBTN:
"""
Show Start and Stop Button in Label
"""
def __init__(self): def __init__(self):
self.lb_frame_btn_lbox = None self.lb_frame_btn_lbox = None
self.wg_switch = None self.wg_switch = None
@ -82,6 +91,10 @@ class StartStopBTN:
class ConToDict: class ConToDict:
"""
The config file is packed into a dictionary,
to display the values Address , DNS and Peer in the labels
"""
@classmethod @classmethod
def covert_to_dict(cls, file): def covert_to_dict(cls, file):
dictlist = [] dictlist = []
@ -121,6 +134,9 @@ class ConToDict:
class TunnelActiv: class TunnelActiv:
"""
Shows the Active Tunnel
"""
@staticmethod @staticmethod
def active(): # Shows the active tunnel def active(): # Shows the active tunnel
active = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split() active = os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"').read().split()
@ -133,6 +149,10 @@ class TunnelActiv:
class ShowAddress: class ShowAddress:
"""
Displays the value address, DNS and peer in the labels
or empty it again
"""
def __init__(self): def __init__(self):
self.lb_frame2 = None self.lb_frame2 = None
self.lb_frame = None self.lb_frame = None
@ -173,14 +193,27 @@ class ShowAddress:
class ListTunnels: class ListTunnels:
"""
Shows all existing Wireguard tunnels
"""
@staticmethod @staticmethod
def tl_list(): def tl_list():
wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split() wg_s = os.popen('nmcli con show | grep -iPo "(.*)(wireguard)"').read().split()
tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list tl = wg_s[::3] # tl = Tunnel list # Show of 4.Element in list
return tl return tl
class ImportTunnel: class ImportTunnel:
"""
Import Class for Wireguard config Files.
Before importing, it is checked whether PrivateKey and PublicKey are in the file.
If True then it is checked whether the PreSharedKey is already in the key file
to avoid an import error so that no double wgconf are imported.
Thus, tunnels can be renamed without the problems arise. If False then the key is written into the file.
Furthermore, it is checked whether the name is longer than 12 characters.
If True then the name is automatically shortened to 12 characters and then imported.
If in each case false comes out, a corresponding window comes to inform the user that something is wrong.
"""
def __init__(self): def __init__(self):
@ -276,7 +309,11 @@ class ImportTunnel:
class FileHandle: class FileHandle:
"""
This class will display the autostart label which
Tunnel is automatically started regardless of the active tunnel.
The selected tunnel is written into a file to read it after the start of the system.
"""
def __init__(self): def __init__(self):
self.wg_autostart = None self.wg_autostart = None
@ -305,6 +342,11 @@ class FileHandle:
class OnOff: class OnOff:
"""
Here it is checked whether the path to the file is there if not it is created.
Set (on), the selected tunnel is displayed in the label.
At (off) the label is first emptied then filled with No Autoconnect
"""
def __init__(self): def __init__(self):
self.wg_autostart = None self.wg_autostart = None
self.selected_option = None self.selected_option = None
@ -332,6 +374,11 @@ class OnOff:
class ExportTunnels: class ExportTunnels:
"""
This will export the tunnels.
A zipfile with current date and time is created
in the user's home directory with correct right
"""
@staticmethod @staticmethod
def wg_export(): def wg_export():
_u1 = str(_u[6:]) _u1 = str(_u[6:])