little fixes

This commit is contained in:
Désiré Werner Menrath 2024-09-07 23:52:16 +02:00
parent 858e9f07fe
commit 607589d44a
6 changed files with 63 additions and 50 deletions

View File

@ -4,10 +4,13 @@
<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 Options in"> <list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes">
<change afterPath="$PROJECT_DIR$/start_wg.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/wg_py" afterDir="false" />
<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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.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_func.py" beforeDir="false" afterPath="$PROJECT_DIR$/wg_func.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wg_py.xml" beforeDir="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" />
@ -45,13 +48,15 @@
&quot;keyToString&quot;: { &quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;, &quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;Python.start_wg.executor&quot;: &quot;Run&quot;,
&quot;Python.wg_func.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;, &quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/punix/Pyapps/wire-py&quot;, &quot;last_opened_file_path&quot;: &quot;/home/punix/Pyapps/wire-py&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot; &quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
} }
}</component> }</component>
<component name="RunManager"> <component name="RunManager" selected="Python.main">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true"> <configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="wire-py" /> <module name="wire-py" />
<option name="ENV_FILES" value="" /> <option name="ENV_FILES" value="" />
@ -74,6 +79,33 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="start_wg" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wire-py" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/start_wg.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.start_wg" />
</list>
</recent_temporary>
</component> </component>
<component name="SharedIndexes"> <component name="SharedIndexes">
<attachedChunks> <attachedChunks>
@ -291,7 +323,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1725567453540</updated> <updated>1725567453540</updated>
</task> </task>
<option name="localTasksCounter" value="26" /> <task id="LOCAL-00026" summary="little fixes">
<option name="closed" value="true" />
<created>1725639633873</created>
<option name="number" value="00026" />
<option name="presentableId" value="LOCAL-00026" />
<option name="project" value="LOCAL" />
<updated>1725639633873</updated>
</task>
<option name="localTasksCounter" value="27" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -343,6 +383,7 @@
<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!" />
<MESSAGE value="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write" /> <MESSAGE value="fixes on empty Listbox now is disable and now works autoconnect label with read and write, delete works now with read and write" />
<MESSAGE value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" /> <MESSAGE value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" />
<option name="LAST_COMMIT_MESSAGE" value="add Frame widget 3&#10;for Buttons and Listbox with Scrollbar.&#10;all Widgets new format&#10;delete works now of disable checkbox when Listbox empty (part two)" /> <MESSAGE value="little fixes" />
<option name="LAST_COMMIT_MESSAGE" value="little fixes" />
</component> </component>
</project> </project>

22
main.py
View File

@ -7,7 +7,6 @@ from wg_func import (TunnelActiv, ListTunnels, ImportTunnel, ConToDict, GreenLab
FileHandle, ExportTunnels, OnOff) FileHandle, ExportTunnels, OnOff)
font_color = '#4011a7' font_color = '#4011a7'
replacement = ''
class MainWindow(tk.Tk): class MainWindow(tk.Tk):
@ -35,8 +34,7 @@ class MainWindow(tk.Tk):
# App Menu # App Menu
self.app_menu = tk.Menu(self, borderwidth=0) self.app_menu = tk.Menu(self, borderwidth=0)
for item in self.app_menu.keys():
print(item, ': ', self.app_menu[item])
self.configure(menu=self.app_menu) self.configure(menu=self.app_menu)
self.app_menu.add_cascade(label='?') self.app_menu.add_cascade(label='?')
@ -106,7 +104,6 @@ class FrameWidgets(ttk.Frame):
# Listbox with Scrollbar # Listbox with Scrollbar
def enable_check_box(event): def enable_check_box(event):
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
print(len(tl))
if len(tl) != 0: if len(tl) != 0:
self.wg_autostart.configure(state='normal') self.wg_autostart.configure(state='normal')
@ -158,23 +155,6 @@ class FrameWidgets(ttk.Frame):
self.l_box.delete(self.select_tunnel[0]) self.l_box.delete(self.select_tunnel[0])
os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf') os.remove(os.environ['HOME'] + '/tester/' + str(select_tl) + '.conf')
del_tl_read = open('wg_py.xml', 'r')
if 'false ' in del_tl_read:
first_word = 'false '
else:
first_word = 'true '
word_replace = ''
# using the for loop
for line in del_tl_read:
line = line.strip()
changes = line.replace(first_word + select_tl, '')
word_replace = word_replace + changes + "\n"
del_tl_read.close()
del_tl = open('wg_py.xml', 'w')
del_tl.write(word_replace)
del_tl.close()
# for disable checkbox when Listbox empty # for disable checkbox when Listbox empty
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
if len(tl) == 0: if len(tl) == 0:

12
start_wg.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/python3
from subprocess import check_call
from pathlib import Path
home = Path.home()
path_to_file = home / 'Pyapps/wire-py/wg_py'
with open(path_to_file, 'r') as file:
for line in file.readlines():
a_con = line[5:]
check_call(['nmcli', 'connection', 'up', a_con])

View File

@ -213,9 +213,6 @@ class ImportTunnel:
ShowAddress.show_data(self) ShowAddress.show_data(self)
file.close() file.close()
os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no') os.system('nmcli con mod ' + str(self.a) + ' connection.autoconnect no')
new_tl = open('wg_py.xml', 'a')
new_tl.write('false ' + str(self.a) + '\n')
new_tl.close()
if 'PrivateKey = ' not in read: if 'PrivateKey = ' not in read:
Message() Message()
except EOFError: except EOFError:
@ -240,31 +237,16 @@ class FileHandle:
self.select_tunnel = None self.select_tunnel = None
def box_set(self): def box_set(self):
word_replace = ''
try: try:
self.select_tunnel = self.l_box.curselection() self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0]) select_tl = self.l_box.get(self.select_tunnel[0])
if self.selected_option.get() == 0: if self.selected_option.get() == 0:
set_on = open('wg_py.xml', 'r') off = open('wg_py', 'w')
# using the for loop off.close()
for line in set_on:
line = line.strip()
changes = line.replace('true ' + select_tl, 'false ' + select_tl)
os.system('nmcli con mod ' + str(self.auto_con) + ' connection.autoconnect no')
word_replace = word_replace + changes + "\n"
set_on.close()
if self.selected_option.get() >= 1: if self.selected_option.get() >= 1:
set_on = open('wg_py.xml', 'r') set_on = open('wg_py', 'w')
# using the for loop set_on.write(select_tl)
for line in set_on:
line = line.strip()
changes = line.replace('false ' + select_tl, 'true ' + select_tl)
os.system('nmcli con mod ' + str(select_tl) + ' connection.autoconnect yes')
word_replace = word_replace + changes + "\n"
set_on.close() set_on.close()
set_off = open('wg_py.xml', 'w')
set_off.write(word_replace)
set_off.close()
except IndexError: except IndexError:
self.selected_option.set(1) self.selected_option.set(1)
@ -279,7 +261,7 @@ class OnOff(tk.Tk, FileHandle):
def on_off(self): def on_off(self):
a_connect = {} a_connect = {}
on_or_off = open('wg_py.xml', 'r') on_or_off = open('wg_py', 'r')
for line in on_or_off.readlines(): for line in on_or_off.readlines():
line_splitted = line.split() line_splitted = line.split()
a_connect[line_splitted[0]] = line_splitted[1] a_connect[line_splitted[0]] = line_splitted[1]

0
wg_py Normal file
View File

View File

@ -1,2 +0,0 @@
false peer_iasus
false rverEppingen