merge jeremy's latest in

This commit is contained in:
ziti-ci
2020-06-05 12:00:23 -04:00
26 changed files with 2126 additions and 93 deletions
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;
namespace ZitiConsoleApp {
class Program {
private static string _versionUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/maven-metadata.xml";
private static string _serviceUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/${version}/ziti-tunnel-win-${version}.zip";
static void Main(string[] args) {
var request = WebRequest.Create(_versionUrl) as HttpWebRequest;
var response = request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
var result = readStream.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/release");
string version = node.InnerText;
Console.WriteLine(version);
string remoteService = _serviceUrl.Replace("${version}", version);
Console.WriteLine(remoteService);
}
}
}
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;Releases</Configurations>
</PropertyGroup>
</Project>
+6 -1
View File
@@ -10,7 +10,7 @@
<Identity
Name="NetFoundryInc.ZitiTunnel"
Publisher="CN=793EB682-E668-4D33-984F-2399413F3801"
Version="1.0.0.0" />
Version="0.1.1.0" />
<Properties>
<DisplayName>Ziti Tunnel</DisplayName>
@@ -46,6 +46,11 @@
</uap:DefaultTile >
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.appService" Executable="ZitiUpdateService.exe">
<uap:AppService Name="Ziti Update Service"/>
</uap:Extension>
</Extensions>
</Application>
</Applications>
+21
View File
@@ -8,6 +8,26 @@
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Releases|AnyCPU">
<Configuration>Releases</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Releases|ARM">
<Configuration>Releases</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Releases|ARM64">
<Configuration>Releases</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Releases|x64">
<Configuration>Releases</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Releases|x86">
<Configuration>Releases</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
@@ -156,6 +176,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZitiTunneler\ZitiTunneler.csproj" />
<ProjectReference Include="..\ZitiUpdateService\ZitiUpdateService.csproj" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
+3 -2
View File
@@ -45,7 +45,8 @@
<Setter Property="Stylus.IsFlicksEnabled" Value="true" />
<Setter Property="Foreground" Value="LightGray" />
<Setter Property="Background" Value="#000F0F23" />
<Setter Property="Width" Value="6" />
<Setter Property="Width" Value="3" />
<Setter Property="Opacity" Value="0.6"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
@@ -89,7 +90,7 @@
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
<Setter Property="Width" Value="6" />
<Setter Property="Width" Value="3" />
<Setter Property="Height" Value="12" />
<Setter TargetName="Thumb" Property="Tag" Value="Horizontal" />
<Setter TargetName="PageDown" Property="Command" Value="ScrollBar.PageLeftCommand" />
-1
View File
@@ -60,7 +60,6 @@
<local:MenuItem Label="About" Icon="/Assets/Images/about.png" MouseUp="ShowAbout"></local:MenuItem>
<local:MenuItem Label="Feedback" Icon="/Assets/Images/feedback.png" MouseUp="ShowFeedback"></local:MenuItem>
<local:MenuItem Label="Support" Icon="/Assets/Images/support.png" MouseUp="ShowSupport"></local:MenuItem>
<local:MenuItem Label="Reset Network" Icon="/Assets/Images/server.png" MouseUp="ResetNetwork"></local:MenuItem>
<local:MenuItem x:Name="DetachButton" Label="Detach App" Icon="/Assets/Images/detach.png" MouseUp="DetachWindow"></local:MenuItem>
<local:MenuItem x:Name="AttachButton" Label="Attach App" Icon="/Assets/Images/detach.png" MouseUp="RetachWindow" Visibility="Collapsed"></local:MenuItem>
</StackPanel>
-16
View File
@@ -125,22 +125,6 @@ namespace ZitiTunneler
Process.Start(new ProcessStartInfo("https://support.netfoundry.io") { UseShellExecute = true });
}
private void RunScript(string scriptText) {
using (PowerShell PowerShellInstance = PowerShell.Create()) {
PowerShellInstance.AddScript(scriptText);
IAsyncResult result = PowerShellInstance.BeginInvoke();
while (result.IsCompleted==false) {
Console.WriteLine("Waiting for pipeline to finish...");
Thread.Sleep(1000);
}
System.Windows.MessageBox.Show("Network Reset");
}
}
private void ResetNetwork(object sender, MouseButtonEventArgs e) {
RunScript("get-netipinterface|ForEach-Object { Set-DnsClientServerAddress-InterfaceIndex $_.ifIndex-ResetServerAddresses}");
}
private void DetachWindow(object sender, MouseButtonEventArgs e) {
Application.Current.MainWindow.ShowInTaskbar = true;
DetachButton.Visibility = Visibility.Collapsed;
+8 -60
View File
@@ -36,55 +36,10 @@ namespace ZitiTunneler {
}
}
public static bool IsAdministrator() {
using (WindowsIdentity identity = WindowsIdentity.GetCurrent()) {
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
private void UpdateServiceFiles() {
if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "Service"))) Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "Service"));
string[] files = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Service"));
foreach (string file in files) {
File.Delete(file);
Console.WriteLine($"{file} is deleted.");
}
WebClient webClient = new WebClient();
webClient.DownloadFile("https://actieve.com/windows-tunneler.zip", Path.Combine(Environment.CurrentDirectory, "Service")+@"\windows-tunneler.zip");
ZipFile.ExtractToDirectory(Path.Combine(Environment.CurrentDirectory, "Service")+@"\windows-tunneler.zip", Path.Combine(Environment.CurrentDirectory, "Service"));
}
private void LaunchOrInstall() {
ServiceController ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName=="ziti");
if (ctl==null) {
if (IsAdministrator()) {
UpdateServiceFiles();
ProcessStartInfo installService = new ProcessStartInfo();
installService.CreateNoWindow = true;
installService.UseShellExecute = false;
installService.FileName = Path.Combine(Environment.CurrentDirectory, "Service") + @"\ziti-tunnel.exe";
installService.WindowStyle = ProcessWindowStyle.Hidden;
installService.Arguments = "install";
try {
using (Process exeProcess = Process.Start(installService)) {
exeProcess.WaitForExit();
ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "ziti");
if (ctl.Status != ServiceControllerStatus.Running) {
try {
ctl.Start();
} catch (Exception e) {
SetCantDisplay();
}
}
}
} catch (Exception e) {
ShowError("Error Installing Service", e.ToString());
}
} else {
ShowError("Admin Account", "Unable to install service, Admin Account required.");
}
SetCantDisplay();
} else {
if (ctl.Status!=ServiceControllerStatus.Running) {
try {
@@ -260,10 +215,8 @@ namespace ZitiTunneler {
private void IdentityForgotten(ZitiIdentity forgotten) {
ZitiIdentity idToRemove = null;
foreach (var id in identities)
{
if(id.Fingerprint == forgotten.Fingerprint)
{
foreach (var id in identities) {
if(id.Fingerprint == forgotten.Fingerprint) {
idToRemove = id;
break;
}
@@ -301,25 +254,20 @@ namespace ZitiTunneler {
ConnectButton.Visibility = Visibility.Visible;
DisconnectButton.Visibility = Visibility.Collapsed;
}
if (!Application.Current.Properties.Contains("ip"))
{
if (!Application.Current.Properties.Contains("ip")) {
Application.Current.Properties.Add("ip", status?.IpInfo?.Ip);
}
if (!Application.Current.Properties.Contains("subnet"))
{
if (!Application.Current.Properties.Contains("subnet")) {
Application.Current.Properties.Add("subnet", status?.IpInfo?.Subnet);
}
if (!Application.Current.Properties.Contains("mtu"))
{
if (!Application.Current.Properties.Contains("mtu")) {
Application.Current.Properties.Add("mtu", status?.IpInfo?.MTU);
}
if (!Application.Current.Properties.Contains("dns"))
{
if (!Application.Current.Properties.Contains("dns")) {
Application.Current.Properties.Add("dns", status?.IpInfo?.DNS);
}
foreach (var id in status.Identities)
{
foreach (var id in status.Identities) {
updateViewWithIdentity(id);
}
LoadIdentities();
+12 -11
View File
@@ -50,7 +50,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
@@ -69,7 +69,7 @@
</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
@@ -77,6 +77,12 @@
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Releases|AnyCPU'">
<OutputPath>bin\Releases\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Assets\Images\icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -310,7 +316,9 @@
<Resource Include="Assets\Images\Ziti-Green.png" />
<Resource Include="Assets\Images\ziti-red.ico" />
<Resource Include="Assets\Images\Ziti-Red.png" />
<Resource Include="Assets\Images\ziti-white.ico" />
<Resource Include="Assets\Images\ziti-white.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\Images\Ziti-White.png" />
</ItemGroup>
<ItemGroup>
@@ -325,14 +333,7 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<FileAssociation Include=".ziti">
<Visible>False</Visible>
<Description>Ziti Identity</Description>
<Progid>Ziti</Progid>
<DefaultIcon>Assets\Images\ziti-white.ico</DefaultIcon>
</FileAssociation>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Assets\Images\server.png" />
</ItemGroup>
+2 -2
View File
@@ -17,11 +17,11 @@
compatibility.
-->
<!--requestedExecutionLevel level="requireAdministrator" uiAccess="false" /-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

+4
View File
@@ -13,5 +13,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZitiTunneler", "ZitiTunnele
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "ZitiInstaller", "ZitiInstaller\ZitiInstaller.wapproj", "{520E523A-1E9B-4983-ABA9-0EB3B27B6420}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZitiUpdateService", "ZitiUpdateService\ZitiUpdateService.csproj", "{9AB81609-F5DD-40A6-87B5-F3279D48514D}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "ZitiTunnelerSetup", "ZitiTunnelerSetup\ZitiTunnelerSetup.vdproj", "{6ABD9DF3-3298-4038-ABED-B16FFD5FF66D}"
EndProject
Global
EndGlobal
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace ZitiUpdateService {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main() {
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new UpdateService()
};
ServiceBase.Run(ServicesToRun);
}
}
}
+56
View File
@@ -0,0 +1,56 @@
namespace ZitiUpdateService {
partial class ProjectInstaller {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.ZitiUpdateProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.ZitiUpdateServiceInstaller = new System.ServiceProcess.ServiceInstaller();
//
// ZitiUpdateProcessInstaller
//
this.ZitiUpdateProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.ZitiUpdateProcessInstaller.Password = null;
this.ZitiUpdateProcessInstaller.Username = null;
//
// ZitiUpdateServiceInstaller
//
this.ZitiUpdateServiceInstaller.Description = "Keep Ziti Service Software Up To Date";
this.ZitiUpdateServiceInstaller.DisplayName = "Ziti Update Service";
this.ZitiUpdateServiceInstaller.ServiceName = "ZitiUpdateService";
this.ZitiUpdateServiceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.ZitiUpdateServiceInstaller.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.ZitiUpdateServiceInstaller_AfterInstall);
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.ZitiUpdateProcessInstaller,
this.ZitiUpdateServiceInstaller});
}
#endregion
private System.ServiceProcess.ServiceProcessInstaller ZitiUpdateProcessInstaller;
private System.ServiceProcess.ServiceInstaller ZitiUpdateServiceInstaller;
}
}
+20
View File
@@ -0,0 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;
namespace ZitiUpdateService {
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer {
public ProjectInstaller() {
InitializeComponent();
}
private void ZitiUpdateServiceInstaller_AfterInstall(object sender, InstallEventArgs e) {
}
}
}
+129
View File
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ZitiUpdateProcessInstaller.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 56</value>
</metadata>
<metadata name="ZitiUpdateServiceInstaller.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>201, 50</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ZitiUpdateService")]
[assembly: AssemblyDescription("Ziti Monitor and Update Service")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("NetFoundry")]
[assembly: AssemblyProduct("ZitiUpdateService")]
[assembly: AssemblyCopyright("Copyright © NetFoundry 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9ab81609-f5dd-40a6-87b5-f3279d48514d")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+70
View File
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
+32
View File
@@ -0,0 +1,32 @@
namespace ZitiUpdateService {
partial class UpdateService {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
components = new System.ComponentModel.Container();
this.ServiceName = "Ziti Update Service";
}
#endregion
}
}
+225
View File
@@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Timers;
using System.Management.Automation;
using System.Xml;
namespace ZitiUpdateService {
public partial class UpdateService : ServiceBase {
private string _version = "";
private bool _isNew = true;
private int _majorVersion = 1;
private string _versionUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/maven-metadata.xml";
private string _serviceUrl = "https://netfoundry.jfrog.io/netfoundry/ziti-maven-snapshot/ziti-tunnel-win/amd64/windows/ziti-tunnel-win/${version}/ziti-tunnel-win-${version}.zip";
private System.Timers.Timer _checkTimer = new System.Timers.Timer();
private System.Timers.Timer _updateTimer = new System.Timers.Timer();
private string _rootDirectory = "";
private string _logDirectory = "";
private bool _isJustStopped = true;
ServiceController controller;
public UpdateService() {
InitializeComponent();
}
protected override void OnStart(string[] args) {
_rootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "NetFoundry");
if (!Directory.Exists(_rootDirectory)) Directory.CreateDirectory(_rootDirectory);
_logDirectory = Path.Combine(_rootDirectory, "Logs");
if (!Directory.Exists(_logDirectory)) Directory.CreateDirectory(_logDirectory);
Log("Setup Watchers");
SetupServiceWatcher();
}
protected override void OnStop() {
Log("Stopping update Service");
}
private void SetupServiceWatcher() {
controller = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "ziti");
if (controller==null) {
Log("Get Installation");
UpdateServiceFiles();
} else {
Log("Check Version");
_isNew = false;
if (File.Exists(Path.Combine(_rootDirectory, @"Service\Version.txt"))) {
_version = File.ReadAllText(Path.Combine(_rootDirectory, @"Service\Version.txt"));
Log("Version Found: " + _version);
if (controller.Status==ServiceControllerStatus.Stopped) {
StartZiti();
} else {
SetupWatcher();
}
} else {
UpdateServiceFiles();
}
}
}
private void SetupWatcher() {
Log("Ziti Update Setting Up Watchers");
; _checkTimer = new System.Timers.Timer();
_checkTimer.Elapsed += CheckService;
_checkTimer.Interval = 60000;
_checkTimer.Enabled = true;
_checkTimer.Start();
_updateTimer = new System.Timers.Timer();
_updateTimer.Elapsed += CheckUpdate;
_updateTimer.Interval = 600000;
_updateTimer.Enabled = true;
_updateTimer.Start();
}
private void CheckUpdate(object sender, ElapsedEventArgs e) {
var request = WebRequest.Create(_versionUrl) as HttpWebRequest;
var response = request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
var result = readStream.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/release");
string version = node.InnerText;
Log("Version Checked: " + version+" on "+_version);
if (version != _version) {
StopZiti();
UpdateServiceFiles();
}
}
private void CheckService(object sender, ElapsedEventArgs e) {
controller = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "ziti");
if (controller.Status == ServiceControllerStatus.Stopped|| controller.Status == ServiceControllerStatus.StopPending) {
if (_isJustStopped) {
_isJustStopped = false;
Log("Ziti Service has been stopped, update Network");
RunScript();
}
} else {
if (controller.Status==ServiceControllerStatus.Running) {
_isJustStopped = true;
}
}
}
private void UpdateServiceFiles() {
if (controller!=null) {
controller.Stop();
} else {
GetFiles();
}
}
private void GetFiles() {
var request = WebRequest.Create(_versionUrl) as HttpWebRequest;
var response = request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
var result = readStream.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNode node = xmlDoc.SelectSingleNode("metadata/versioning/release");
string version = node.InnerText;
Log("Got Version: " + version);
string remoteService = _serviceUrl.Replace("${version}", version);
if (!Directory.Exists(Path.Combine(_rootDirectory, "Service"))) Directory.CreateDirectory(Path.Combine(_rootDirectory, "Service"));
string[] files = Directory.GetFiles(Path.Combine(_rootDirectory, "Service"));
foreach (string file in files) {
try {
Log("Delete: " + file);
File.Delete(file);
} catch (Exception e) {
EventLog.WriteEntry("Ziti", e.ToString(), EventLogEntryType.Error);
}
}
WebClient webClient = new WebClient();
webClient.DownloadFile(remoteService, Path.Combine(_rootDirectory, "Service") + @"\windows-tunneler.zip");
Log("Zip Downloaded");
ZipFile.ExtractToDirectory(Path.Combine(_rootDirectory, "Service") + @"\windows-tunneler.zip", Path.Combine(_rootDirectory, "Service"));
Log("Zip UnZipped");
File.WriteAllText(Path.Combine(_rootDirectory, @"Service\Version.txt"), version);
_version = version;
if (_isNew) {
Log("Installing Service " + _version);
ProcessStartInfo installService = new ProcessStartInfo();
installService.CreateNoWindow = true;
installService.UseShellExecute = true;
installService.FileName = Path.Combine(_rootDirectory, "Service") + @"\ziti-tunnel.exe";
installService.WindowStyle = ProcessWindowStyle.Hidden;
installService.Arguments = "install";
Log("Install Using " + installService.FileName + " " + installService.Arguments);
try {
Process exeProcess = Process.Start(installService);
exeProcess.WaitForExit();
StartZiti();
Log("Installed " + installService.FileName + " " + installService.Arguments);
} catch (Exception e) {
Log("Cannot Install Service - " + e.ToString());
}
} else {
StartZiti();
}
}
private void RunScript() {
string scriptText = "get-netipinterface|ForEach-Object { Set-DnsClientServerAddress-InterfaceIndex $_.ifIndex-ResetServerAddresses}";
Log("Executing: " + scriptText);
using (PowerShell PowerShellInstance = PowerShell.Create()) {
PowerShellInstance.AddScript(scriptText);
IAsyncResult result = PowerShellInstance.BeginInvoke();
while (result.IsCompleted == false) {
Thread.Sleep(1000);
}
}
}
private void StartZiti() {
controller = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "ziti");
if (controller.Status != ServiceControllerStatus.Running) {
try {
Log("Starting Service");
controller.Start();
controller.WaitForStatus(ServiceControllerStatus.Running);
SetupWatcher();
} catch (Exception e) {
Log("Cannot Start Service - " + e.ToString());
}
}
}
private void StopZiti() {
controller = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "ziti");
if (controller.Status != ServiceControllerStatus.Stopped) {
try {
controller.Stop();
controller.WaitForStatus(ServiceControllerStatus.Stopped);
} catch (Exception e) {
Log("Cannot Stop Service - " + e.ToString());
}
}
}
private void Log(string message) {
File.AppendAllText(Path.Combine(_logDirectory, @"Log.log"), DateTime.Now.ToString()+" "+message);
EventLog.WriteEntry("Ziti Update Service", message, EventLogEntryType.Information);
}
}
}
+137
View File
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9AB81609-F5DD-40A6-87B5-F3279D48514D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ZitiUpdateService</RootNamespace>
<AssemblyName>ZitiUpdateService</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>ziti-white.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>189AAD422A106DC81E8E79C7E0D2118CEB2E6321</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>
</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Releases|AnyCPU'">
<OutputPath>bin\Releases\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Management" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ProjectInstaller.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ProjectInstaller.Designer.cs">
<DependentUpon>ProjectInstaller.cs</DependentUpon>
</Compile>
<Compile Include="UpdateService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UpdateService.Designer.cs">
<DependentUpon>UpdateService.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="ZitiUpdateService_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ProjectInstaller.resx">
<DependentUpon>ProjectInstaller.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="ziti-white.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.PowerShell.5.ReferenceAssemblies" version="1.1.0" targetFramework="net48" />
</packages>
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB