-
Notifications
You must be signed in to change notification settings - Fork 13
/
d-rats_repeater.py
executable file
·1362 lines (1104 loc) · 42.3 KB
/
d-rats_repeater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# File: d_rats_repeater.py
'''D-Rats Repeater.'''
# pylint wants only 1000 lines per module.
# pylint does not like the module name, wants "snake_case" compliance.
# pylint: disable=too-many-lines, invalid-name
#
# Copyright 2008 Dan Smith <[email protected]>
# Python3 conversion Copyright 2022-2024 John Malmberg <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
from __future__ import print_function
import argparse
import ast
import logging
import os
import threading
import time
import socket
import sys
import configparser
# This makes pylance happy with out overriding settings
# from the invoker of the class
if not '_' in locals():
import gettext
_ = gettext.gettext
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import GObject
# Make sure no one tries to run this with privileges.
try:
if os.geteuid() == 0:
print("Refusing to run with unneeded privileges!")
sys.exit(1)
except AttributeError:
pass
from d_rats.version import __version__
from d_rats.version import DRATS_VERSION
from d_rats.dplatform import Platform
from d_rats import transport
from d_rats import comm
from d_rats.listwidget import ListWidget
from d_rats.miscwidgets import make_choice
from d_rats.configui.dratsradiopanel import prompt_for_port
gettext.install("D-RATS")
IN = 0
OUT = 1
PEEK = 2
class CallInfo:
'''
Call Information.
:param call: Call sign
:type call: str
:param call_transport: Transport call was heard on
:type call_transport: :class:`Transporter`
'''
def __init__(self, call, call_transport):
self.__call = call
self.just_heard(call_transport)
def get_call(self):
'''
Get call.
:returns: Call sign
:rtype: str
'''
return self.__call
def just_heard(self, heard_transport):
'''
Just heard.
:param heard_transport: Transport that had something heard
:type heard_transport: :class:`Transporter`
'''
self.__heard = time.time()
self.__transport = heard_transport
def last_heard(self):
'''
Last heard.
:returns: Time for last heard station
:type float:
'''
return time.time() - self.__heard
def last_transport(self):
'''
Last transport.
:returns: Last transport heard
:rtype: :class:`Transporter`
'''
return self.__transport
def call_in_list(call_info, call):
'''
Call in list?
:param call_info: list of callsign information objects
:type call_info: list[:class:`CallInfo`]
:param call: Call sign to lookup
:type call: str
:returns true: If call sign is found
:rtype: bool
'''
for info in call_info:
if call == info.get_call():
return True
return False
# pylint wants only 7 instance attributes per class
# pylint: disable=too-many-instance-attributes
class Repeater:
'''
Repeater.
:param ident: Identity string, Default 'D-RATS Network Proxy'
:type ident: str
:param require_auth: True is authorization required
:type require_auth: bool
:param trust_local: True if local should be trusted
:type trust_local: bool
:param gps_okay_ports: List of GPS active TCP/IP ports, default None
:type gps_ok_ports: list
'''
logger = logging.getLogger("Repeater")
def __init__(self, ident="D-RATS Network Proxy",
require_auth=False, trust_local=False, gps_okay_ports=None):
self.paths = []
self.calls = {}
self.thread = None
self.enabled = True
self.socket = None
self.repeat_thread = None
self.ident = ident
self.require_auth = require_auth
self.trust_local = trust_local
self.condition = threading.Condition()
self.gps_socket = None
self.gps_sockets = []
self.gps_okay_ports = []
if gps_okay_ports:
self.gps_okay_ports = gps_okay_ports
# Forget port for a station after 10 minutes
self.__call_timeout = 600
def __should_repeat_gps(self, gps_transport, _frame):
if not self.gps_okay_ports:
return True
return gps_transport.name in self.gps_okay_ports
# pylint wants a max of 12 branches per function or method
# pylint: disable=too-many-branches
def __repeat(self, rpt_transport, frame):
if frame.d_station == "!":
return
gps_start = '$'
if not isinstance(frame.data, str):
gps_start = b'$'
if frame.s_station == frame.d_station == "CQCQCQ" and \
frame.session == 1 and \
frame.data.startswith(gps_start) and \
self.__should_repeat_gps(rpt_transport, frame):
for sock in self.gps_sockets:
sock.send(frame.data)
src_info = self.calls.get(frame.s_station, None)
if src_info is None and frame.s_station != "CQCQCQ":
self.logger.info("__repeat: Adding new station %s to port %s",
frame.s_station, rpt_transport)
self.calls[frame.s_station] = CallInfo(frame.s_station,
rpt_transport)
elif src_info:
if src_info.last_transport() != rpt_transport:
self.logger.info("__repeat: Station %s moved to port %s",
frame.s_station, rpt_transport)
src_info.just_heard(rpt_transport)
dst_info = self.calls.get(frame.d_station, None)
if dst_info is not None:
if not dst_info.last_transport().enabled:
self.logger.info("__repeat: Last transport for %s is dead",
frame.d_station)
elif dst_info.last_heard() < self.__call_timeout:
self.logger.info("__repeat: Delivering frame to %s at %s",
frame.d_station, dst_info.last_transport())
dst_info.last_transport().send_frame(frame.get_copy())
return
self.logger.info("__repeat: Last port for %s was %i sec"
" ago (>%i sec)",
frame.d_station,
dst_info.last_heard(),
self.__call_timeout)
self.logger.info("__repeat: Repeating frame to %s on all ports",
frame.d_station)
for path in self.paths[:]:
if path == rpt_transport:
continue
if not path.enabled:
self.logger.info("__repeat: Found a stale path, removing...")
path.disable()
self.paths.remove(path)
else:
path.send_frame(frame.get_copy())
def add_new_transport(self, new_transport):
'''
Add new transport.
:param new_transport: Transport to add
:type new_transport: :class:`Transporter`
'''
self.paths.append(new_transport)
def handler(frame):
self.condition.acquire()
try:
self.__repeat(new_transport, frame)
# pylint: disable=broad-except
except Exception:
self.logger.info("add_new_transport: Generic Exception",
exc_info=True)
self.condition.release()
new_transport.inhandler = handler
def auth_exchange(self, pipe):
'''
Authorization Exchange.
:param pipe: socket object
:type pipe: socket
:returns: Data for exchange
:rtype: tuple[str, str]
'''
username = password = None
count = 0
def readline(sock):
data = ""
while "\r\n" not in data:
try:
data_part = sock.read(32)
except socket.timeout:
continue
if data_part == b"":
break
data += data_part.decode('utf-8', 'replace')
return data.strip()
while (not username or not password) and count < 3:
line = readline(pipe)
if not line:
continue
try:
cmd, value = line.split(" ", 1)
except ValueError:
pipe.write(b"501 Invalid Syntax\r\n")
break
cmd = cmd.upper()
if cmd == "USER" and not username and not password:
username = value
elif cmd == "PASS" and username and not password:
password = value
else:
pipe.write(b"201 Protocol violation\r\n")
break
if username and not password:
out_data = b"102 %s okay\r\n" % cmd.encode('utf-8', 'replace')
pipe.write(out_data)
if not username or not password:
self.logger.info("auth_exchange: Negotiation failed with client")
return username, password
def auth_user(self, pipe):
'''
Authorize user.
:param pipe: Pipe object
:type pipe: socket
:return: True if authorized
:rtype: bool
'''
# pylint: disable=protected-access
host, _port = pipe._socket.getpeername()
if not self.require_auth:
pipe.write(b"100 Authentication not required\r\n")
return True
if self.trust_local and host == "127.0.0.1":
pipe.write(b"100 Authentication not required for localhost\r\n")
return True
auth_fname = Platform.get_platform().config_file("users.txt")
try:
auth = open(auth_fname)
lines = auth.readlines()
auth.close()
except (NameError, FileNotFoundError) as err:
self.logger.info("auth_user: Failed to open %s: %s",
auth_fname, err)
pipe.write(b"101 Authorization required\r\n")
username, password = self.auth_exchange(pipe)
lno = 1
for line in lines:
line = line.strip()
try:
user, passwd = line.split(" ", 1)
user = user.upper()
except ValueError:
self.logger.info("auth_user: Failed to parse "
"line %i in users.txt: %s",
lno, line)
continue
if user == username and passwd == password:
self.logger.info("Authorized user %s", user)
pipe.write(b"200 Authorized\r\n")
return True
self.logger.info("auth_user: User %s failed to authenticate", username)
pipe.write(b"500 Not authorized\r\n")
return False
@staticmethod
def address_to_string(address):
'''
Address to string.
Multiple ways that a address can be converted to a string.
:param address: an Address Family
:type address: string or tuple
:returns: A string representing the address
:rtype: str
'''
# https://docs.python.org/3/library/socket.html
if isinstance(address, str):
return address
ret_str = ''
for part in address:
if ret_str:
ret_str += ','
ret_str += str(part)
return ret_str
def accept_new(self):
'''Accept new.'''
if not self.socket:
return
try:
(csocket, addr) = self.socket.accept()
except BlockingIOError:
return
addr_str = self.address_to_string(addr)
self.logger.info("accept_new: Accepted new client %s", addr_str)
path = comm.SocketDataPath(csocket)
tport = transport.Transporter(path,
authfn=self.auth_user,
warmup_timeout=0)
self.add_new_transport(tport)
def accept_new_gps(self):
'''Accept new GPS.'''
if not self.gps_socket:
return
try:
(csocket, addr) = self.gps_socket.accept()
except BlockingIOError:
return
addr_str = self.address_to_string(addr)
self.logger.info("accept_new_gps: Accepted new GPS client %s", addr_str)
self.gps_sockets.append(csocket)
@staticmethod
def listen_on(port):
'''
Listen on.
:param port: TCP/IP port number
:type port: int
:returns: socket object
:rtype: socket
'''
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setblocking(0)
sock.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR,
1)
sock.bind(('0.0.0.0', port))
sock.listen(0)
return sock
def _repeat(self):
while self.enabled:
self.condition.acquire()
self.accept_new()
self.accept_new_gps()
self.condition.release()
time.sleep(0.5)
self.logger.info("_repeat: Repeater thread ended")
def repeat(self):
'''Repeat.'''
self.repeat_thread = threading.Thread(target=self._repeat)
self.repeat_thread.daemon = True
self.repeat_thread.start()
def stop(self):
'''Stop.'''
self.enabled = False
self.condition.acquire()
self.condition.notify()
self.condition.release()
if self.repeat_thread:
self.logger.info("stop: Stopping repeater")
self.repeat_thread.join()
for path in self.paths:
self.logger.info("stop: Stopping")
path.disable()
if self.socket:
self.socket.close()
class RepeaterUI:
'''Repeater UI.'''
logger = logging.getLogger("RepeaterUI")
def __init__(self):
self.repeater = None
self.tap = None
self.tick = 0
self.platform = Platform.get_platform()
self.config = self.load_config()
self.logger.info("Version: %s", DRATS_VERSION)
def load_config(self):
'''
Load configuration.
:returns: Config object
:rtype: :class:`DratsConfig`
'''
self.config_fn = self.platform.config_file("repeater.config")
config = configparser.ConfigParser()
config.add_section("settings")
config.set("settings", "devices", "[]")
config.set("settings", "acceptnet", "True")
config.set("settings", "netport", "9000")
config.set("settings", "id", "NotSet")
config.set("settings", "idfreq", "30")
config.set("settings", "require_auth", "False")
config.set("settings", "trust_local", "True")
config.set("settings", "gpsport", "9500")
config.add_section("tweaks")
config.set("tweaks", "allow_gps", "")
config.read(self.config_fn)
return config
# pylint wants a max of 15 local variables
# pylint wants a max of 50 statements
# pylint wants a max of 12 branches
# pylint: disable=too-many-locals, too-many-statements, too-many-branches
def add_outgoing_paths(self, ident, paths):
'''
Add outgoing paths.
:param ident: Path id
:type ident: str
:param path: Paths data
:type path: list[tuple]
'''
require_auth = self.config.get("settings", "require_auth") == "True"
trust_local = self.config.get("settings", "trust_local") == "True"
gps_okay_ports = self.config.get("tweaks", "allow_gps").split(",")
self.logger.info("add_outgoing_path: Repeater id is %s", ident)
self.repeater = Repeater(ident, require_auth,
trust_local, gps_okay_ports)
for dev, param in paths:
timeout = 0
if dev.startswith("net:"):
try:
_net, host, port = dev.split(":", 2)
port = int(port)
except ValueError as err:
self.logger.info("add_outgoing_paths: "
"Invalid net string: %s (%s)",
dev, err)
continue
self.logger.info("add_outgoing_paths: Socket %s %i (%s)",
host, port, param)
if param:
if ident == 'MYCALL':
self.logger.info("add_outgoing_paths: "
"invalid callsign %s for %s",
ident, dev)
continue
path = comm.SocketDataPath((host, port, ident, param))
else:
path = comm.SocketDataPath((host, port))
elif dev.startswith("tnc-ax25:"):
if ident == 'MYCALL':
self.logger.info("add_outgoing_paths: "
"invalid callsign %s for %s",
ident, dev)
continue
_tnc, radio_port, tncport, digi_path = port.split(":")
digi_path = digi_path.replace(";", ",")
radio_port = "%s:%s" % (radio_port, tncport)
new_dev = dev.replace('tnc-ax25:', "")
param_int = int(param)
self.logger.info("add_outgoing_paths: TNC-AX25 %s %i",
new_dev, param_int)
path = comm.TNCAX25DataPath((new_dev, param_int,
ident, digi_path))
elif dev.startswith("tnc:"):
try:
_tnc, port, device = dev.split(":", 2)
device = int(device)
except ValueError as err:
self.logger.info("add_outgoing_paths: "
"Invalid tnc string: %s (%s)",
dev, err)
continue
new_dev = dev.replace('tnc:', "")
param_int = int(param)
self.logger.info("add_outgoing_paths: TNC %s %i",
new_dev, param_int)
path = comm.TNCDataPath((new_dev, param_int))
elif dev.startswith("dongle:"):
if ident == 'MYCALL':
self.logger.info("add_outgoing_paths: "
"invalid callsign %s for %s",
ident, dev)
continue
self.logger.info("add_outgoing_paths: Dongle %s",
new_dev)
path = comm.SocketDataPath(("127.0.0.1", 20003, ident, None))
elif dev.startswith("agwpe:"):
new_dev = dev.replace("agwpe:", "")
self.logger.info("add_outgoing_paths: AGWPE %s",
new_dev)
path = comm.AGWDataPath(new_dev, 0.5)
else:
param_int = int(param)
self.logger.info("add_outgoing_paths: Serial: %s %i",
dev, param_int)
path = comm.SerialDataPath((dev, param_int))
timeout = 3
path.connect()
tport = transport.Transporter(path, warmup_timeout=timeout,
name=dev)
self.repeater.add_new_transport(tport)
# pylint wants a max of 7 instance attributes
# pylint: disable=too-many-instance-attributes
class RepeaterGUI(RepeaterUI):
'''Repeater GUI.'''
logger = logging.getLogger("RepeaterGUI")
def __init__(self):
RepeaterUI.__init__(self)
self.window = Gtk.Window()
# self.window = Gtk.Window(Gtk.WINDOW_TOPLEVEL)
self.window.set_default_size(450, 380)
self.window.connect("delete_event", self.ev_delete)
self.window.connect("destroy", self.sig_destroy)
self.window.set_title("D-RATS Repeater Proxy")
self.traffic_buffer = None
self.traffic_view = None
self.conn_list = None
self.trust_local = None
self.req_auth = None
self.id_freq = None
self.entry_id = None
self.entry_port = None
self.entry_gpsport = None
self.net_enabled = None
self.dev_list = None
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5)
self.tabs = Gtk.Notebook()
self.tabs.append_page(self.make_settings(), Gtk.Label.new("Settings"))
# pylint: disable=fixme
# FIXME: later
# self.tabs.append_page(self.make_monitor(), Gtk.Label.new("Monitor"))
self.tabs.show()
vbox.pack_start(self.tabs, 1, 1, 1)
vbox.pack_start(self.make_bottom_buttons(), 0, 0, 0)
vbox.show()
self.window.add(vbox)
self.window.show()
# GLib.timeout_add(1000, self.update)
try:
if self.config.get("settings", "state") == "True":
self.button_on(None)
except (configparser.NoOptionError, OSError):
self.logger.info("__init__: Starting repeater error.",
exc_info=True)
def add_serial(self, _widget):
'''
Add serial port button click handler.
:param _widget: Button widget, unused
:type _widget: :class:`Gtk.Button`
'''
_name, portspec, param = prompt_for_port(None, pname=False)
if portspec is None:
return
self.dev_list.add_item(portspec, param)
def save_config(self, config):
'''
Save config.
:param config: Config object
:type config: :class:`DratsConfig`
'''
self.sync_config()
file_handle = open(self.config_fn, "w")
config.write(file_handle)
file_handle.close()
def sig_destroy(self, _widget, _data=None):
'''
Destroy Event handler.
Signals that the widget is being destroyed.
:param _widget: :class:`Gtk.Window`
:param _data: Unused, default None
'''
self.button_off(None, False)
# Documentation states this signal should not be used
# for saving the widget state.
self.save_config(self.config)
Gtk.main_quit()
def ev_delete(self, _widget, _event):
'''
Delete Event handler.
This event is signaled by a top level window being closed.
:param _widget: Widget being deleted, Unused
:type _widget: :class:`Gtk.Window`
:param _event: Event signaled, Unused
:type _event: :class:`Gtk.Event`
:returns: True to stop other handlers from handling event.
:rtype bool
'''
self.button_off(None, False)
self.save_config(self.config)
if self.repeater:
self.repeater.stop()
Gtk.main_quit()
return False
def make_side_buttons(self):
'''
Make side buttons.
:returns: Gtk.Box object with buttons
:rtype: :class:`Gtk.Box`
'''
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 2)
but_add = Gtk.Button.new_with_label("Add")
but_add.connect("clicked", self.add_serial)
but_add.set_size_request(75, 30)
but_add.show()
vbox.pack_start(but_add, 0, 0, 0)
but_remove = Gtk.Button.new_with_label("Remove")
but_remove.set_size_request(75, 30)
but_remove.connect("clicked", self.button_remove)
but_remove.show()
vbox.pack_start(but_remove, 0, 0, 0)
vbox.show()
return vbox
def load_devices(self):
'''Load devices.'''
try:
devices = ast.literal_eval(self.config.get("settings", "devices"))
for device, radio in devices:
self.dev_list.add_item(device, radio)
except (ValueError, configparser.NoOptionError) as err:
self.logger.info("load_devices: Unable to load devices %s", err)
def make_devices(self):
'''
Make Devices.
:returns: Gtk.Frame object
:rtype: :class:`Gtk.Frame`
'''
frame = Gtk.Frame.new("Paths")
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 2)
frame.add(vbox)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
self.dev_list = ListWidget([(GObject.TYPE_STRING, "Device"),
(GObject.TYPE_STRING, "Param")])
self.dev_list.show()
self.load_devices()
# sw = Gtk.ScrolledWindow()
list_box = Gtk.ListBox()
list_box.add(self.dev_list)
list_box.show()
hbox.pack_start(list_box, 1, 1, 1)
hbox.pack_start(self.make_side_buttons(), 0, 0, 0)
hbox.show()
vbox.pack_start(hbox, 1, 1, 1)
vbox.show()
frame.show()
return frame
def make_network(self):
'''
Make Network.
:returns: Gtk.Frame object
:rtype: :class:`Gtk.Frame`
'''
frame = Gtk.Frame.new("Network")
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 2)
frame.add(vbox)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
self.net_enabled = Gtk.CheckButton.new_with_label(
"Accept incoming connections")
try:
accept = self.config.getboolean("settings", "acceptnet")
except configparser.NoOptionError:
accept = True
self.net_enabled.set_active(accept)
self.net_enabled.show()
hbox.pack_start(self.net_enabled, 0, 0, 0)
self.entry_port = Gtk.Entry()
try:
port = self.config.get("settings", "netport")
except configparser.NoOptionError:
port = "9000"
self.entry_gpsport = Gtk.Entry()
try:
gpsport = self.config.get("settings", "gpsport")
except configparser.NoOptionError:
port = "9500"
self.entry_gpsport.set_text(gpsport)
self.entry_gpsport.set_size_request(100, -1)
self.entry_gpsport.show()
hbox.pack_end(self.entry_gpsport, 0, 0, 0)
lab = Gtk.Label.new("GPS Port:")
lab.show()
hbox.pack_end(lab, 0, 0, 0)
self.entry_port.set_text(port)
self.entry_port.set_size_request(100, -1)
self.entry_port.show()
hbox.pack_end(self.entry_port, 0, 0, 0)
lab = Gtk.Label.new("Port:")
lab.show()
hbox.pack_end(lab, 0, 0, 0)
hbox.show()
vbox.pack_start(hbox, 0, 0, 0)
vbox.show()
frame.show()
return frame
def make_bottom_buttons(self):
'''
Make bottom buttons.
:returns: Gtk.Box object with buttons
:rtype: :class:`Gtk.Box`
'''
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
self.but_on = Gtk.Button.new_with_label("On")
self.but_on.set_size_request(75, 30)
self.but_on.connect("clicked", self.button_on)
self.but_on.show()
hbox.pack_start(self.but_on, 0, 0, 0)
self.but_off = Gtk.Button.new_with_label("Off")
self.but_off.set_size_request(75, 30)
self.but_off.connect("clicked", self.button_off)
self.but_off.set_sensitive(False)
self.but_off.show()
hbox.pack_start(self.but_off, 0, 0, 0)
hbox.show()
return hbox
def make_id(self):
'''
Make ID for Repeater Callsign.
:returns: Gtk.Frame object
:rtype: :class:`Gtk.Frame`
'''
frame = Gtk.Frame.new("Repeater Callsign")
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 2)
self.entry_id = Gtk.Entry()
try:
deftxt = self.config.get("settings", "id")
except configparser.NoOptionError:
self.logger.info("make_id 'id' broad-except",
exc_info=True)
deftxt = "MYCALL"
self.entry_id.set_text(deftxt)
self.entry_id.set_max_length(8)
self.entry_id.show()
hbox.pack_start(self.entry_id, 1, 1, 1)
try:
idfreq = self.config.get("settings", "idfreq")
except configparser.NoOptionError:
idfreq = "30"
self.id_freq = make_choice(["Never", "30", "60", "120"],
True,
idfreq)
self.id_freq.set_size_request(75, -1)
# self.id_freq.show()
hbox.pack_start(self.id_freq, 0, 0, 0)
hbox.show()
frame.add(hbox)
frame.show()
return frame
def make_auth(self):
'''
Make authentication.
:returns: Gtk.Frame object
:rtype: :class:`Gtk.Frame`
'''
frame = Gtk.Frame.new("Authentication")
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 20)
def toggle_option(check_button, option):
'''
Toggle Option CheckButton toggled handler.
:param check_button: Button widget signaled
:type check_button: :class:`Gtk.CheckButton`
:param option: option name
:type option: str
'''
self.config.set("settings", option,
str(check_button.get_active()))
self.req_auth = Gtk.CheckButton.new_with_label("Require Authentication")
self.req_auth.connect("toggled", toggle_option, "require_auth")
self.req_auth.show()
self.req_auth.set_active(self.config.getboolean("settings",
"require_auth"))
hbox.pack_start(self.req_auth, 0, 0, 0)
self.trust_local = Gtk.CheckButton.new_with_label("Trust localhost")
self.trust_local.connect("toggled", toggle_option, "trust_local")
self.trust_local.show()
self.trust_local.set_active(self.config.getboolean("settings",
"trust_local"))
hbox.pack_start(self.trust_local, 0, 0, 0)
def clicked_edit_users(_button):
'''
Clicked Edit Users Button handler.
:param _button: Button Widget signaled, unused
:type _button: :class:`Gtk.Button`
'''
self.platform.open_text_file(self.platform.config_file("users.txt"))
edit_users = Gtk.Button.new_with_label("Edit Users")
edit_users.connect("clicked", clicked_edit_users)
edit_users.show()
edit_users.set_size_request(75, 30)
hbox.pack_end(edit_users, 0, 0, 0)
hbox.show()
frame.add(hbox)
frame.show()
return frame
def make_settings(self):
'''
Make settings display.
:returns: Gtk.Box with settings
:rtype: :class:`Gtk.Box`