Add button for sending toml
This commit is contained in:
parent
c8a21c73a8
commit
3ba0004370
8 changed files with 74 additions and 11 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>com.apple.security.network.server</key>
|
||||||
|
<true/>
|
||||||
<key>com.apple.developer.associated-domains</key>
|
<key>com.apple.developer.associated-domains</key>
|
||||||
<array>
|
<array>
|
||||||
<string>applinks:burrow.rs?mode=developer</string>
|
<string>applinks:burrow.rs?mode=developer</string>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>com.apple.security.network.server</key>
|
||||||
|
<true/>
|
||||||
<key>com.apple.developer.associated-domains</key>
|
<key>com.apple.developer.associated-domains</key>
|
||||||
<array>
|
<array>
|
||||||
<string>applinks:burrow.rs?mode=developer</string>
|
<string>applinks:burrow.rs?mode=developer</string>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import BurrowShared
|
||||||
struct BurrowView: View {
|
struct BurrowView: View {
|
||||||
@Environment(\.webAuthenticationSession)
|
@Environment(\.webAuthenticationSession)
|
||||||
private var webAuthenticationSession
|
private var webAuthenticationSession
|
||||||
@State private var rpcClient: Client? = nil
|
@State private var rpcClient: Client?
|
||||||
@State private var showAlert = false
|
@State private var showAlert = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,66 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import BurrowShared
|
||||||
|
|
||||||
struct MenuItemToggleView: View {
|
struct MenuItemToggleView: View {
|
||||||
@Environment(\.tunnel)
|
@Environment(\.tunnel)
|
||||||
var tunnel: Tunnel
|
var tunnel: Tunnel
|
||||||
|
@State private var showAlert = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
VStack {
|
||||||
VStack(alignment: .leading) {
|
HStack {
|
||||||
Text("Burrow")
|
VStack(alignment: .leading) {
|
||||||
.font(.headline)
|
Text("Burrow")
|
||||||
Text(tunnel.status.description)
|
.font(.headline)
|
||||||
.font(.subheadline)
|
Text(tunnel.status.description)
|
||||||
}
|
.font(.subheadline)
|
||||||
Spacer()
|
}
|
||||||
Toggle(isOn: tunnel.toggleIsOn) {
|
Spacer()
|
||||||
}
|
Toggle(isOn: tunnel.toggleIsOn) {
|
||||||
|
}
|
||||||
.disabled(tunnel.toggleDisabled)
|
.disabled(tunnel.toggleDisabled)
|
||||||
.toggleStyle(.switch)
|
.toggleStyle(.switch)
|
||||||
|
}
|
||||||
|
Button("Add Custom WG Config", action: sncAddCustomnetwork)
|
||||||
}
|
}
|
||||||
.accessibilityElement(children: .combine)
|
.accessibilityElement(children: .combine)
|
||||||
.padding(.horizontal, 4)
|
.padding(.horizontal, 4)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.frame(minWidth: 300, minHeight: 32, maxHeight: 32)
|
.frame(minWidth: 300, minHeight: 32, maxHeight: 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sncAddCustomnetwork(){
|
||||||
|
Task {
|
||||||
|
try await addCustomnetwork()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addCustomnetwork() async {
|
||||||
|
do{
|
||||||
|
let networkToml = """
|
||||||
|
[[peers]]
|
||||||
|
public_key = "8GaFjVO6c4luCHG4ONO+1bFG8tO+Zz5/Gy+Geht1USM="
|
||||||
|
preshared_key = "ha7j4BjD49sIzyF9SNlbueK0AMHghlj6+u0G3bzC698="
|
||||||
|
allowed_ips = ["8.8.8.8/32", "0.0.0.0/0"]
|
||||||
|
endpoint = "wg.burrow.rs:51820"
|
||||||
|
|
||||||
|
[interface]
|
||||||
|
private_key = "OEPVdomeLTxTIBvv3TYsJRge0Hp9NMiY0sIrhT8OWG8="
|
||||||
|
address = ["10.13.13.2/24"]
|
||||||
|
listen_port = 51820
|
||||||
|
dns = []
|
||||||
|
"""
|
||||||
|
let client = try Client()
|
||||||
|
try await client.single_request("AddConfigToml", params: networkToml, type: BurrowResult<AnyResponseData>.self)
|
||||||
|
alert("Successs!", isPresented: $showAlert){
|
||||||
|
Button("OK", role: .cancel) {}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Tunnel {
|
extension Tunnel {
|
||||||
|
|
|
||||||
14
Apple/App/RpcOperations.swift
Normal file
14
Apple/App/RpcOperations.swift
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// RpcOperations.swift
|
||||||
|
// App
|
||||||
|
//
|
||||||
|
// Created by Jett Chen on 2024/5/18.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class RpcOperations{
|
||||||
|
func uploadConfig(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
0BA6D73C2BA6393200BD4B55 /* NWConnection+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00117302B2FFFC900D87C25 /* NWConnection+Async.swift */; };
|
0BA6D73C2BA6393200BD4B55 /* NWConnection+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00117302B2FFFC900D87C25 /* NWConnection+Async.swift */; };
|
||||||
0BA6D73D2BA6393B00BD4B55 /* NewlineProtocolFramer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00117322B3001A400D87C25 /* NewlineProtocolFramer.swift */; };
|
0BA6D73D2BA6393B00BD4B55 /* NewlineProtocolFramer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00117322B3001A400D87C25 /* NewlineProtocolFramer.swift */; };
|
||||||
0BA6D73E2BA6394B00BD4B55 /* DataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B28F1552ABF463A000D44B0 /* DataTypes.swift */; };
|
0BA6D73E2BA6394B00BD4B55 /* DataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B28F1552ABF463A000D44B0 /* DataTypes.swift */; };
|
||||||
|
0BE456612BF90752005E4D47 /* RpcOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BE456602BF90752005E4D47 /* RpcOperations.swift */; };
|
||||||
43AA26D82A10004900F14CE6 /* MenuItemToggleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43AA26D72A10004900F14CE6 /* MenuItemToggleView.swift */; };
|
43AA26D82A10004900F14CE6 /* MenuItemToggleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43AA26D72A10004900F14CE6 /* MenuItemToggleView.swift */; };
|
||||||
D000363D2BB8928E00E582EC /* NetworkCarouselView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D000363C2BB8928E00E582EC /* NetworkCarouselView.swift */; };
|
D000363D2BB8928E00E582EC /* NetworkCarouselView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D000363C2BB8928E00E582EC /* NetworkCarouselView.swift */; };
|
||||||
D000363F2BB895FB00E582EC /* OAuth2.swift in Sources */ = {isa = PBXBuildFile; fileRef = D000363E2BB895FB00E582EC /* OAuth2.swift */; };
|
D000363F2BB895FB00E582EC /* OAuth2.swift in Sources */ = {isa = PBXBuildFile; fileRef = D000363E2BB895FB00E582EC /* OAuth2.swift */; };
|
||||||
|
|
@ -79,6 +80,7 @@
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
0B28F1552ABF463A000D44B0 /* DataTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTypes.swift; sourceTree = "<group>"; };
|
0B28F1552ABF463A000D44B0 /* DataTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataTypes.swift; sourceTree = "<group>"; };
|
||||||
0B46E8DF2AC918CA00BA2A3C /* Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
|
0B46E8DF2AC918CA00BA2A3C /* Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
|
||||||
|
0BE456602BF90752005E4D47 /* RpcOperations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RpcOperations.swift; sourceTree = "<group>"; };
|
||||||
43AA26D72A10004900F14CE6 /* MenuItemToggleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemToggleView.swift; sourceTree = "<group>"; };
|
43AA26D72A10004900F14CE6 /* MenuItemToggleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemToggleView.swift; sourceTree = "<group>"; };
|
||||||
D000363C2BB8928E00E582EC /* NetworkCarouselView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkCarouselView.swift; sourceTree = "<group>"; };
|
D000363C2BB8928E00E582EC /* NetworkCarouselView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkCarouselView.swift; sourceTree = "<group>"; };
|
||||||
D000363E2BB895FB00E582EC /* OAuth2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth2.swift; sourceTree = "<group>"; };
|
D000363E2BB895FB00E582EC /* OAuth2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OAuth2.swift; sourceTree = "<group>"; };
|
||||||
|
|
@ -259,6 +261,7 @@
|
||||||
D0FAB5952B818B2900F6A84B /* TunnelButton.swift */,
|
D0FAB5952B818B2900F6A84B /* TunnelButton.swift */,
|
||||||
D0B98FC629FDC5B5004E7149 /* Tunnel.swift */,
|
D0B98FC629FDC5B5004E7149 /* Tunnel.swift */,
|
||||||
D0FAB5912B818A5900F6A84B /* NetworkExtensionTunnel.swift */,
|
D0FAB5912B818A5900F6A84B /* NetworkExtensionTunnel.swift */,
|
||||||
|
0BE456602BF90752005E4D47 /* RpcOperations.swift */,
|
||||||
D0BCC5FC2A086D4700AD070D /* NetworkExtension+Async.swift */,
|
D0BCC5FC2A086D4700AD070D /* NetworkExtension+Async.swift */,
|
||||||
D05EF8C72B81818D0017AB4F /* FloatingButtonStyle.swift */,
|
D05EF8C72B81818D0017AB4F /* FloatingButtonStyle.swift */,
|
||||||
D05B9F7929E39EED008CB1F9 /* Assets.xcassets */,
|
D05B9F7929E39EED008CB1F9 /* Assets.xcassets */,
|
||||||
|
|
@ -485,6 +488,7 @@
|
||||||
D000363F2BB895FB00E582EC /* OAuth2.swift in Sources */,
|
D000363F2BB895FB00E582EC /* OAuth2.swift in Sources */,
|
||||||
D0FAB5962B818B2900F6A84B /* TunnelButton.swift in Sources */,
|
D0FAB5962B818B2900F6A84B /* TunnelButton.swift in Sources */,
|
||||||
D00AA8972A4669BC005C8102 /* AppDelegate.swift in Sources */,
|
D00AA8972A4669BC005C8102 /* AppDelegate.swift in Sources */,
|
||||||
|
0BE456612BF90752005E4D47 /* RpcOperations.swift in Sources */,
|
||||||
D05EF8C82B81818D0017AB4F /* FloatingButtonStyle.swift in Sources */,
|
D05EF8C82B81818D0017AB4F /* FloatingButtonStyle.swift in Sources */,
|
||||||
D032E6522B8A79C20006B8AD /* HackClub.swift in Sources */,
|
D032E6522B8A79C20006B8AD /* HackClub.swift in Sources */,
|
||||||
D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */,
|
D05B9F7629E39EEC008CB1F9 /* BurrowApp.swift in Sources */,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>com.apple.security.network.server</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.network.client</key>
|
||||||
|
<true/>
|
||||||
<key>com.apple.developer.networking.networkextension</key>
|
<key>com.apple.developer.networking.networkextension</key>
|
||||||
<array>
|
<array>
|
||||||
<string>packet-tunnel-provider</string>
|
<string>packet-tunnel-provider</string>
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ mod tests {
|
||||||
fn tst_config_toml() {
|
fn tst_config_toml() {
|
||||||
let cfig = Config::default();
|
let cfig = Config::default();
|
||||||
let toml = toml::to_string(&cfig).unwrap();
|
let toml = toml::to_string(&cfig).unwrap();
|
||||||
|
println!("{}", &toml);
|
||||||
insta::assert_snapshot!(toml);
|
insta::assert_snapshot!(toml);
|
||||||
let cfig2: Config = toml::from_str(&toml).unwrap();
|
let cfig2: Config = toml::from_str(&toml).unwrap();
|
||||||
assert_eq!(cfig, cfig2);
|
assert_eq!(cfig, cfig2);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue