diff --git a/.vs/TeamviewerExporter/v15/.suo b/.vs/TeamviewerExporter/v15/.suo new file mode 100644 index 0000000..d77b636 Binary files /dev/null and b/.vs/TeamviewerExporter/v15/.suo differ diff --git a/TeamviewerExporter.sln b/TeamviewerExporter.sln new file mode 100644 index 0000000..981b7b4 --- /dev/null +++ b/TeamviewerExporter.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamviewerExporter", "TeamviewerExporter\TeamviewerExporter.csproj", "{D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D08A2A84-18DA-4C00-BA0A-AA73188E0E3B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/TeamviewerExporter/Devices.cs b/TeamviewerExporter/Devices.cs new file mode 100644 index 0000000..58532b7 --- /dev/null +++ b/TeamviewerExporter/Devices.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamviewerExporter +{ + public class Device + { + public string remotecontrol_id { get; set; } + public string device_id { get; set; } + public string alias { get; set; } + public string groupid { get; set; } + public string online_state { get; set; } + public bool assigned_to { get; set; } + public string supported_features { get; set; } + public string description { get; set; } + + public string remotecontrol_id_clean { get; set; } + public string groupname { get; set; } + } + + public class Devices + { + public List devices { get; set; } + } +} diff --git a/TeamviewerExporter/ExportToRdm.cs b/TeamviewerExporter/ExportToRdm.cs new file mode 100644 index 0000000..d44dbf5 --- /dev/null +++ b/TeamviewerExporter/ExportToRdm.cs @@ -0,0 +1,47 @@ +using CsvHelper.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamviewerExporter +{ + public class ExportToRdm + { + public ExportToRdm() + { + ConnectionType = "TeamViewer"; + //OpenEmbedded = false; + //UserName = Environment.UserName; + + if(!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportDefaultPassword)) + { + TeamViewer_Password = Properties.Settings.Default.ImportDefaultPassword; + } + } + + public string Host { get; set; } + public string Name { get; set; } + public string ConnectionType { get; set; } + public string Group { get; set; } + public string Description { get; set; } + //public bool OpenEmbedded { get; set; } + //public string UserName { get; set; } + //public string Domain { get; set; } + public string TeamViewer_Password { get; set; } + public string TeamViewer_ID { get; set; } + } + + public sealed class MapClass : CsvClassMap + { + /// + /// this mapping class is needed to overwrite header names to the needed ones from remotedesktopmanager + /// + public MapClass() + { + base.AutoMap(); + Map(m => m.TeamViewer_ID).Name(@"TeamViewer\ID"); + Map(m => m.TeamViewer_Password).Name(@"TeamViewer\Password"); + } + } +} diff --git a/TeamviewerExporter/Group.cs b/TeamviewerExporter/Group.cs new file mode 100644 index 0000000..6bb8792 --- /dev/null +++ b/TeamviewerExporter/Group.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TeamviewerExporter +{ + public class Group + { + public string id { get; set; } + public string name { get; set; } + public string permissions { get; set; } + } + + public class Groups + { + public List groups { get; set; } + } +} diff --git a/TeamviewerExporter/Program.cs b/TeamviewerExporter/Program.cs new file mode 100644 index 0000000..f958f13 --- /dev/null +++ b/TeamviewerExporter/Program.cs @@ -0,0 +1,119 @@ +using CsvHelper; +using RestSharp; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace TeamviewerExporter +{ + class Program + { + static void Main(string[] args) + { + try + { + Console.WriteLine("Connecting to teamviewer web api ..."); + RestClient client = new RestClient(Properties.Settings.Default.BaseUrl); + + Console.WriteLine("Getting device list..."); + RestRequest requestDevices = new RestRequest(Properties.Settings.Default.DevicesUrlPart, Method.GET); + requestDevices.AddHeader("Authorization", string.Format("Bearer {0}", Properties.Settings.Default.AuthorizationToken)); + IRestResponse responseDevices = client.Execute(requestDevices); + + Console.WriteLine("Getting groups list..."); + RestRequest requestGroups = new RestRequest(Properties.Settings.Default.GroupsUrlPart, Method.GET); + requestGroups.AddHeader("Authorization", string.Format("Bearer {0}", Properties.Settings.Default.AuthorizationToken)); + IRestResponse responseGroups = client.Execute(requestGroups); + + Console.WriteLine(string.Format("Got {0} entries and {1} groups.", responseDevices.Data.devices.Count, responseGroups.Data.groups.Count)); + + Console.WriteLine("Adding information to original entries..."); + + for (int i = 0; i < responseDevices.Data.devices.Count; i++) + { + // set cleaned teamviewer id + if(char.IsLetter(responseDevices.Data.devices[i].remotecontrol_id[0])) + { + responseDevices.Data.devices[i].remotecontrol_id_clean = responseDevices.Data.devices[i].remotecontrol_id.Substring(1); + } + else + { + responseDevices.Data.devices[i].remotecontrol_id_clean = responseDevices.Data.devices[i].remotecontrol_id; + } + + // write group name + Group inGroup = responseGroups.Data.groups.FirstOrDefault(w => w.id == responseDevices.Data.devices[i].groupid); + if(inGroup != null) + { + responseDevices.Data.devices[i].groupname = inGroup.name; + } + } + + Console.WriteLine("Writing json object to csv file 'original.csv'"); + //TextWriter tw = File.CreateText("original.csv"); + + TextWriter tw = new StreamWriter("original.csv", false, Encoding.UTF8); + + CsvWriter csv = new CsvWriter(tw); + csv.WriteRecords(responseDevices.Data.devices); + csv.Dispose(); + + Console.WriteLine("Wrote original csv file - starting to write RDM import csv."); + + List erdm = new List(); + foreach (TeamviewerExporter.Device dev in responseDevices.Data.devices) + { + ExportToRdm toAdd = new ExportToRdm(); + toAdd.Description = dev.description; + toAdd.Name = dev.alias; + toAdd.TeamViewer_ID = dev.remotecontrol_id_clean; + toAdd.Host = toAdd.TeamViewer_ID; + + if(dev.groupname != null) + { + toAdd.Group = dev.groupname; + } + + erdm.Add(toAdd); + } + + Console.WriteLine("Writing RDM compatible import file 'rdm.csv'"); + //xtWriter rtw = File.CreateText("rdm.csv"); + TextWriter rtw = new StreamWriter("rdm.csv", false, Encoding.UTF8); + CsvWriter rcsv = new CsvWriter(rtw); + rcsv.Configuration.RegisterClassMap(typeof(MapClass)); // add custom mapping for headlines + rcsv.WriteRecords(erdm); // write complete object to disc as csv + rcsv.Dispose(); + + Console.WriteLine("Successfully wrote 'rdm.csv' - application finished successfully"); + } + catch(Exception ex) + { + Console.WriteLine(); + Console.WriteLine(string.Format("SOMETHING HAPPENED{0}{1}", Environment.NewLine, ex.ToString())); + } + finally + { + Console.WriteLine("Press any enter to exit :-)"); + Console.ReadLine(); + } + } + } + + public class EncodingStringWriter : StringWriter + { + private readonly Encoding _encoding; + + public EncodingStringWriter(StringBuilder builder, Encoding encoding) : base(builder) + { + _encoding = encoding; + } + + public override Encoding Encoding + { + get { return _encoding; } + } + } +} diff --git a/TeamviewerExporter/Properties/AssemblyInfo.cs b/TeamviewerExporter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3f3caee --- /dev/null +++ b/TeamviewerExporter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("TeamviewerExporter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TeamviewerExporter")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("d08a2a84-18da-4c00-ba0a-aa73188e0e3b")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TeamviewerExporter/Properties/Settings.Designer.cs b/TeamviewerExporter/Properties/Settings.Designer.cs new file mode 100644 index 0000000..41d901d --- /dev/null +++ b/TeamviewerExporter/Properties/Settings.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace TeamviewerExporter.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1863152-yCthX3KSfWLFJKuT9xMP")] + public string AuthorizationToken { + get { + return ((string)(this["AuthorizationToken"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("https://webapi.teamviewer.com")] + public string BaseUrl { + get { + return ((string)(this["BaseUrl"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("/api/v1/devices")] + public string DevicesUrlPart { + get { + return ((string)(this["DevicesUrlPart"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string ImportDefaultPassword { + get { + return ((string)(this["ImportDefaultPassword"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("/api/v1/groups")] + public string GroupsUrlPart { + get { + return ((string)(this["GroupsUrlPart"])); + } + } + } +} diff --git a/TeamviewerExporter/Properties/Settings.settings b/TeamviewerExporter/Properties/Settings.settings new file mode 100644 index 0000000..3ab2eb9 --- /dev/null +++ b/TeamviewerExporter/Properties/Settings.settings @@ -0,0 +1,21 @@ + + + + + + 1863152-yCthX3KSfWLFJKuT9xMP + + + https://webapi.teamviewer.com + + + /api/v1/devices + + + + + + /api/v1/groups + + + \ No newline at end of file diff --git a/TeamviewerExporter/TeamviewerExporter.csproj b/TeamviewerExporter/TeamviewerExporter.csproj new file mode 100644 index 0000000..216b81a --- /dev/null +++ b/TeamviewerExporter/TeamviewerExporter.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {D08A2A84-18DA-4C00-BA0A-AA73188E0E3B} + Exe + TeamviewerExporter + TeamviewerExporter + v4.0 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\CsvHelper.2.16.3.0\lib\net40\CsvHelper.dll + + + ..\packages\RestSharp.105.2.3\lib\net4\RestSharp.dll + + + + + + + + + + + + + + + + True + True + Settings.settings + + + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + \ No newline at end of file diff --git a/TeamviewerExporter/app.config b/TeamviewerExporter/app.config new file mode 100644 index 0000000..294f9e7 --- /dev/null +++ b/TeamviewerExporter/app.config @@ -0,0 +1,27 @@ + + + + +
+ + + + + + XXXXXXX-XXXXXXXXXXXXXXXXXXXX + + + https://webapi.teamviewer.com + + + /api/v1/devices + + + + + + /api/v1/groups + + + + \ No newline at end of file diff --git a/TeamviewerExporter/obj/Debug/CoreCompileInputs.cache b/TeamviewerExporter/obj/Debug/CoreCompileInputs.cache new file mode 100644 index 0000000..6b42f0d --- /dev/null +++ b/TeamviewerExporter/obj/Debug/CoreCompileInputs.cache @@ -0,0 +1 @@ +edcbbdbb5c8ef5ad2080a5603e03f38cfcbb903e diff --git a/TeamviewerExporter/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/TeamviewerExporter/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..066d25b Binary files /dev/null and b/TeamviewerExporter/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/TeamviewerExporter/packages.config b/TeamviewerExporter/packages.config new file mode 100644 index 0000000..4dabb23 --- /dev/null +++ b/TeamviewerExporter/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file