Skip to content

Commit

Permalink
ACT in GUI-Warp macOS port
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Sep 25, 2023
1 parent b061a38 commit 3c81afe
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

* 2023.09.24 Current
* 2023.09.25 Current
* ACT in `GUI-Warp` macOS port
* `gui-warp.py`: ACT tab introduced; minor ACT pipe fixes
* Timestamps added to ACT; option to unlink ACT pipe
* ACT data requested via `SIGUSR2` available in `<PREFIX>/var/spool/ts-warp.act`
Expand Down
13 changes: 6 additions & 7 deletions gui/gui-warp.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class App:

self.password = ''

self.version = 'v1.0.10'
self.version = 'v1.0.11'
self.width = width
self.height = height

Expand Down Expand Up @@ -100,7 +100,7 @@ class App:
self.tsw_opts = tk.StringVar()
self.ent_opt = ttk.Entry(lfrm_top, textvariable=self.tsw_opts).grid(column=5, row=0, padx=3, sticky=tk.EW)

# -- Display ini/fw/log pane --------------------------------------------------------------------------------- #
# -- Display INI/FW/LOG/ACT pane ----------------------------------------------------------------------------- #
tabControl = ttk.Notebook(self.root)
tab_ini = ttk.Frame(tabControl)
tab_fw = ttk.Frame(tabControl)
Expand Down Expand Up @@ -166,7 +166,7 @@ class App:
scroll_fw.config(command=fw_txt.yview)
fw_txt.config(yscrollcommand=scroll_fw.set)

# -- Tab Log ------------------------------------------------------------------------------------------------- #
# -- Tab LOG ------------------------------------------------------------------------------------------------- #
tab_log.columnconfigure(0, weight=1)
tab_log.rowconfigure(1, weight=1)

Expand Down Expand Up @@ -234,7 +234,7 @@ class App:
t_widget.insert('', tk.END, values=l.split(','))

if refresh:
self.root.after(3000, self.read_file_tree, t_widget, filename, refresh)
self.root.after(5000, self.read_file_tree, t_widget, filename, refresh)

def readfile(self, t_widget, filename, refresh=False):
t_widget.config(state='normal')
Expand All @@ -249,9 +249,8 @@ class App:
self.root.after(3000, self.readfile, t_widget, filename, refresh)

def savefile(self, t_widget, filename):
f = open(filename, 'w')
f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline
f.close()
with open(filename, 'w') as f:
f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline

def pauselog(self, btn, txt, filename):
if self.pause_log:
Expand Down
Binary file modified gui/ports/macOS/gui-warp.app.tgz
Binary file not shown.
96 changes: 80 additions & 16 deletions gui/ports/macOS/gui-warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, width=800, height=560,

self.password = ''

self.version = 'v1.0.15-mac'
self.version = 'v1.0.16-mac'
self.width = width
self.height = height

Expand Down Expand Up @@ -99,24 +99,27 @@ def __init__(self, width=800, height=560,
self.tsw_opts = tk.StringVar()
self.ent_opt = ttk.Entry(lfrm_top, textvariable=self.tsw_opts).grid(column=5, row=0, padx=3, sticky=tk.EW)

# -- Display ini/fw/log pane --------------------------------------------------------------------------------- #
# -- Display INI/FW/LOG/ACT pane ----------------------------------------------------------------------------- #
tabControl = ttk.Notebook(self.root)
tab_ini = ttk.Frame(tabControl)
tab_log = ttk.Frame(tabControl)
tab_act = ttk.Frame(tabControl)

tabControl.add(tab_log, text='Log')
tabControl.add(tab_ini, text='INI')
tabControl.add(tab_act, text='ACT')

tabControl.grid(column=0, row=1, sticky=tk.NSEW)

# -- Tab Log ------------------------------------------------------------------------------------------------- #
# -- Tab LOG ------------------------------------------------------------------------------------------------- #
tab_log.columnconfigure(0, weight=1)
tab_log.rowconfigure(1, weight=1)

ttk.Label(tab_log, text='Log auto-refresh:').grid(column=0, row=0, sticky=tk.E)

btn_pause = ttk.Button(tab_log, width=self._btnw, text='■')
btn_pause.grid(column=1, row=0, sticky=tk.W, padx=self._padx, pady=self._pady)
self.pause = False
self.pause_log = False
btn_pause['command'] = lambda: self.pauselog(btn_pause, log_txt, logfile)

log_txt = tk.Text(tab_log, highlightthickness=0, state='disabled')
Expand Down Expand Up @@ -162,6 +165,26 @@ def __init__(self, width=800, height=560,
scroll_ini.config(command=ini_txt.yview)
ini_txt.config(yscrollcommand=scroll_ini.set)

# -- Tab ACT ------------------------------------------------------------------------------------------------- #
tab_act.columnconfigure(0, weight=1)
tab_act.rowconfigure(1, weight=1)

ttk.Label(tab_act, text='ACT auto-refresh:').grid(column=0, row=0, sticky=tk.E)

btn_act = ttk.Button(tab_act, width=self._btnw, text='▶')
btn_act.grid(column=1, row=0, sticky=tk.W, padx=self._padx, pady=self._pady)
self.pause_act = True
btn_act['command'] = lambda: self.pauseact(btn_act, tree_act, actfile)

cols_act = ('Time', 'PID', 'Status', 'Section', 'Client', 'Client bytes', 'Target', 'Target bytes')
tree_act = ttk.Treeview(tab_act, columns=cols_act, show='headings')

for col in cols_act:
tree_act.heading(col, text=col)
tree_act.column(col, width=100)

tree_act.grid(row=1, column=0, columnspan=2, sticky=tk.NSEW)

# -- Status bar ---------------------------------------------------------------------------------------------- #
lfrm_bottom = tk.LabelFrame(self.root, relief=tk.FLAT, padx=self._padx)
lfrm_bottom.grid(column=0, row=2, sticky=tk.EW)
Expand All @@ -173,35 +196,64 @@ def __init__(self, width=800, height=560,

self.root.mainloop()

def read_file_tree(self, t_widget, filename, refresh=False):
if not self.pause_act:
with open(pidfile, 'r') as pf:
subprocess.Popen(['sudo', 'kill', '-USR2', pf.readline()[:-1]])

for item in t_widget.get_children():
t_widget.delete(item)

with open(filename, 'r') as f:
f.readline()
while True:
l = f.readline()
if l == '\n':
break
t_widget.insert('', tk.END, values=l.split(','))

if refresh:
self.root.after(5000, self.read_file_tree, t_widget, filename, refresh)

def readfile(self, t_widget, filename, refresh=False):
t_widget.config(state='normal')
f = open(filename, 'r')
t_widget.delete(1.0, tk.END)
t_widget.insert(tk.END, ''.join(f.readlines()))
t_widget.see(tk.END)
f.close()
with open(filename, 'r') as f:
t_widget.delete(1.0, tk.END)
t_widget.insert(tk.END, ''.join(f.readlines()))
t_widget.see(tk.END)

if refresh:
t_widget.config(state='disabled')
if not self.pause:
if not self.pause_log:
self.root.after(3000, self.readfile, t_widget, filename, refresh)

def saveini(self, t_widget, filename):
f = open(filename, 'w')
f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline
f.close()
with open(filename, 'w') as f:
f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline

# Rebuild ts-warp_pf.conf when saving the INI-file
with open(fwfile, "w") as outfw:
subprocess.run(['./ts-warp_autofw.sh', prefix], stdout=outfw)

def pauselog(self, btn, txt, filename):
if self.pause:
self.pause = False
if self.pause_log:
self.pause_log = False
btn['text'] = '■' # Pause log auto-refresh
self.readfile(txt, filename, refresh=True)
else:
self.pause = True
self.pause_log = True
btn['text'] = '↭' # Enable auto-refresh

def pauseact(self, btn, tree, filename):
if self.pause_act:
self.pause_act = False
btn['text'] = '■' # Pause act auto-refresh
self.read_file_tree(tree, filename, refresh=True)
else:
self.pause_act = True
btn['text'] = '▶' # Enable auto-refresh
self.read_file_tree(tree, filename, refresh=False)

def status(self, lbl, btn, pidfile):
pf = None
try:
Expand Down Expand Up @@ -298,31 +350,43 @@ def get_password(self):
fwfile = prefix + 'etc/ts-warp_pf.conf'
logfile = prefix + 'var/log/ts-warp.log'
pidfile = prefix + 'var/run/ts-warp.pid'
actfile = prefix + 'var/spool/ts-warp/ts-warp.act'

if 'GUI-WARP' in ini.sections():
runcmd = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['runcmd']
inifile = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['inifile']
fwfile = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['fwfile']
logfile = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['logfile']
pidfile = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['pidfile']
actfile = ini['GUI-WARP']['prefix'] + ini['GUI-WARP']['actfile']

if not os.path.exists(inifile): # Failback to the home directory and reset paths
prefix = home_prefix
inifile = prefix + 'etc/ts-warp.ini'
fwfile = prefix + 'etc/ts-warp_pf.conf'
logfile = prefix + 'var/log/ts-warp.log'
pidfile = prefix + 'var/run/ts-warp.pid'
actfile = prefix + 'var/spool/ts-warp/ts-warp.act'

if not os.path.exists(prefix): # Create ts-warp dir + subdirs in home
os.makedirs(prefix + 'etc/')
os.makedirs(prefix + 'var/log/')
os.makedirs(prefix + 'var/run/')
os.makedirs(prefix + 'var/spool/ts-warp/')
shutil.copyfile('./ts-warp.ini', inifile)
os.chmod(inifile, 0o600)

if not os.path.exists(prefix + 'etc/'):
os.makedirs(prefix + 'etc/')
if not os.path.exists(fwfile):
with open(fwfile, "w") as outfw:
subprocess.run(['./ts-warp_autofw.sh', prefix], stdout=outfw)
if not os.path.exists(logfile):
os.makedirs(prefix + 'var/log/')
open(logfile, 'a').close()
if not os.path.exists(prefix + 'var/run/'):
os.makedirs(prefix + 'var/run/')
if not os.path.exists(prefix + 'var/spool/ts-warp/'):
os.makedirs(prefix + 'var/spool/ts-warp/')

app = App(runcmd=runcmd, inifile=inifile, fwfile=fwfile, logfile=logfile, pidfile=pidfile)

0 comments on commit 3c81afe

Please sign in to comment.