forked from cedrozor/myrtille
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnterpriseService.cs
207 lines (188 loc) · 7.31 KB
/
EnterpriseService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Myrtille: A native HTML4/5 Remote Desktop Protocol client.
Copyright(c) 2014-2019 Cedric Coste
Copyright(c) 2018 Paul Oliver (Olive Innovations)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using Myrtille.Services.Contracts;
namespace Myrtille.Services
{
public class EnterpriseService : IEnterpriseService
{
public bool GetState()
{
return Program._enterpriseAdapter != null;
}
public EnterpriseSession Authenticate(string username, string password)
{
try
{
Trace.TraceInformation("Requesting authentication of user {0}", username);
var result = Program._enterpriseAdapter.Authenticate(username, password, Program._adminGroup, Program._enterpriseDomain);
if (result != null)
{
result.UserName = username;
}
return result;
}
catch (Exception ex)
{
Trace.TraceError("Failed to authenticate user {0}, ({1})", username, ex);
return null;
}
}
public void Logout(string sessionID)
{
try
{
Program._enterpriseAdapter.Logout(sessionID);
}
catch (Exception ex)
{
Trace.TraceError("Failed to logout session {0}", sessionID, ex);
}
}
public long? AddHost(EnterpriseHostEdit editHost, string sessionID)
{
try
{
Trace.TraceInformation("Add host requested, host {0}", editHost.HostName);
return Program._enterpriseAdapter.AddHost(editHost, sessionID);
}catch(Exception ex)
{
Trace.TraceError("Failed to add host {0}, ({1})",editHost.HostName, ex);
return null;
}
}
public EnterpriseHostEdit GetHost(long hostID, string sessionID)
{
try
{
Trace.TraceInformation("Edit host requested, host {0}", hostID);
return Program._enterpriseAdapter.GetHost(hostID, sessionID);
}
catch (Exception ex)
{
Trace.TraceError("Failed to get host {0}, ({1})", hostID, ex);
return null;
}
}
public bool UpdateHost(EnterpriseHostEdit editHost, string sessionID)
{
try
{
Trace.TraceInformation("Update host requested, host {0}", editHost.HostName);
return Program._enterpriseAdapter.UpdateHost(editHost, sessionID);
}
catch (Exception ex)
{
Trace.TraceError("Failed to update host {0}, ({1})", editHost.HostName, ex);
return false;
}
}
public bool DeleteHost(long hostID, string sessionID)
{
try
{
Trace.TraceInformation("Deleting host");
return Program._enterpriseAdapter.DeleteHost(hostID, sessionID);
}
catch (Exception ex)
{
Trace.TraceError("Unable to delete host {0} ({1})", hostID, ex);
return false;
}
}
public List<EnterpriseHost> GetSessionHosts(string sessionID)
{
try
{
Trace.TraceInformation("Requesting session host list");
return Program._enterpriseAdapter.SessionHosts(sessionID);
}
catch (Exception ex)
{
Trace.TraceError("Unable to get host list {0}", ex);
return new List<EnterpriseHost>();
}
}
public EnterpriseConnectionDetails GetSessionConnectionDetails(string sessionID, long hostID, string sessionKey)
{
try
{
Trace.TraceInformation("Requesting session details");
var result = Program._enterpriseAdapter.GetSessionConnectionDetails(sessionID, hostID, sessionKey);
var domain = ConfigurationManager.AppSettings["EnterpriseDomain"];
var netbiosDomain = ConfigurationManager.AppSettings["EnterpriseNetbiosDomain"];
if (!string.IsNullOrEmpty(netbiosDomain) && !result.PromptForCredentials)
{
result.Domain = netbiosDomain;
}
else if (result != null && domain != null
&& !IPAddress.TryParse(domain, out IPAddress address) //check if domain is IP, prevent login failure if FQDN not used
&& !result.PromptForCredentials) //no need to set this automatically if the user is prompted for credentials
{
result.Domain = domain;
}
return result;
}
catch (Exception ex)
{
Trace.TraceError("Unable to get session connection details {0}", ex);
return null;
}
}
public string CreateUserSession(string sessionID, long hostID, string username, string password)
{
try
{
Trace.TraceInformation("Create user session requested, host {0}, user {1}", hostID, username);
return Program._enterpriseAdapter.CreateUserSession(sessionID,hostID,username,password);
}
catch (Exception ex)
{
Trace.TraceError("Failed to create session {0}, ({1})", hostID, ex);
return null;
}
}
public bool ChangeUserPassword(string username, string oldPassword, string newPassword)
{
try
{
Trace.TraceInformation("Change password for user {0}", username);
return Program._enterpriseAdapter.ChangeUserPassword(username, oldPassword, newPassword, Program._enterpriseDomain);
}
catch (Exception ex)
{
Trace.TraceError("Failed to change password for user {0}, ({1})", username, ex);
return false;
}
}
public bool AddSessionHostCredentials(EnterpriseHostSessionCredentials credentials)
{
try
{
Trace.TraceInformation("creating session credentials for {0}", credentials.Username);
return Program._enterpriseAdapter.AddSessionHostCredentials(credentials);
}
catch (Exception ex)
{
Trace.TraceError("Failed to set session credentials for user {0}, ({1})", credentials.Username, ex);
return false;
}
}
}
}