diff --git a/CHANGELOG.md b/CHANGELOG.md index 85db81d..cceb346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG -* **2024.09.30 Current** +* **2024.11.08 Current** + * `gui-warp.py`: Minor changes about log-file size and FW-file selection under `Linux` * `ts-warp.c`: Null-pointer dereference in `PIDS` table processing fixed * `ts-warp.c`: `ACT` reporting `[SECTIONS]` * `inifile.c`: Correct usage of multiple links of a proxy-chain diff --git a/gui/gui-warp.py.in b/gui/gui-warp.py.in index 358d338..269cd28 100644 --- a/gui/gui-warp.py.in +++ b/gui/gui-warp.py.in @@ -62,7 +62,7 @@ class App: self.password = '' - self.version = 'v1.0.25' + self.version = 'v1.0.26' self.width = width self.height = height @@ -147,7 +147,8 @@ class App: 'tsw01:' + subprocess.Popen([prefix + '/bin/ts-pass', self.tswhash.get().encode()], stdout=subprocess.PIPE).stdout.read().decode().strip('\n\r')) - ttk.Label(frm_tab_ini_top, text='Save changes:').grid(column=2, row=0, sticky=tk.E) + sch = ttk.Label(frm_tab_ini_top, text='Save configuration:') + sch.grid(column=2, row=0, sticky=tk.E) btn_save_ini = ttk.Button(frm_tab_ini_top, width=self._btnw, text='▲') btn_save_ini.grid(column=3, row=0, sticky=tk.W, padx=self._padx, pady=self._pady) btn_save_ini['command'] = lambda: self.savefile(ini_txt, inifile) @@ -358,11 +359,11 @@ It is a free and open-source software, but if you want to support it, please do' """ t_widget.config(state='normal') - with open(filename, 'r', encoding='utf-8') as f: - sz = os.path.getsize(filename) - if sz > self.log_size: + sz = os.path.getsize(filename) + if sz > self.log_size: + with open(filename, 'r', encoding='utf-8') as f: + f.seek(self.log_size) self.log_size = sz - t_widget.delete(1.0, tk.END) t_widget.insert(tk.END, ''.join(f.readlines())) t_widget.see(tk.END) @@ -536,7 +537,7 @@ if __name__ == "__main__": runcmd = prefix + '/etc/ts-warp.sh' inifile = prefix + '/etc/ts-warp.ini' - fwfile = prefix + ('/etc/ts-warp_pf.conf' if platform.system() != 'Linux' else '/etc/ts-warp_nftables.sh') + fwfile = prefix + ('/etc/ts-warp_pf.conf' if platform.system() != 'Linux' else '/etc/ts-warp_nftables.sh' if os.path.isfile('/etc/ts-warp_nftables.sh') else '/etc/ts-warp_iptables.sh') logfile = prefix + '/var/log/ts-warp.log' pidfile = prefix + '/var/run/ts-warp.pid' actfile = prefix + '/var/spool/ts-warp/ts-warp.act' diff --git a/gui/ports/macOS/gui-warp.ini b/gui/ports/macOS/gui-warp.ini index 6de251f..c509869 100644 --- a/gui/ports/macOS/gui-warp.ini +++ b/gui/ports/macOS/gui-warp.ini @@ -10,6 +10,7 @@ prefix = ~/ts-warp inifile = /etc/ts-warp.ini # fwfile = /etc/ts-warp_pf.conf # This should be autoconfigured logfile = /var/log/ts-warp.log +logfile_size = 3145728 pidfile = /var/run/ts-warp.pid actfile = /var/spool/ts-warp/ts-warp.act daemon_options = diff --git a/gui/ports/macOS/gui-warp.py b/gui/ports/macOS/gui-warp.py index 01c244d..2c0ecdc 100644 --- a/gui/ports/macOS/gui-warp.py +++ b/gui/ports/macOS/gui-warp.py @@ -55,12 +55,13 @@ def __init__(self, width=800, height=560, daemon_options="", fwfile='/usr/local/etc/ts-warp_pf.conf', logfile='/usr/local/var/log/ts-warp.log', + logfile_size=3145728, pidfile='/usr/local/var/run/ts-warp.pid', url_new_vesrsion=''): self.password = '' - self.version = 'v1.0.32-mac' + self.version = 'v1.0.33-mac' self.width = width self.height = height @@ -134,11 +135,11 @@ def __init__(self, width=800, height=560, 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_log = False - btn_pause['command'] = lambda: self.pauselog(btn_pause, log_txt, logfile) + btn_pause['command'] = lambda: self.pauselog(btn_pause, log_txt, logfile, logfile_size) log_txt = tk.Text(tab_log, highlightthickness=0, state='disabled') log_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW) - tab_log.bind("", self.readfile_log(log_txt, logfile, refresh=True)) + tab_log.bind("", self.readfile_log(log_txt, logfile, logfile_size, refresh=True)) scroll_log = ttk.Scrollbar(tab_log, orient=tk.VERTICAL) scroll_log.grid(column=2, row=1, sticky=tk.NSEW) @@ -166,7 +167,8 @@ def __init__(self, width=800, height=560, 'tsw01:' + subprocess.Popen(['./ts-pass', self.tswhash.get().encode()], stdout=subprocess.PIPE).stdout.read().decode().strip('\n\r')) - ttk.Label(frm_tab_ini_top, text='Save changes:').grid(column=2, row=0, sticky=tk.E) + sch = ttk.Label(frm_tab_ini_top, text='Save configuration:', foreground='green') + sch.grid(column=2, row=0, sticky=tk.E) btn_save_ini = ttk.Button(frm_tab_ini_top, width=self._btnw, text='▲') btn_save_ini.grid(column=3, row=0, sticky=tk.W, padx=self._padx, pady=self._pady) btn_save_ini['command'] = lambda: self.saveini(ini_txt, inifile) @@ -174,6 +176,7 @@ def __init__(self, width=800, height=560, ini_txt = tk.Text(tab_ini, highlightthickness=0) ini_txt.grid(column=0, row=1, columnspan=2, sticky=tk.NSEW) tab_ini.bind("", self.readfile_ini(ini_txt, inifile)) +# ini_txt.bind('<>', lambda: sch.config(foreground='red') if ini_txt.edit_modified() == 1 else sch.config(foreground='green')) scroll_ini = ttk.Scrollbar(tab_ini, orient=tk.VERTICAL) scroll_ini.grid(column=2, row=1, sticky=tk.NSEW) @@ -331,25 +334,31 @@ def readfile_ini(self, t_widget, filename): t_widget.insert(tk.END, ''.join(f.readlines())) t_widget.see(tk.END) + # t_widget.edit_modified(False) + # ---------------------------------------------------------------------------------------------------------------- # - def readfile_log(self, t_widget, filename, refresh=False): + def readfile_log(self, t_widget, filename, logfile_size, refresh=False): """ Read contents of the LOG-file """ t_widget.config(state='normal') - with open(filename, 'r', encoding='utf-8') as f: - sz = os.path.getsize(filename) - if sz > self.log_size: - self.log_size = sz - t_widget.delete(1.0, tk.END) - t_widget.insert(tk.END, ''.join(f.readlines())) - t_widget.see(tk.END) + sz = os.path.getsize(filename) + if sz > self.log_size: + with open(filename, 'r', encoding='utf-8') as f: + if sz > logfile_size: + f.truncate(0) + t_widget.delete(1.0, tk.END) + else: + f.seek(self.log_size) + self.log_size = sz + t_widget.insert(tk.END, ''.join(f.readlines())) + t_widget.see(tk.END) if refresh: t_widget.config(state='disabled') if not self.pause_log: - self.root.after(500, self.readfile_log, t_widget, filename, refresh) + self.root.after(500, self.readfile_log, t_widget, filename, logfile_size, refresh) # ---------------------------------------------------------------------------------------------------------------- # def saveini(self, t_widget, filename): @@ -363,13 +372,15 @@ def saveini(self, t_widget, filename): f.write(t_widget.get('1.0', tk.END)[:-1]) # Strip extra newline os.chown(filename, uid, gid) + # t_widget.edit_modified(False) + # Rebuild ts-warp_pf.conf when saving the INI-file with open(fwfile, 'w', encoding='utf8') as outfw: subprocess.run(['./ts-warp_autofw.sh', prefix], stdout=outfw, check=False) os.chown(fwfile, uid, gid) # ---------------------------------------------------------------------------------------------------------------- # - def pauselog(self, btn, txt, filename): + def pauselog(self, btn, txt, filename, logfile_size): """ Pause LOG """ @@ -377,7 +388,7 @@ def pauselog(self, btn, txt, filename): if self.pause_log: self.pause_log = False btn['text'] = '■' # Pause log auto-refresh - self.readfile_log(txt, filename, refresh=True) + self.readfile_log(txt, filename, logfile_size, refresh=True) else: self.pause_log = True btn['text'] = '↭' # Enable auto-refresh @@ -528,6 +539,7 @@ def dedupch(s, c='/'): inifile = prefix + 'etc/ts-warp.ini' fwfile = prefix + 'etc/ts-warp_pf.conf' logfile = prefix + 'var/log/ts-warp.log' + logfile_size = 3145728 pidfile = prefix + 'var/run/ts-warp.pid' actfile = prefix + 'var/spool/ts-warp/ts-warp.act' daemon_options = '' @@ -547,6 +559,8 @@ def dedupch(s, c='/'): fwfile = '/' + dedupch(prefix + gui_ini['GUI-WARP']['fwfile']) if 'logfile' in gui_ini['GUI-WARP'].keys(): logfile = '/' + dedupch(prefix + gui_ini['GUI-WARP']['logfile']) + if 'logfile_size' in gui_ini['GUI-WARP'].keys(): + logfile_size = int(gui_ini['GUI-WARP']['logfile_size']) if 'pidfile' in gui_ini['GUI-WARP'].keys(): pidfile = '/' + dedupch(prefix + gui_ini['GUI-WARP']['pidfile']) if 'actfile' in gui_ini['GUI-WARP'].keys():