checkpoint to start testing with UI more

This commit is contained in:
dovholuknf
2020-04-21 00:44:21 -04:00
parent 03c3eefcd2
commit 1631b69dd6
3 changed files with 116 additions and 39 deletions
+39 -6
View File
@@ -18,7 +18,7 @@ namespace ZitiTunneler {
public System.Windows.Forms.NotifyIcon notifyIcon;
private DateTime _startDate;
private System.Windows.Forms.Timer _timer;
private ServiceClient.Client serviceClient = null;
private Client serviceClient = null;
private List<ZitiIdentity> identities
{
@@ -65,10 +65,18 @@ namespace ZitiTunneler {
this.Top = desktopWorkingArea.Bottom-this.Height-25;
// add a new service client
serviceClient = new ServiceClient.Client();
serviceClient = new Client();
Application.Current.Properties.Add("ServiceClient", serviceClient);
Application.Current.Properties.Add("Identities", new List<ZitiIdentity>());
LoadStatusFromService();
try
{
LoadStatusFromService();
}
catch
{
//probably some kind of problem with the service...
MessageBox.Show("oh my goodness - problem with the service. Almost certainly means the service is NOT RUNNING... Jeremy make this pretty");
}
LoadIdentities();
}
@@ -125,7 +133,32 @@ namespace ZitiTunneler {
jwtDialog.Filter = "Ziti Identities (*.jwt)|*.jwt";
if (jwtDialog.ShowDialog() == true) {
string fileContent = File.ReadAllText(jwtDialog.FileName);
// Clint!! AxedaBuddy - What to do with the jwt file?
// Jeremy!! AxedaBuddy - DUN!
try
{
Identity createdId = serviceClient.AddIdentity(System.IO.Path.GetFileName(jwtDialog.FileName), false, fileContent);
if (createdId != null)
{
identities.Add(ZitiIdentity.FromClient(createdId));
MessageBox.Show("New identity added with fingerprint: " + createdId.FingerPrint);
updateViewWithIdentity(createdId);
}
else
{
// Jeremy buddy - error popup here
MessageBox.Show("created id was null - wtf jeremy. your fault");
}
}
catch (ServiceException se)
{
MessageBox.Show(se.AdditionalInfo, se.Message);
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error", ex.Message);
}
LoadIdentities();
}
}
@@ -144,7 +177,7 @@ namespace ZitiTunneler {
{
serviceClient.SetTunnelState(true);
}
catch (ServiceClient.ServiceException se)
catch (ServiceException se)
{
MessageBox.Show(se.AdditionalInfo, se.Message);
}
@@ -175,7 +208,7 @@ namespace ZitiTunneler {
{
serviceClient.SetTunnelState(false);
}
catch (ServiceClient.ServiceException se)
catch (ServiceException se)
{
MessageBox.Show(se.AdditionalInfo, se.Message);
}
+76 -32
View File
@@ -24,7 +24,7 @@ namespace ZitiTunneler.ServiceClient
const string logPipe = @"NetFoundry\tunneler\logs";
const string localPipeServer = ".";
const PipeDirection inOut = PipeDirection.InOut;
const int ServiceConnectTimeout = 5000;
const int ServiceConnectTimeout = 500;
NamedPipeClientStream pipeClient = null;
StreamWriter writer = null;
@@ -40,22 +40,52 @@ namespace ZitiTunneler.ServiceClient
{
lock (namedPipeSyncLock)
{
if(pipeClient != null)
if (pipeClient != null)
{
pipeClient.Dispose();
}
pipeClient = new NamedPipeClientStream(localPipeServer, ipcPipe, inOut);
writer = new StreamWriter(pipeClient);
reader = new StreamReader(pipeClient);
pipeClient.Connect(ServiceConnectTimeout);
try
{
pipeClient.Connect(ServiceConnectTimeout);
}
catch
{
//todo: better error
Debug.WriteLine("There was a problem connecting to the service");
reader.Close();
try
{
writer.Close();
}
catch
{
//intentionally ignored
}
pipeClient.Close();
reader = null;
writer = null;
pipeClient = null;
}
}
}
public ZitiTunnelStatus GetStatus()
{
send(new ServiceFunction() { Function = "Status" });
var rtn = read<ZitiTunnelStatus>();
return rtn;
try
{
send(new ServiceFunction() { Function = "Status" });
var rtn = read<ZitiTunnelStatus>();
return rtn;
}
catch (IOException ioe)
{
//almost certainly a problem with the pipe - recreate the pipe...
setupPipe();
throw ioe;
}
}
ServiceFunction AddIdentityFunction = new ServiceFunction() { Function = "AddIdentity" };
@@ -78,21 +108,18 @@ namespace ZitiTunneler.ServiceClient
}
};
//serializer.Serialize(Console.Out, newId);
send(AddIdentityFunction);
send(newId);
var resp = read<NewIdentityResponse>();
//NewIdentityResponse nidresp = (NewIdentityResponse)serializer.Deserialize(sr, typeof(NewIdentityResponse));
Debug.WriteLine(resp.ToString());
return resp.Payload;
}
catch(IOException ioe)
catch (IOException ioe)
{
//almost certainly a problem with the pipe - recreate the pipe...
setupPipe();
throw ioe;
throw;
}
}
@@ -140,26 +167,34 @@ namespace ZitiTunneler.ServiceClient
public string GetLogs()
{
NamedPipeClientStream logClient = new NamedPipeClientStream(localPipeServer, logPipe, PipeDirection.In);
reader = new StreamReader(logClient);
logClient.Connect(ServiceConnectTimeout);
/*
string line = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
do
try
{
line = reader.ReadLine();
sb.Append(line);
sb.Append("\r\n");
Debug.WriteLine(line);
} while (line != null);
*/
string content = reader.ReadToEnd();
//string content = sb.ToString();
//ugly hack to turn ansi escaping to not... _bleck_
//todo: fix this :point_up:
content = new System.Text.RegularExpressions.Regex(@"\x1B\[[^@-~]*[@-~]").Replace(content, "");
return content;
NamedPipeClientStream logClient = new NamedPipeClientStream(localPipeServer, logPipe, PipeDirection.In);
reader = new StreamReader(logClient);
logClient.Connect(ServiceConnectTimeout);
/*
string line = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
do
{
line = reader.ReadLine();
sb.Append(line);
sb.Append("\r\n");
Debug.WriteLine(line);
} while (line != null);
*/
string content = reader.ReadToEnd();
//string content = sb.ToString();
//ugly hack to turn ansi escaping to not... _bleck_
//todo: fix this :point_up:
content = new System.Text.RegularExpressions.Regex(@"\x1B\[[^@-~]*[@-~]").Replace(content, "");
return content;
}
catch
{
//almost certainly a problem with the pipe - probably means the service is NOT running
return "Error fetching logs from service. Is it running?";
}
}
public void IdentityOnOff(Identity id)
@@ -320,14 +355,23 @@ namespace ZitiTunneler.ServiceClient
string json = JsonConvert.SerializeObject(objToSend, Formatting.Indented);
Debug.WriteLine(json);
serializer.Serialize(writer, objToSend);
try
{
serializer.Serialize(writer, objToSend);
}
catch
{
//if this fails it's usually because the writer is null/invalid. throwing IOException
//will trigger the pipe to rebuild
throw new IOException("Unexpected error when sending data to service");
}
writer.Flush();
}
private T read<T>() where T : SvcResponse
{
T resp = (T)serializer.Deserialize(reader, typeof(T));
if(resp.Code != 0)
if (resp.Code != 0)
{
throw new ServiceException(resp.Message, resp.Code, resp.Error);
}
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="go build main.go" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
<module name="wintun-testing" />
<working_directory value="$PROJECT_DIR$/" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<envs>
<env name="PATH" value="v:\dev\tools\mingw-w64\bin" />