Advanced settings implemented.

This commit is contained in:
Scott Duensing 2023-09-29 19:18:57 -05:00
parent ddc67de905
commit 27389bdb23
19 changed files with 264 additions and 46 deletions

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -15,6 +16,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
function createEmbeddedBinary() { function createEmbeddedBinary() {

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -15,6 +16,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
# Build n2n. # Build n2n.

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
# Nothing to do on the native platform. # Nothing to do on the native platform.

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_NAME Windows)

View file

@ -15,8 +15,7 @@ script = ExtResource("1_c1h2m")
unique_name_in_owner = true unique_name_in_owner = true
title = "Settings" title = "Settings"
initial_position = 1 initial_position = 1
size = Vector2i(500, 450) size = Vector2i(500, 670)
visible = false
unresizable = true unresizable = true
[node name="MarginContainer" type="MarginContainer" parent="SettingsWindow"] [node name="MarginContainer" type="MarginContainer" parent="SettingsWindow"]
@ -107,76 +106,164 @@ horizontal_alignment = 2
[node name="ServerPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/ServerGridContainer"] [node name="ServerPortSpinBox" type="SpinBox" parent="SettingsWindow/MarginContainer/VBoxContainer/ServerGridContainer"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
min_value = 1.0
max_value = 65535.0 max_value = 65535.0
page = 100.0 page = 100.0
value = 1.0
rounded = true rounded = true
alignment = 2
select_all_on_focus = true select_all_on_focus = true
[node name="MarginContainer2" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] [node name="MarginContainer2" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 20) custom_minimum_size = Vector2(0, 20)
layout_mode = 2 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 layout_mode = 2
theme_override_constants/h_separation = 10 theme_override_constants/h_separation = 10
theme_override_constants/v_separation = 10 theme_override_constants/v_separation = 10
columns = 3 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 layout_mode = 2
text = "IP Address:" text = "IP Address:"
horizontal_alignment = 2 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
select_all_on_focus = true 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
text = "Automatic" 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 layout_mode = 2
text = "MAC Address:" text = "MAC Address:"
horizontal_alignment = 2 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
select_all_on_focus = true 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
text = "Automatic" 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) custom_minimum_size = Vector2(0, 20)
layout_mode = 2 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 layout_mode = 2
theme_override_constants/h_separation = 10 theme_override_constants/h_separation = 10
theme_override_constants/v_separation = 10 theme_override_constants/v_separation = 10
columns = 2 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 8 size_flags_horizontal = 8
text = "Enable Compression" 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
text = "Start Network on Startup" text = "Start Network on Startup"
[node name="MarginContainer3" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] [node name="MarginContainer3" type="MarginContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 40) custom_minimum_size = Vector2(0, 30)
layout_mode = 2 layout_mode = 2
[node name="ButtonsHBoxContainer" type="HBoxContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"] [node name="ButtonsHBoxContainer" type="HBoxContainer" parent="SettingsWindow/MarginContainer/VBoxContainer"]
@ -189,6 +276,8 @@ layout_mode = 2
text = "Save" text = "Save"
[connection signal="close_requested" from="SettingsWindow" to="." method="_on_settings_window_close_requested"] [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/AdvancedToggleHBoxContainer/AdvancedCheckButton" to="." method="_on_advanced_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/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"] [connection signal="pressed" from="SettingsWindow/MarginContainer/VBoxContainer/ButtonsHBoxContainer/SaveSettingsButton" to="." method="_on_save_settings_button_pressed"]

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Control extends Control

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node
@ -32,6 +34,12 @@ var _data_type := {}
var _timer : Timer var _timer : Timer
var _my_port := 0 var _my_port := 0
var _management_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) signal data_recieved(type: String, data: Array)
@ -86,6 +94,26 @@ func _send(what: String, mode: String = MODE_READ):
_sequence = 1 _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(): func shutdown():
if _edge_pid >= 0: if _edge_pid >= 0:
if OS.is_process_running(_edge_pid): if OS.is_process_running(_edge_pid):
@ -94,15 +122,17 @@ func shutdown():
_edge_running = false _edge_running = false
func start_edge(community: String, key: String, supernode: String, port: int = 7777, my_port: int = 5643, management_port: int = 5644): func start_edge():
_my_port = my_port
_management_port = management_port
_timer = Timer.new() _timer = Timer.new()
_timer.wait_time = 3 _timer.wait_time = 3
_timer.autostart = true _timer.autostart = true
_timer.timeout.connect(_on_timer_timeout) _timer.timeout.connect(_on_timer_timeout)
var binary = OS.get_user_data_dir() + "/edge" 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": if OS.get_name() == "Windows":
binary = binary + ".exe" binary = binary + ".exe"
else: else:

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,9 +14,14 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
# Things to do: # 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: # Issues to watch:
# - https://github.com/ntop/n2n/issues/1090 (P2P connections still occupy server traffic) # - https://github.com/ntop/n2n/issues/1090 (P2P connections still occupy server traffic)
@ -29,12 +35,6 @@
extends Control 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_SETTINGS = 0
const FILE_ID_EXIT = 2 const FILE_ID_EXIT = 2
@ -62,9 +62,7 @@ func _data_recieved(type, data):
_ip = data[0]["ip4addr"] _ip = data[0]["ip4addr"]
my_ip_label.text = _ip my_ip_label.text = _ip
if !Peers.is_running(): if !Peers.is_running():
# This is PEER_BASE_PORT + 1 because there will never be a peer ID of 0 Peers.start_server(_ip, Settings.mesh_port_spin_box.value, Settings.user_name_line_edit.text, Settings.uuid)
# 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)
if type == "edges": if type == "edges":
if Peers.update(data): if Peers.update(data):
_draw_tree() _draw_tree()
@ -142,8 +140,11 @@ func _on_help_id_pressed(id):
func _on_online_check_button_toggled(toggled_on): func _on_online_check_button_toggled(toggled_on):
if toggled_on: if toggled_on:
#***TODO*** Not all Edge options are supported yet. Edge.bind("" if Settings.vpn_bind_check_button.is_pressed else Settings.vpn_bind_line_edit, Settings.listening_port_spin_box.value)
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.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) online_check_button.set_pressed_no_signal(false)
else: else:
_go_offline() _go_offline()
@ -151,7 +152,7 @@ func _on_online_check_button_toggled(toggled_on):
func _ready(): func _ready():
Settings.startup() 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. # If we're on Windows, be sure we're running as Administrator.
# This is going to bork up network shares later. # This is going to bork up network shares later.
if OS.get_name() == "Windows": if OS.get_name() == "Windows":

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Control extends Control

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node
@ -158,7 +160,11 @@ func send_to_peer(peer, verb: String, payload: Dictionary):
func start_server(address, portStart, user, uuid): func start_server(address, portStart, user, uuid):
if !_serverRunning: if !_serverRunning:
clear() 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["ip"] = address
_userInfo["user"] = user _userInfo["user"] = user
_userInfo["uuid"] = uuid _userInfo["uuid"] = uuid

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node
@ -20,7 +22,7 @@ extends Node
var _udp := UDPServer.new() var _udp := UDPServer.new()
var _ask_pass_password := "" var _ask_pass_password := ""
var _ask_pass_port := 19999 var _ask_pass_port := 0
var _ask_pass_script := "" var _ask_pass_script := ""
var _root_password = null var _root_password = null
@ -31,13 +33,13 @@ func _elevate_unix(program: String, arguments: PackedStringArray):
return -1 return -1
_ask_pass_password = Util.generate_password() _ask_pass_password = Util.generate_password()
_ask_pass_script = OS.get_user_data_dir() + "/ask_pass.sh" _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("#!/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.store_line("echo " + _ask_pass_password + " | nc -w1 -u 127.0.0.1 " + str(_ask_pass_port))
ask_pass.close() ask_pass.close()
OS.execute("chmod", ["+x", _ask_pass_script]) OS.execute("chmod", ["+x", _ask_pass_script])
OS.set_environment("SUDO_ASKPASS", _ask_pass_script) OS.set_environment("SUDO_ASKPASS", _ask_pass_script)
var options = ["-A", program] var options := ["-A", program]
options.append_array(arguments) options.append_array(arguments)
var pid = OS.create_process("sudo", options, false) var pid = OS.create_process("sudo", options, false)
return pid return pid
@ -56,9 +58,9 @@ func _elevate_windows(program: String, arguments: PackedStringArray):
handle.store_line(power) handle.store_line(power)
handle.close() handle.close()
# Run it. # Run it.
var cmdPid = OS.create_process(cmdFile, [], true) var cmdPid := OS.create_process(cmdFile, [], true)
# Wait for PID to be created. # Wait for PID to be created.
var pid = -1 var pid := -1
var count := 5 var count := 5
while !FileAccess.file_exists(pidFile) and count > 0: while !FileAccess.file_exists(pidFile) and count > 0:
OS.delay_msec(500) OS.delay_msec(500)
@ -86,7 +88,7 @@ func _process(_delta):
_udp.poll() _udp.poll()
if _udp.is_connection_available(): if _udp.is_connection_available():
var peer: PacketPeerUDP = _udp.take_connection() 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 peer.get_packet_error() == OK:
if data.strip_edges() == _ask_pass_password: if data.strip_edges() == _ask_pass_password:
if _root_password != null: if _root_password != null:
@ -104,7 +106,8 @@ func elevate(program: String, arguments: PackedStringArray = []):
func is_elevated(): func is_elevated():
if OS.get_name() == "Windows": 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 return true if result == 0 else false
else: else:
return false # We don't support this on UNIX. return false # We don't support this on UNIX.
@ -117,6 +120,6 @@ func shutdown():
DirAccess.remove_absolute(_ask_pass_script) DirAccess.remove_absolute(_ask_pass_script)
func startup(port: int = 19999): func startup(port: int):
_ask_pass_port = port _ask_pass_port = port
_udp.listen(_ask_pass_port, "127.0.0.1") _udp.listen(_ask_pass_port, "127.0.0.1")

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,11 +14,28 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Control 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 settings_window = %SettingsWindow
@onready var user_name_line_edit = %UserNameLineEdit @onready var user_name_line_edit = %UserNameLineEdit
@onready var network_name_line_edit = %NetworkNameLineEdit @onready var network_name_line_edit = %NetworkNameLineEdit
@ -31,6 +49,12 @@ extends Control
@onready var compression_check_button = %CompressionCheckButton @onready var compression_check_button = %CompressionCheckButton
@onready var auto_start_check_button = %AutoStartCheckButton @onready var auto_start_check_button = %AutoStartCheckButton
@onready var save_settings_button = %SaveSettingsButton @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 var _crypto
@ -53,12 +77,21 @@ func _init_crypto():
_key.load("user://rsa.key") _key.load("user://rsa.key")
func _on_ip_check_button_toggled(_toggled_on): func _on_advanced_check_button_toggled(toggled_on):
ip_line_edit.editable = !ip_check_button.button_pressed 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): func _on_ip_check_button_toggled(toggled_on):
mac_line_edit.editable = !mac_check_button.button_pressed 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(): func _on_save_settings_button_pressed():
@ -70,6 +103,10 @@ func _on_settings_window_close_requested():
settings_window.visible = false settings_window.visible = false
func _on_vpn_bind_check_button_toggled(toggled_on):
vpn_bind_line_edit.editable = !toggled_on
func load_settings(): func load_settings():
# Do we have a configuration yet? # Do we have a configuration yet?
passwords = {} passwords = {}
@ -88,6 +125,11 @@ func load_settings():
mac_line_edit.text = "DE:AD:BE:EF:00:01" mac_line_edit.text = "DE:AD:BE:EF:00:01"
mac_check_button.button_pressed = true mac_check_button.button_pressed = true
mac_line_edit.editable = false 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 compression_check_button.button_pressed = true
auto_start_check_button.button_pressed = false auto_start_check_button.button_pressed = false
uuid = Uuid.v4() 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_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_check_button.button_pressed = config.get_value("settings", "macAutomatic", true)
mac_line_edit.editable = !mac_check_button.button_pressed 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) compression_check_button.button_pressed = config.get_value("settings", "compression", true)
auto_start_check_button.button_pressed = config.get_value("settings", "autoStart", false) auto_start_check_button.button_pressed = config.get_value("settings", "autoStart", false)
uuid = config.get_value("settings", "identity", Uuid.v4()) 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) await Dialog.alert("Invalid MAC Address", "The MAC address entered is invalid.", settings_window)
return 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. # Save it.
var config = ConfigFile.new() var config = ConfigFile.new()
# Settings. # Settings.
@ -143,6 +199,11 @@ func save_settings():
config.set_value("settings", "ipAutomatic", ip_check_button.button_pressed) config.set_value("settings", "ipAutomatic", ip_check_button.button_pressed)
config.set_value("settings", "macAddress", mac_line_edit.text) config.set_value("settings", "macAddress", mac_line_edit.text)
config.set_value("settings", "macAutomatic", mac_check_button.button_pressed) 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", "compression", compression_check_button.button_pressed)
config.set_value("settings", "autoStart", auto_start_check_button.button_pressed) config.set_value("settings", "autoStart", auto_start_check_button.button_pressed)
#config.set_value("settings", "position", DisplayServer.window_get_position()) #config.set_value("settings", "position", DisplayServer.window_get_position())
@ -156,6 +217,8 @@ func save_settings():
func startup(): func startup():
settings_window.visible = false
advanced_v_box_container.visible = false
settings_window.size.y = BASIC_SIZE
_init_crypto() _init_crypto()
load_settings() load_settings()

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
extends Node extends Node

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
Import('env') Import('env')

View file

@ -1,3 +1,4 @@
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -13,6 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
def can_build(env, platform): def can_build(env, platform):

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
#
# Ham'n'Cheese # Ham'n'Cheese
# Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com> # Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
# #
@ -15,6 +16,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/> # along with this program; if not, see <http://www.gnu.org/licenses/>
#
# #