From 567788078bab82600463cf499c7043126fd04c10 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 25 Jun 2020 00:06:06 -0400 Subject: [PATCH 1/2] updates to the service, logging and small bug fixes --- service/cziti/ctun.go | 4 ++-- service/cziti/dns-proxy.go | 2 +- service/cziti/dns.go | 1 + service/cziti/sdk.go | 2 +- service/cziti/windns/windns.go | 2 +- service/ziti-tunnel/service/ipc.go | 33 ++++++++++++++++++++++------ service/ziti-tunnel/service/state.go | 14 +----------- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/service/cziti/ctun.go b/service/cziti/ctun.go index 3ea04c7c..1ad976ed 100644 --- a/service/cziti/ctun.go +++ b/service/cziti/ctun.go @@ -249,7 +249,7 @@ func (t *tunnel) runWriteLoop() { func (t *tunnel) AddIntercept(svcId string, service string, host string, port int, ctx unsafe.Pointer) { log.Debugf("about to add intercept for: %s, %s, %d", service, host, port) res := C.ziti_tunneler_intercept_v1(t.tunCtx, ctx, C.CString(svcId), C.CString(service), C.CString(host), C.int(port)) - log.Debugf("intercept added", res) + log.Debugf("intercept added: %v", res) } func RemoveIntercept(svcvId string) { @@ -263,6 +263,6 @@ func AddIntercept(svcId string, service string, host string, port uint16, ctx *C for _, t := range devMap { log.Debug("adding intercept for: %s, %s, %d", service, host, port) res := C.ziti_tunneler_intercept_v1(t.tunCtx, unsafe.Pointer(ctx.nf), C.CString(svcId), C.CString(service), C.CString(host), C.int(port)) - log.Debugf("intercept added", res) + log.Debugf("intercept added: %v", res) } } \ No newline at end of file diff --git a/service/cziti/dns-proxy.go b/service/cziti/dns-proxy.go index 59f65495..c1d582ea 100644 --- a/service/cziti/dns-proxy.go +++ b/service/cziti/dns-proxy.go @@ -46,7 +46,7 @@ func processDNSquery(packet []byte, p *net.UDPAddr, s *net.UDPConn) { // never proxy hostnames that we know about regardless of type if ip != nil { - log.Debug("resolved ", query.Name, ip) + log.Debugf("resolved %s as %v", query.Name, ip) var answer *dns.A if query.Qtype == dns.TypeA && len(ip.To4()) == net.IPv4len { diff --git a/service/cziti/dns.go b/service/cziti/dns.go index 406db970..a17e0b19 100644 --- a/service/cziti/dns.go +++ b/service/cziti/dns.go @@ -58,6 +58,7 @@ type ctxService struct { } func (dns *dnsImpl) RegisterService(dnsName string, port uint16, ctx *CZitiCtx, name string) (net.IP, error) { + log.Infof("adding DNS entry for service name %s@%s:%d", name, dnsName, port) DnsInit(defaultCidr, defaultMaskBits) dnsName = dnsName + "." key := fmt.Sprint(dnsName, ':', port) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 3743e8d0..eb59d4de 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -172,11 +172,11 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un } ctx.Services.Store(id, added) if host != "" && port != -1 { - log.Infof("service intercept beginning for service: %s @ %s:%d") ip, err := DNS.RegisterService(host, uint16(port), ctx, name) if err != nil { log.Warn(err) } else { + log.Infof("service intercept beginning for service: %s@%s:%d on ip %s", name, host, port, ip.String()) log.Infof("service[%s] is mapped to <%s:%d>", name, ip.String(), port) for _, t := range devMap { t.AddIntercept(id, name, ip.String(), port, unsafe.Pointer(ctx.nf)) diff --git a/service/cziti/windns/windns.go b/service/cziti/windns/windns.go index 1a27a84b..529816bf 100644 --- a/service/cziti/windns/windns.go +++ b/service/cziti/windns/windns.go @@ -42,7 +42,7 @@ func ResetDNS() { err := cmd.Run() if err != nil { - log.Errorf("ERROR resetting DNS", err) + log.Errorf("ERROR resetting DNS: %v", err) } } diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 100f406a..fc65dbbf 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -24,6 +24,7 @@ import ( "fmt" "github.com/Microsoft/go-winio" "github.com/netfoundry/ziti-foundation/identity/identity" + idcfg "github.com/netfoundry/ziti-sdk-golang/ziti/config" "github.com/netfoundry/ziti-sdk-golang/ziti/enroll" "github.com/netfoundry/ziti-tunnel-win/service/cziti" "github.com/netfoundry/ziti-tunnel-win/service/cziti/windns" @@ -38,6 +39,7 @@ import ( "math/rand" "net" "os" + "os/signal" "strings" "time" ) @@ -140,15 +142,20 @@ func SubMain(ops chan string, changes chan<- svc.Status) error { return nil } func waitForStopRequest(ops <-chan string) { - + sig := make(chan os.Signal) + signal.Notify(sig) loop: for { - c := <-ops - log.Infof("request for control received: %v", c) - if c == "stop" { - break loop - } else { - log.Debug("unexpected operation: " + c) + select { + case c := <-ops: + log.Infof("request for control received: %v", c) + if c == "stop" { + break loop + } else { + log.Debug("unexpected operation: " + c) + } + case s := <-sig: + log.Warnf("signal received! %v", s) } } log.Debugf("wait loop is exiting") @@ -693,6 +700,18 @@ func connectIdentity(id *dto.Identity) { } id.Active = true log.Infof("identity [%s] connected [%t] and set to active [%t]", id.Name, id.Connected, id.Active) + + events.broadcast <- dto.IdentityEvent{ + ActionEvent: IDENTITY_ADDED, + Id: dto.Identity{ + Name: id.Name, + FingerPrint: id.FingerPrint, + Active: id.Active, + Config: idcfg.Config{}, + Status: "enrolled", + Services: id.Services, + }, + } } func disconnectIdentity(id *dto.Identity) error { diff --git a/service/ziti-tunnel/service/state.go b/service/ziti-tunnel/service/state.go index 9d919cdd..77aa94e6 100644 --- a/service/ziti-tunnel/service/state.go +++ b/service/ziti-tunnel/service/state.go @@ -21,7 +21,6 @@ import ( "bufio" "encoding/json" "fmt" - idcfg "github.com/netfoundry/ziti-sdk-golang/ziti/config" "github.com/netfoundry/ziti-tunnel-win/service/cziti" "github.com/netfoundry/ziti-tunnel-win/service/ziti-tunnel/config" "github.com/netfoundry/ziti-tunnel-win/service/ziti-tunnel/dto" @@ -198,6 +197,7 @@ func (t *RuntimeState) LoadIdentity(id *dto.Identity) { id.NFContext = ctx id.Connected = true + id.Active = true if ctx == nil { log.Warnf("connecting to identity with fingerprint [%s] did not error but no context was returned", id.FingerPrint) return @@ -216,18 +216,6 @@ func (t *RuntimeState) LoadIdentity(id *dto.Identity) { } else { log.Warnf("NOZITI set to true. this should be only used for debugging") } - - events.broadcast <- dto.IdentityEvent{ - ActionEvent: IDENTITY_ADDED, - Id: dto.Identity{ - Name: id.Name, - FingerPrint: id.FingerPrint, - Active: id.Active, - Config: idcfg.Config{}, - Status: "enrolled", - Services: id.Services, - }, - } } func noZiti() bool { From 485e70545ef74f300af05de3b20da7e56cd02d62 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 25 Jun 2020 00:09:53 -0400 Subject: [PATCH 2/2] updates to the UI for presentation issues --- ZitiTunneler/IdentityDetails.xaml.cs | 11 +++++++++-- ZitiTunneler/IdentityItem.xaml.cs | 14 ++++---------- ZitiTunneler/MainWindow.xaml.cs | 12 +++++++----- ZitiTunneler/Models/UILog.cs | 6 ------ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ZitiTunneler/IdentityDetails.xaml.cs b/ZitiTunneler/IdentityDetails.xaml.cs index db5b9ce5..3c0bd255 100644 --- a/ZitiTunneler/IdentityDetails.xaml.cs +++ b/ZitiTunneler/IdentityDetails.xaml.cs @@ -40,6 +40,7 @@ namespace ZitiTunneler { } set { _identity = value; + this.IdDetailToggle.Enabled = _identity.IsEnabled; UpdateView(); IdentityArea.Opacity = 1.0; IdentityArea.Visibility = Visibility.Visible; @@ -47,6 +48,9 @@ namespace ZitiTunneler { } } + public IdentityItem SelectedIdentity { get; set; } + + public bool IsAttached { get { return _isAttached; @@ -63,8 +67,8 @@ namespace ZitiTunneler { IdDetailToggle.Enabled = _identity.IsEnabled; IdentityName.Value = _identity.Name; IdentityNetwork.Value = _identity.ControllerUrl; - IdentityEnrollment.Value = _identity.EnrollmentStatus; - IdentityStatus.Value = _identity.Status; + IdentityEnrollment.Value = _identity.Status; + IdentityStatus.Value = _identity.IsEnabled ? "active" : "disabled"; ServiceList.Children.Clear(); for (int i=0; i<_identity.Services.Count; i++) { ServiceInfo editor = new ServiceInfo(); @@ -78,6 +82,9 @@ namespace ZitiTunneler { private void IdToggle(bool on) { ServiceClient.Client client = (ServiceClient.Client)Application.Current.Properties["ServiceClient"]; client.IdentityOnOff(_identity.Fingerprint, on); + SelectedIdentity.ToggleSwitch.Enabled = on; + _identity.IsEnabled = on; + IdentityStatus.Value = _identity.IsEnabled ? "active" : "disabled"; } public IdentityDetails() { diff --git a/ZitiTunneler/IdentityItem.xaml.cs b/ZitiTunneler/IdentityItem.xaml.cs index 0569c7e1..e1bcb844 100644 --- a/ZitiTunneler/IdentityItem.xaml.cs +++ b/ZitiTunneler/IdentityItem.xaml.cs @@ -20,8 +20,6 @@ namespace ZitiTunneler { /// public partial class IdentityItem:UserControl { - public delegate void Click(ZitiIdentity identity); - public event Click OnClick; public ZitiIdentity _identity; public ZitiIdentity Identity { get { @@ -45,7 +43,6 @@ namespace ZitiTunneler { } } - public bool isOn = false; public IdentityItem() { InitializeComponent(); ToggleSwitch.OnToggled += ToggleIdentity; @@ -72,10 +69,6 @@ namespace ZitiTunneler { } } - private void ToggleButton_Checked(object sender, RoutedEventArgs e) { - isOn = !isOn; - } - private void Canvas_MouseEnter(object sender, MouseEventArgs e) { OverState.Opacity = 0.2; } @@ -85,9 +78,10 @@ namespace ZitiTunneler { } private void OpenDetails(object sender, MouseButtonEventArgs e) { - if (OnClick != null) { - OnClick(_identity); - } + IdentityDetails deets = ((MainWindow)Application.Current.MainWindow).IdentityMenu; + deets.SelectedIdentity = this; + deets.Identity = this.Identity; + this.ToggleSwitch.IsEnabled = this.Identity.IsEnabled; } } } diff --git a/ZitiTunneler/MainWindow.xaml.cs b/ZitiTunneler/MainWindow.xaml.cs index ac477df1..e4ec807c 100644 --- a/ZitiTunneler/MainWindow.xaml.cs +++ b/ZitiTunneler/MainWindow.xaml.cs @@ -163,6 +163,10 @@ namespace ZitiTunneler { var found = identities.Find(i => i.Fingerprint == e.Id.FingerPrint); if (found == null) { identities.Add(zid); + } else { + //if we get here exit out so that LoadIdentities() doesn't get called + found.IsEnabled = true; + return; } } else { IdentityForgotten(ZitiIdentity.FromClient(e.Id)); @@ -334,7 +338,7 @@ namespace ZitiTunneler { DisconnectButton.Visibility = Visibility.Visible; } id.Identity = ids[i]; - id.OnClick += OpenIdentity; + //id.OnClick += OpenIdentity; IdList.Children.Add(id); IdList.Height += 60; } @@ -345,7 +349,7 @@ namespace ZitiTunneler { private void OpenIdentity(ZitiIdentity identity) { IdentityMenu.Identity = identity; - + } private void ShowMenu(object sender, MouseButtonEventArgs e) { @@ -401,7 +405,7 @@ namespace ZitiTunneler { _timer.Enabled = true; _timer.Start(); } - private async void Connect(object sender, RoutedEventArgs e) + private void Connect(object sender, RoutedEventArgs e) { this.Dispatcher.Invoke(() => { @@ -424,7 +428,6 @@ namespace ZitiTunneler { } for (int i = 0; i < IdList.Children.Count; i++) { IdentityItem item = IdList.Children[i] as IdentityItem; - item.isOn = true; item._identity.IsEnabled = true; item.RefreshUI(); } @@ -448,7 +451,6 @@ namespace ZitiTunneler { } for (int i = 0; i < IdList.Children.Count; i++) { IdentityItem item = IdList.Children[i] as IdentityItem; - item.isOn = false; item._identity.IsEnabled = false; item.RefreshUI(); } diff --git a/ZitiTunneler/Models/UILog.cs b/ZitiTunneler/Models/UILog.cs index 4fbe77b2..fc157a6d 100644 --- a/ZitiTunneler/Models/UILog.cs +++ b/ZitiTunneler/Models/UILog.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.IO; namespace ZitiTunneler.Models {