From 27389bdb23ed8ed1d38147a25298f47dbca68952 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Fri, 29 Sep 2023 19:18:57 -0500 Subject: [PATCH] Advanced settings implemented. --- N2NCMakeLists.txt | 2 + build-godot.sh | 2 + build-n2n.sh | 2 + cmake/x86_64-linux-gnu.cmake | 2 + cmake/x86_64-w64-mingw32.cmake | 2 + hamncheese/Scenes/settings.tscn | 121 +++++++++++++++++++++++++++----- hamncheese/Scripts/about.gd | 2 + hamncheese/Scripts/dialog.gd | 2 + hamncheese/Scripts/edge.gd | 38 ++++++++-- hamncheese/Scripts/main.gd | 25 +++---- hamncheese/Scripts/manual.gd | 2 + hamncheese/Scripts/network.gd | 2 + hamncheese/Scripts/peers.gd | 8 ++- hamncheese/Scripts/process.gd | 19 ++--- hamncheese/Scripts/settings.gd | 73 +++++++++++++++++-- hamncheese/Scripts/util.gd | 2 + modules/embedded/SCsub | 2 + modules/embedded/config.py | 2 + prereqs.sh | 2 + 19 files changed, 264 insertions(+), 46 deletions(-) diff --git a/N2NCMakeLists.txt b/N2NCMakeLists.txt index cc1f9d4..84684fa 100644 --- a/N2NCMakeLists.txt +++ b/N2NCMakeLists.txt @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# cmake_minimum_required(VERSION 3.22) diff --git a/build-godot.sh b/build-godot.sh index d2252a0..0f27ff8 100755 --- a/build-godot.sh +++ b/build-godot.sh @@ -1,5 +1,6 @@ #!/bin/bash +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -15,6 +16,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# function createEmbeddedBinary() { diff --git a/build-n2n.sh b/build-n2n.sh index 6808d8e..3492001 100755 --- a/build-n2n.sh +++ b/build-n2n.sh @@ -1,5 +1,6 @@ #!/bin/bash +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -15,6 +16,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# # Build n2n. diff --git a/cmake/x86_64-linux-gnu.cmake b/cmake/x86_64-linux-gnu.cmake index 956baea..9f1af5e 100644 --- a/cmake/x86_64-linux-gnu.cmake +++ b/cmake/x86_64-linux-gnu.cmake @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# # Nothing to do on the native platform. diff --git a/cmake/x86_64-w64-mingw32.cmake b/cmake/x86_64-w64-mingw32.cmake index c0ecbb5..d9a40cc 100644 --- a/cmake/x86_64-w64-mingw32.cmake +++ b/cmake/x86_64-w64-mingw32.cmake @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# set(CMAKE_SYSTEM_NAME Windows) diff --git a/hamncheese/Scenes/settings.tscn b/hamncheese/Scenes/settings.tscn index cb9209c..6b56b53 100644 --- a/hamncheese/Scenes/settings.tscn +++ b/hamncheese/Scenes/settings.tscn @@ -15,8 +15,7 @@ script = ExtResource("1_c1h2m") unique_name_in_owner = true title = "Settings" initial_position = 1 -size = Vector2i(500, 450) -visible = false +size = Vector2i(500, 670) unresizable = true [node name="MarginContainer" type="MarginContainer" parent="SettingsWindow"] @@ -107,76 +106,164 @@ horizontal_alignment = 2 [node name="ServerPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/ServerGridContainer"] unique_name_in_owner = true layout_mode = 2 +min_value = 1.0 max_value = 65535.0 page = 100.0 +value = 1.0 rounded = true +alignment = 2 select_all_on_focus = true [node name="MarginContainer2" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] custom_minimum_size = Vector2(0, 20) layout_mode = 2 -[node name="AddressesGridContainer" type="GridContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] +[node name="AdvancedToggleHBoxContainer" type="HBoxContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] +layout_mode = 2 +alignment = 2 + +[node name="AdvancedCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedToggleHBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "Show Advanced Options" + +[node name="AdvancedVBoxContainer" type="VBoxContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="MarginContainer5" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] +custom_minimum_size = Vector2(0, 20) +layout_mode = 2 + +[node name="AddressesGridContainer" type="GridContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] layout_mode = 2 theme_override_constants/h_separation = 10 theme_override_constants/v_separation = 10 columns = 3 -[node name="Label" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="Label" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] layout_mode = 2 text = "IP Address:" horizontal_alignment = 2 -[node name="IPLineEdit" type="LineEdit" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="IPLineEdit" type="LineEdit" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 select_all_on_focus = true -[node name="IPCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="IPCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] unique_name_in_owner = true layout_mode = 2 text = "Automatic" -[node name="Label2" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="Label2" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] layout_mode = 2 text = "MAC Address:" horizontal_alignment = 2 -[node name="MACLineEdit" type="LineEdit" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="MACLineEdit" type="LineEdit" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 select_all_on_focus = true -[node name="MACCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer"] +[node name="MACCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] unique_name_in_owner = true layout_mode = 2 text = "Automatic" -[node name="MarginContainer4" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] +[node name="Label3" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] +layout_mode = 2 +text = "VPN Bind:" +horizontal_alignment = 2 + +[node name="VPNBindLineEdit" type="LineEdit" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +select_all_on_focus = true + +[node name="VPNBindCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "All" +alignment = 2 + +[node name="MarginContainer4" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] custom_minimum_size = Vector2(0, 20) layout_mode = 2 -[node name="GridContainer" type="GridContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] +[node name="PortsGridContainer" type="GridContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +columns = 2 + +[node name="Label" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +layout_mode = 2 +text = "VPN Listening Port: " +horizontal_alignment = 2 + +[node name="ListeningPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 1.0 +max_value = 65535.0 +page = 100.0 +value = 1.0 +alignment = 2 + +[node name="Label2" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +layout_mode = 2 +text = "Management Start Port: " +horizontal_alignment = 2 + +[node name="ManagementPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 1.0 +max_value = 65535.0 +page = 100.0 +value = 1.0 +alignment = 2 + +[node name="Label3" type="Label" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +layout_mode = 2 +text = "Mesh Network Starting Port: " +horizontal_alignment = 2 + +[node name="MeshPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/PortsGridContainer"] +unique_name_in_owner = true +layout_mode = 2 +min_value = 1.0 +max_value = 65535.0 +page = 100.0 +value = 1.0 +alignment = 2 + +[node name="MarginContainer6" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] +custom_minimum_size = Vector2(0, 20) +layout_mode = 2 + +[node name="TogglesGridContainer" type="GridContainer" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer"] layout_mode = 2 theme_override_constants/h_separation = 10 theme_override_constants/v_separation = 10 columns = 2 -[node name="CompressionCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/GridContainer"] +[node name="CompressionCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/TogglesGridContainer"] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 8 text = "Enable Compression" -[node name="AutoStartCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/GridContainer"] +[node name="AutoStartCheckButton" type="CheckButton" parent="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/TogglesGridContainer"] unique_name_in_owner = true layout_mode = 2 text = "Start Network on Startup" [node name="MarginContainer3" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] -custom_minimum_size = Vector2(0, 40) +custom_minimum_size = Vector2(0, 30) layout_mode = 2 [node name="ButtonsHBoxContainer" type="HBoxContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] @@ -189,6 +276,8 @@ layout_mode = 2 text = "Save" [connection signal="close_requested" from="SettingsWindow" to="." method="_on_settings_window_close_requested"] -[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer/IPCheckButton" to="." method="_on_ip_check_button_toggled"] -[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer/MACCheckButton" to="." method="_on_mac_check_button_toggled"] +[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AdvancedToggleHBoxContainer/AdvancedCheckButton" to="." method="_on_advanced_check_button_toggled"] +[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer/IPCheckButton" to="." method="_on_ip_check_button_toggled"] +[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer/MACCheckButton" to="." method="_on_mac_check_button_toggled"] +[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AdvancedVBoxContainer/AddressesGridContainer/VPNBindCheckButton" to="." method="_on_vpn_bind_check_button_toggled"] [connection signal="pressed" from="SettingsWindow/MarginContainer/VBoxContainer/ButtonsHBoxContainer/SaveSettingsButton" to="." method="_on_save_settings_button_pressed"] diff --git a/hamncheese/Scripts/about.gd b/hamncheese/Scripts/about.gd index 6aabbf1..ad5d4ff 100644 --- a/hamncheese/Scripts/about.gd +++ b/hamncheese/Scripts/about.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Control diff --git a/hamncheese/Scripts/dialog.gd b/hamncheese/Scripts/dialog.gd index a85a91e..d17c946 100644 --- a/hamncheese/Scripts/dialog.gd +++ b/hamncheese/Scripts/dialog.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node diff --git a/hamncheese/Scripts/edge.gd b/hamncheese/Scripts/edge.gd index 9d701d4..9be247f 100644 --- a/hamncheese/Scripts/edge.gd +++ b/hamncheese/Scripts/edge.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node @@ -32,6 +34,12 @@ var _data_type := {} var _timer : Timer var _my_port := 0 var _management_port := 0 +var _community := "" +var _key := "" +var _supernode := "" +var _super_port := 0 +var _local_port := 0 +var _local_ip := "" signal data_recieved(type: String, data: Array) @@ -86,6 +94,26 @@ func _send(what: String, mode: String = MODE_READ): _sequence = 1 +func bind(local_ip: String = "", local_port: int = 10000): + _local_ip = local_ip + _local_port = local_port + + +func set_management(management_port: int = 5644, my_port: int = 5643): + _my_port = my_port + _management_port = management_port + + +func set_network(community: String, key: String): + _community = community + _key = key + + +func set_supernode(supernode: String, port: int = 7777): + _supernode = supernode + _super_port = port + + func shutdown(): if _edge_pid >= 0: if OS.is_process_running(_edge_pid): @@ -94,15 +122,17 @@ func shutdown(): _edge_running = false -func start_edge(community: String, key: String, supernode: String, port: int = 7777, my_port: int = 5643, management_port: int = 5644): - _my_port = my_port - _management_port = management_port +func start_edge(): _timer = Timer.new() _timer.wait_time = 3 _timer.autostart = true _timer.timeout.connect(_on_timer_timeout) var binary = OS.get_user_data_dir() + "/edge" - var arguments = ["--management-password", _password, "-c", community, "-k", key, "-l", supernode + ":" + str(port)] + var arguments = ["--management-password", _password, "-c", _community, "-k", _key, "-l", _supernode + ":" + str(_super_port), "-p"] + if _local_ip != "": + arguments.append(_local_ip + ":" + str(_local_port)) + else: + arguments.append(str(_local_port)) if OS.get_name() == "Windows": binary = binary + ".exe" else: diff --git a/hamncheese/Scripts/main.gd b/hamncheese/Scripts/main.gd index 649f41b..dfbf558 100644 --- a/hamncheese/Scripts/main.gd +++ b/hamncheese/Scripts/main.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,9 +14,14 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# # Things to do: +# - Get the rest of the edge settings into the dialog. +# - Rearrange settings dialog into simple/advanced. +# - Find non-sleazy way to handle registry editing for file access on Windows. +# - Crazy amount of other stuff. # # Issues to watch: # - https://github.com/ntop/n2n/issues/1090 (P2P connections still occupy server traffic) @@ -29,12 +35,6 @@ extends Control -# This port, and the next 255 ports, will be used. -# PEER_BASE_PORT Process Password Listening Port. -# PEER_BASE_PORT + 1 Unused Listening Port for Incoming Edge Management Data. -# PEER_BASE_PORT + 2 From here on, mesh peer sending ports and our mesh listening port. -const PEER_BASE_PORT := 20000 - const FILE_ID_SETTINGS = 0 const FILE_ID_EXIT = 2 @@ -62,9 +62,7 @@ func _data_recieved(type, data): _ip = data[0]["ip4addr"] my_ip_label.text = _ip if !Peers.is_running(): - # This is PEER_BASE_PORT + 1 because there will never be a peer ID of 0 - # so the first usable port is therefore PEER_BASE_PORT + 2. - Peers.start_server(_ip, PEER_BASE_PORT + 1, Settings.user_name_line_edit.text, Settings.uuid) + Peers.start_server(_ip, Settings.mesh_port_spin_box.value, Settings.user_name_line_edit.text, Settings.uuid) if type == "edges": if Peers.update(data): _draw_tree() @@ -142,8 +140,11 @@ func _on_help_id_pressed(id): func _on_online_check_button_toggled(toggled_on): if toggled_on: - #***TODO*** Not all Edge options are supported yet. - if await Edge.start_edge(Settings.network_name_line_edit.text, Settings.network_password_line_edit.text, Settings.server_line_edit.text, Settings.server_port_spin_box.value, PEER_BASE_PORT + 1) == false: + Edge.bind("" if Settings.vpn_bind_check_button.is_pressed else Settings.vpn_bind_line_edit, Settings.listening_port_spin_box.value) + Edge.set_network(Settings.network_name_line_edit.text, Settings.network_password_line_edit.text) + Edge.set_supernode(Settings.server_line_edit.text, Settings.server_port_spin_box.value) + Edge.set_management(Settings.management_port_spin_box.value, Settings.management_port_spin_box.value + 1) + if await Edge.start_edge() == false: online_check_button.set_pressed_no_signal(false) else: _go_offline() @@ -151,7 +152,7 @@ func _on_online_check_button_toggled(toggled_on): func _ready(): Settings.startup() - Process.startup(PEER_BASE_PORT) + Process.startup(Settings.management_port_spin_box.value + 2) # If we're on Windows, be sure we're running as Administrator. # This is going to bork up network shares later. if OS.get_name() == "Windows": diff --git a/hamncheese/Scripts/manual.gd b/hamncheese/Scripts/manual.gd index 117e8a7..fa32f84 100644 --- a/hamncheese/Scripts/manual.gd +++ b/hamncheese/Scripts/manual.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Control diff --git a/hamncheese/Scripts/network.gd b/hamncheese/Scripts/network.gd index 5ce261e..75ae436 100644 --- a/hamncheese/Scripts/network.gd +++ b/hamncheese/Scripts/network.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node diff --git a/hamncheese/Scripts/peers.gd b/hamncheese/Scripts/peers.gd index d85b64d..5cac290 100644 --- a/hamncheese/Scripts/peers.gd +++ b/hamncheese/Scripts/peers.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node @@ -158,7 +160,11 @@ func send_to_peer(peer, verb: String, payload: Dictionary): func start_server(address, portStart, user, uuid): if !_serverRunning: clear() - _basePort = portStart + # We are creating the peer port number by combining the portStart with the + # last octet of the peer's VPN IP address. Since this octet cannot be zero, + # we actually use portStart-1 as the base so we don't waste the first port + # specified by portStart. + _basePort = portStart - 1 _userInfo["ip"] = address _userInfo["user"] = user _userInfo["uuid"] = uuid diff --git a/hamncheese/Scripts/process.gd b/hamncheese/Scripts/process.gd index 254e60c..bbc331a 100644 --- a/hamncheese/Scripts/process.gd +++ b/hamncheese/Scripts/process.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node @@ -20,7 +22,7 @@ extends Node var _udp := UDPServer.new() var _ask_pass_password := "" -var _ask_pass_port := 19999 +var _ask_pass_port := 0 var _ask_pass_script := "" var _root_password = null @@ -31,13 +33,13 @@ func _elevate_unix(program: String, arguments: PackedStringArray): return -1 _ask_pass_password = Util.generate_password() _ask_pass_script = OS.get_user_data_dir() + "/ask_pass.sh" - var ask_pass = FileAccess.open(_ask_pass_script, FileAccess.WRITE) + var ask_pass := FileAccess.open(_ask_pass_script, FileAccess.WRITE) ask_pass.store_line("#!/usr/bin/env bash") ask_pass.store_line("echo " + _ask_pass_password + " | nc -w1 -u 127.0.0.1 " + str(_ask_pass_port)) ask_pass.close() OS.execute("chmod", ["+x", _ask_pass_script]) OS.set_environment("SUDO_ASKPASS", _ask_pass_script) - var options = ["-A", program] + var options := ["-A", program] options.append_array(arguments) var pid = OS.create_process("sudo", options, false) return pid @@ -56,9 +58,9 @@ func _elevate_windows(program: String, arguments: PackedStringArray): handle.store_line(power) handle.close() # Run it. - var cmdPid = OS.create_process(cmdFile, [], true) + var cmdPid := OS.create_process(cmdFile, [], true) # Wait for PID to be created. - var pid = -1 + var pid := -1 var count := 5 while !FileAccess.file_exists(pidFile) and count > 0: OS.delay_msec(500) @@ -86,7 +88,7 @@ func _process(_delta): _udp.poll() if _udp.is_connection_available(): var peer: PacketPeerUDP = _udp.take_connection() - var data = peer.get_packet().get_string_from_ascii() + var data := peer.get_packet().get_string_from_ascii() if peer.get_packet_error() == OK: if data.strip_edges() == _ask_pass_password: if _root_password != null: @@ -104,7 +106,8 @@ func elevate(program: String, arguments: PackedStringArray = []): func is_elevated(): if OS.get_name() == "Windows": - var result = OS.execute("net.exe", [ "sessions" ]) + # This will error if run by a standard user. + var result := OS.execute("net.exe", [ "sessions" ]) return true if result == 0 else false else: return false # We don't support this on UNIX. @@ -117,6 +120,6 @@ func shutdown(): DirAccess.remove_absolute(_ask_pass_script) -func startup(port: int = 19999): +func startup(port: int): _ask_pass_port = port _udp.listen(_ask_pass_port, "127.0.0.1") diff --git a/hamncheese/Scripts/settings.gd b/hamncheese/Scripts/settings.gd index f4fa79e..d2e9cdf 100644 --- a/hamncheese/Scripts/settings.gd +++ b/hamncheese/Scripts/settings.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,11 +14,28 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Control +# Ports used: +# MANAGEMENT_PORT Binds to 127.0.0.1 to talk from GUI to the edge. +# MANAGEMENT_PORT + 1 Binds to 127.0.0.1 to talk from edge to the GUI. +# MANAGEMENT_PORT + 2 Binds to 127.0.0.1 to handle Process password requests. +# PEER_BASE_PORT + x Binds to VPN for mesh peer sending ports and our mesh listening port. +# LISTEN_PORT Binds to every adapter it can. Listens for VPN traffic. + +const MANAGEMENT_PORT := 20000 +const PEER_BASE_PORT := 20000 +const LISTEN_PORT := 10000 + + +const BASIC_SIZE := 340 +const ADVANCED_SIZE := 670 + + @onready var settings_window = %SettingsWindow @onready var user_name_line_edit = %UserNameLineEdit @onready var network_name_line_edit = %NetworkNameLineEdit @@ -31,6 +49,12 @@ extends Control @onready var compression_check_button = %CompressionCheckButton @onready var auto_start_check_button = %AutoStartCheckButton @onready var save_settings_button = %SaveSettingsButton +@onready var advanced_v_box_container = %AdvancedVBoxContainer +@onready var listening_port_spin_box = %ListeningPortSpinBox +@onready var management_port_spin_box = %ManagementPortSpinBox +@onready var mesh_port_spin_box = %MeshPortSpinBox +@onready var vpn_bind_line_edit = %VPNBindLineEdit +@onready var vpn_bind_check_button = %VPNBindCheckButton var _crypto @@ -53,12 +77,21 @@ func _init_crypto(): _key.load("user://rsa.key") -func _on_ip_check_button_toggled(_toggled_on): - ip_line_edit.editable = !ip_check_button.button_pressed +func _on_advanced_check_button_toggled(toggled_on): + if toggled_on: + settings_window.size.y = ADVANCED_SIZE + else: + settings_window.size.y = BASIC_SIZE + advanced_v_box_container.visible = toggled_on + settings_window.move_to_center() -func _on_mac_check_button_toggled(_toggled_on): - mac_line_edit.editable = !mac_check_button.button_pressed +func _on_ip_check_button_toggled(toggled_on): + ip_line_edit.editable = !toggled_on + + +func _on_mac_check_button_toggled(toggled_on): + mac_line_edit.editable = !toggled_on func _on_save_settings_button_pressed(): @@ -70,6 +103,10 @@ func _on_settings_window_close_requested(): settings_window.visible = false +func _on_vpn_bind_check_button_toggled(toggled_on): + vpn_bind_line_edit.editable = !toggled_on + + func load_settings(): # Do we have a configuration yet? passwords = {} @@ -88,6 +125,11 @@ func load_settings(): mac_line_edit.text = "DE:AD:BE:EF:00:01" mac_check_button.button_pressed = true mac_line_edit.editable = false + vpn_bind_line_edit.text = "0.0.0.0" + vpn_bind_check_button.button_pressed = true + listening_port_spin_box.value = LISTEN_PORT + management_port_spin_box.value = MANAGEMENT_PORT + mesh_port_spin_box.value = PEER_BASE_PORT compression_check_button.button_pressed = true auto_start_check_button.button_pressed = false uuid = Uuid.v4() @@ -103,6 +145,12 @@ func load_settings(): mac_line_edit.text = config.get_value("settings", "macAddress", "DE:AD:BE:EF:00:01") mac_check_button.button_pressed = config.get_value("settings", "macAutomatic", true) mac_line_edit.editable = !mac_check_button.button_pressed + vpn_bind_line_edit.text = config.get_value("settings", "bindAddress", "0.0.0.0") + vpn_bind_check_button.button_pressed = config.get_value("settings", "bindAll", true) + vpn_bind_line_edit.editable = !vpn_bind_check_button.button_pressed + listening_port_spin_box.value = config.get_value("settings", "listeningPort", LISTEN_PORT) + management_port_spin_box.value = config.get_value("settings", "managementPort", MANAGEMENT_PORT) + mesh_port_spin_box.value = config.get_value("settings", "meshPort", PEER_BASE_PORT) compression_check_button.button_pressed = config.get_value("settings", "compression", true) auto_start_check_button.button_pressed = config.get_value("settings", "autoStart", false) uuid = config.get_value("settings", "identity", Uuid.v4()) @@ -132,6 +180,14 @@ func save_settings(): await Dialog.alert("Invalid MAC Address", "The MAC address entered is invalid.", settings_window) return + # Validate Bind address, if needed. + if !vpn_bind_check_button.button_pressed: + var ipCheck = RegEx.create_from_string("^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$") + if ipCheck.search(vpn_bind_line_edit.text) == null: + # Not an IP address. + await Dialog.alert("Invalid Bind Address", "The bind address entered is invalid.", settings_window) + return + # Save it. var config = ConfigFile.new() # Settings. @@ -143,6 +199,11 @@ func save_settings(): config.set_value("settings", "ipAutomatic", ip_check_button.button_pressed) config.set_value("settings", "macAddress", mac_line_edit.text) config.set_value("settings", "macAutomatic", mac_check_button.button_pressed) + config.set_value("settings", "bindAddress", vpn_bind_line_edit.text) + config.set_value("settings", "bindAll ", vpn_bind_check_button.button_pressed) + config.set_value("settings", "listeningPort", listening_port_spin_box.value) + config.set_value("settings", "managementPort", management_port_spin_box.value) + config.set_value("settings", "meshPort", mesh_port_spin_box.value) config.set_value("settings", "compression", compression_check_button.button_pressed) config.set_value("settings", "autoStart", auto_start_check_button.button_pressed) #config.set_value("settings", "position", DisplayServer.window_get_position()) @@ -156,6 +217,8 @@ func save_settings(): func startup(): + settings_window.visible = false + advanced_v_box_container.visible = false + settings_window.size.y = BASIC_SIZE _init_crypto() load_settings() - diff --git a/hamncheese/Scripts/util.gd b/hamncheese/Scripts/util.gd index 5f3086a..275eabd 100644 --- a/hamncheese/Scripts/util.gd +++ b/hamncheese/Scripts/util.gd @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# extends Node diff --git a/modules/embedded/SCsub b/modules/embedded/SCsub index e75bb2e..7c3985d 100644 --- a/modules/embedded/SCsub +++ b/modules/embedded/SCsub @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# Import('env') diff --git a/modules/embedded/config.py b/modules/embedded/config.py index a344f20..be97f27 100644 --- a/modules/embedded/config.py +++ b/modules/embedded/config.py @@ -1,3 +1,4 @@ +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -13,6 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# def can_build(env, platform): diff --git a/prereqs.sh b/prereqs.sh index 141014b..0781e9c 100755 --- a/prereqs.sh +++ b/prereqs.sh @@ -1,5 +1,6 @@ #!/bin/bash +# # Ham'n'Cheese # Copyright (C) 2023-2024 Scott Duensing # @@ -15,6 +16,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see +# #