Skip to content

Commit

Permalink
Test 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Jul 8, 2024
1 parent 546634b commit a29243c
Showing 1 changed file with 7 additions and 81 deletions.
88 changes: 7 additions & 81 deletions pages/settings/PageSettingsTailscale.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,90 +62,16 @@ Page {
property bool isConnected: connectState == 100 && isEnabledAndRunning


property string network: "Wired"
property string tech: "ethernet"

property alias service: service.service
readonly property bool ready: root.service.length > 0

readonly property bool _wifi: tech === "wifi"
readonly property bool _disconnected: service.state === "idle" || service.state === "failure"

VeQuickItem {
id: service

uid: Global.venusPlatform.serviceUid + "/Network/Services"

property string service
property string state
property string method_
property string macAddress
property string ipAddress
property string netmask
property string subnet
property string gateway
property string nameserver
property string strength
readonly property bool manual: method_ === "manual"
property bool secured
property bool favorite
property bool completed

// Only handle changed value after component completion because otherwise <network> may not be set correctly.
// onValueChanged: if (completed) parseJson()
Component.onCompleted: {
completed = true
parseJson()
if (root._wifi) {
setAgent("on")
}
}

function parseJson() {
// make subnet available outside of this function
root.subnet = calculateSubnetFromNetmask(ipAddress, netmask)


if (!isValid || typeof value !== "string") {
return
}
property VeQuickItem networkServicesItem: VeQuickItem { uid: Global.venusPlatform.serviceUid + "/Network/Services" }

const services = JSON.parse(value)
property string networkServices: networkServicesItem.isValid ? networkServicesItem.value : ""
console.log("networkServices: " + networkServices)

let details
const networkServicesJson = JSON.parse(networkServices)

// Find the network service using service identifier
if (root.service.length > 0) {
for (const [network, networkDetails] of Object.entries(services[tech])) {
if (root.service === networkDetails["Service"]) {
root.network = network // SSID name may have been updated
details = networkDetails
break
}
}
} else if (network.length > 0) {
// If not available use the network name instead (in Ethernet case "Wired")
details = network && services[tech][network] ? services[tech][network] : undefined
}
property string subnet: calculateSubnetFromNetmask(networkServicesJson["ethernet"]["Wired"]["Address"], networkServicesJson["ethernet"]["Wired"]["Netmask"])
console.log("subnet: " + subnet)

if (details) {
root.service = details["Service"]
state = details["State"]
method_ = details["Method"]
ipAddress = details["Address"]
macAddress = details["Mac"]
netmask = details["Netmask"]
gateway = details["Gateway"]
nameserver = details["Nameservers"][0] || ""
strength = details["Strength"] || ""
secured = details["Secured"] === "yes"
favorite = details["Favorite"] === "yes"

subnet = calculateSubnetFromNetmask(ipAddress, netmask)
console.log("Subnet: " + subnet)
}
}
}

function calculateSubnetFromNetmask(ipAddress, netmask) {
// Split IP address and netmask into octets
Expand Down Expand Up @@ -355,7 +281,7 @@ Page {
//% ""
// text: qsTrId("settings_tailscale_")
text: "Expose physical subnet routes to your entire Tailscale network. Separate multiple IP/subnets by comma.\n
Enter \"" + service.subnet + "\" to be able to access your local network via Tailscale.\n
Enter \"" + subnet + "\" to be able to access your local network via Tailscale.\n
\n
NOTE: If you haven't enabled \"autoApprovers\" in the Tailscale admin console, then you need to manually approve the route in the Tailscale admin console. See https://tailscale.com/kb/1019/subnets -> Enable subnet routes from the admin console"
}
Expand Down

0 comments on commit a29243c

Please sign in to comment.