Skip to content

Commit b99d25b

Browse files
committed
bug fixes
1 parent 1ce1561 commit b99d25b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1021
-568
lines changed

RemoteDesktopServer_Library/BaseServer.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void RemoteDesktop::BaseServer::_ConnectWrapper(unsigned short port, std::wstrin
111111
}
112112
void RemoteDesktop::BaseServer::_HandleDisconnects_DesktopSwitches(){
113113
if (!_DesktopMonitor->Is_InputDesktopSelected()) _DesktopMonitor->Switch_to_Desktop(DesktopMonitor::Desktops::INPUT);
114-
114+
115115
//handle client disconnects here
116116
if (!_DisconectClientList.empty()){
117117
std::lock_guard<std::mutex> lock(_DisconectClientLock);
@@ -203,7 +203,7 @@ bool RemoteDesktop::BaseServer::_Listen(unsigned short port){
203203
SocketArray.push_back(std::make_shared<SocketHandler>(listensocket, false));
204204

205205
WSANETWORKEVENTS NetworkEvents;
206-
206+
int counter = 0;
207207
while (Running && !EventArray.empty()) {
208208

209209
auto Index = WSAWaitForMultipleEvents(EventArray.size(), EventArray.data(), FALSE, 1000, FALSE);
@@ -232,14 +232,17 @@ bool RemoteDesktop::BaseServer::_Listen(unsigned short port){
232232
_OnDisconnectHandler(SocketArray[Index].get());
233233
}
234234
}
235-
_HandleDisconnects_DesktopSwitches();
236-
if (Index == WSA_WAIT_TIMEOUT)
237-
{//this will check every timeout... which is good
238-
std::lock_guard<std::mutex> lo(_SocketArrayLock);
239-
for (auto& c : SocketArray) {
240-
c->CheckState();
241-
}
235+
if (counter++ > 5 || Index == WSA_WAIT_TIMEOUT){
236+
DEBUG_MSG("Checking Timeouts!");
237+
_HandleDisconnects_DesktopSwitches();
238+
239+
std::lock_guard<std::mutex> lo(_SocketArrayLock);
240+
for (auto& c : SocketArray) {
241+
c->CheckState();
242+
}
243+
242244
}
245+
243246
}
244247

245248
DEBUG_MSG("_Listen Exiting");

RemoteDesktopServer_Library/MainServer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
void RemoteDesktop::Startup(LPWSTR* argv, int argc, bool startasproxy){
1010

11-
11+
#if !_DEBUG
12+
if (RemoteDesktop::TryToElevate(argv, argc)) return;//if the app was able to elevate, shut this instance down
13+
#endif
1214
if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
1315
{
1416
if (_wcsicmp(L"uninstall", argv[1] + 1) == 0) UninstallService(Service_Name());
@@ -25,30 +27,28 @@ void RemoteDesktop::Startup(LPWSTR* argv, int argc, bool startasproxy){
2527
else if (_wcsicmp(L"run", argv[1] + 1) == 0)
2628
{
2729
auto _Server = std::make_unique<RemoteDesktop::RD_Server>();
28-
2930
if (startasproxy) _Server->Listen(DefaultPort(), DefaultGateway(), startasproxy);
3031
else _Server->Listen(DefaultPort());
3132
}
3233
}
3334
else
3435
{
35-
36-
auto msg = std::to_wstring(DefaultPort()) + L" " + std::wstring(DefaultGateway()) + L" " + std::wstring(DefaultProxyGetSessionURL());
36+
3737
auto ret = IDYES;
3838
if (startasproxy){
3939
ret = MessageBox(
4040
NULL,
41-
msg.c_str(),
41+
DisclaimerMessage(),
4242
(LPCWSTR)L"Disclaimer",
4343
MB_ICONQUESTION | MB_YESNO
4444
);
4545
}
46-
4746
//try to install the service if launched normally. If the service cannot be installed it is because its already installed, or the progrm was not launched with correct permissions.
4847
//in which case, try to launch the program normally.
4948
if (ret == IDYES){
5049
//the below line was added so that in cases where UAC is required to access the network, it will activate the pop up as early as possible
5150
RemoteDesktop::PrimeNetwork(DefaultPort());
51+
5252
if (!InstallService(
5353
Service_Name(), // Name of service
5454
Service_Display_Name(), // Name to display

RemoteDesktopServer_Library/RD_Server.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,11 @@ void RemoteDesktop::RD_Server::_Handle_ConnectionInfo(Packet_Header* header, con
244244
memcpy(&h, data, header->PayloadLen);
245245
h.UserName[UNAMELEN] = 0;
246246
sh->UserName = std::wstring(h.UserName);
247-
auto con = sh->UserName + L" has connected to your machine . . .";
248-
_SystemTray->Popup(L"Connection Established", con.c_str(), 2000);
247+
if (sh->UserName.size() > 2){
248+
auto con = sh->UserName + L" has connected to your machine . . .";
249+
_SystemTray->Popup(L"Connection Established", con.c_str(), 2000);
250+
}
251+
249252
}
250253
void RemoteDesktop::RD_Server::OnReceive(Packet_Header* header, const char* data, std::shared_ptr<SocketHandler>& sh) {
251254
switch (header->Packet_Type){
@@ -282,7 +285,7 @@ void RemoteDesktop::RD_Server::OnReceive(Packet_Header* header, const char* data
282285
}
283286
}
284287
void RemoteDesktop::RD_Server::OnDisconnect(std::shared_ptr<SocketHandler>& sh) {
285-
if (!sh->UserName.empty()){
288+
if (sh->UserName.size()>2){
286289
auto con = sh->UserName + L" has Disconnected from your machine . . .";
287290
_SystemTray->Popup(L"Connection Disconnected", con.c_str(), 2000);
288291
}
Binary file not shown.

RemoteDesktopServer_Library/ServiceInstaller.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ bool InstallService(PWSTR pszServiceName,
3131
{
3232
wchar_t szPath[MAX_PATH];
3333
bool ret = false;
34-
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)) == 0) wprintf(L"GetModuleFileName failed w/err 0x%08lx\n", GetLastError());
35-
34+
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)) == 0) {
35+
wprintf(L"GetModuleFileName failed w/err 0x%08lx\n", GetLastError());
36+
return false;
37+
}
3638
auto schSCManager=RAIISC_HANDLE(OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE));
3739
if (schSCManager.get() == nullptr) wprintf(L"OpenSCManager failed w/err 0x%08lx\n", GetLastError());
3840
else {

RemoteDesktopServer_Library/SystemTray.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void RemoteDesktop::SystemTray::_Run(){
167167
MSG msg;
168168
while (_Running && (GetMessage(&msg, Hwnd, 0, 0) != 0))
169169
{
170+
170171
TranslateMessage(&msg);
171172
DispatchMessage(&msg);
172173
}
@@ -177,6 +178,7 @@ void RemoteDesktop::SystemTray::AddMenuItem(const wchar_t* itemname, Delegate<vo
177178
CallBacks.push_back(cb);
178179
}
179180
void RemoteDesktop::SystemTray::Popup(const wchar_t* title, const wchar_t* message, unsigned int timeout){
181+
180182
if (!_TrayIconCreated) return;
181183
NOTIFYICONDATA ni;
182184
memset(&ni, 0, sizeof(NOTIFYICONDATA));

RemoteDesktopServer_Library/logo.bmp

0 Bytes
Binary file not shown.

RemoteDesktopViewer_Library/BaseClient.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void RemoteDesktop::BaseClient::Connect(std::wstring host, std::wstring port, in
3030
void RemoteDesktop::BaseClient::_RunWrapper(int dst_id, std::wstring aeskey){
3131
int counter = 0;
3232

33-
while (Running && ++counter< MaxConnectAttempts){
33+
while (Running && ++counter < MaxConnectAttempts){
3434
DEBUG_MSG("Connect Loop % ", dst_id);
3535
_OnConnectingAttempt(counter, MaxConnectAttempts);
3636
if (!_Connect(dst_id, aeskey)){
@@ -55,15 +55,15 @@ bool RemoteDesktop::BaseClient::_Connect(int dst_id, std::wstring aeskey){
5555
Socket->Connected_CallBack = DELEGATE(&RemoteDesktop::BaseClient::_OnConnectHandler, this);
5656
Socket->Receive_CallBack = DELEGATE(&RemoteDesktop::BaseClient::_OnReceiveHandler, this);
5757
Socket->Disconnect_CallBack = DELEGATE(&RemoteDesktop::BaseClient::_OnDisconnectHandler, this);
58-
58+
5959
Socket->Exchange_Keys(dst_id, -1, aeskey);
6060
return true;
6161
}
6262
void RemoteDesktop::BaseClient::_Run(){
6363
auto newevent = WSACreateEvent();
6464

6565
WSAEventSelect(Socket->get_Socket(), newevent, FD_CLOSE | FD_READ);
66-
66+
int counter = 0;
6767
WSANETWORKEVENTS NetworkEvents;
6868
DEBUG_MSG("Starting Loop");
6969

@@ -81,11 +81,14 @@ void RemoteDesktop::BaseClient::_Run(){
8181
else if (((NetworkEvents.lNetworkEvents & FD_CLOSE) == FD_CLOSE) && NetworkEvents.iErrorCode[FD_CLOSE_BIT] == ERROR_SUCCESS){
8282
break;// get out of loop and try reconnecting
8383
}
84-
}
85-
if (Index == WSA_WAIT_TIMEOUT)
86-
{//this will check every timeout... which is good
84+
}
85+
if (counter++ > 5 || Index == WSA_WAIT_TIMEOUT){
86+
DEBUG_MSG("Checking Timeouts!");
8787
Socket->CheckState();
88+
counter = 0;
8889
}
90+
91+
8992
}
9093
DEBUG_MSG("Ending Loop");
9194
WSACloseEvent(newevent);
@@ -118,7 +121,7 @@ void RemoteDesktop::BaseClient::Send(NetworkMessages m, NetworkMsg& msg){
118121
}
119122

120123
void RemoteDesktop::BaseClient::Stop() {
121-
Running = false;
124+
Running = false;
122125
if (std::this_thread::get_id() != _BackGroundNetworkWorker.get_id()){
123126
if (_BackGroundNetworkWorker.joinable()) _BackGroundNetworkWorker.join();
124127
}

RemoteDesktop_CSLibrary/RemoteDesktop_CSLibrary.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{7BE9D1DD-5D03-4070-B471-F4BF98C408D3}</ProjectGuid>
7+
<ProjectGuid>{8E748DA1-9A21-42C7-B89A-94CB72BC954F}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>RemoteDesktop_CSLibrary</RootNamespace>
Binary file not shown.

RemoteDesktop_GatewayExample/Controllers/HomeController.cs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class HomeController : Controller
1111
// GET: Home
1212
public ActionResult Index()
1313
{
14-
var testing = new RemoteDesktop_CSLibrary.Client();
1514
return View();
1615
}
1716
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Security;
7+
8+
namespace RemoteDesktop_GatewayExample.Controllers
9+
{
10+
#if !DEBUG
11+
[RequireHttps]
12+
#endif
13+
public class SupportController : RemoteDesktop_GatewayServer.Controllers.RAT_SupportBaseController
14+
{
15+
16+
public new ActionResult GetID(string computername, string username, string mac, string session)
17+
{
18+
return base.GetID(computername, username, mac, session);
19+
}
20+
21+
public new ActionResult GetP2P_File()
22+
{
23+
return base.GetP2P_File();
24+
}
25+
public new ActionResult GetGateway_File()
26+
{
27+
return base.GetGateway_File();
28+
29+
}
30+
31+
public new ActionResult Authenticate(string Username, string Password)
32+
{
33+
//BOGUS TEST BELOW>>> CHANGE TO DO REAL AUTH
34+
bool result = !string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password);
35+
36+
if(result)
37+
{
38+
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
39+
1,
40+
Username,
41+
DateTime.Now,
42+
DateTime.Now.AddHours(5),//expiration date
43+
false,
44+
"Rat_Viewer_Group",
45+
FormsAuthentication.FormsCookiePath);
46+
string encTicket = FormsAuthentication.Encrypt(ticket);
47+
48+
// Create the cookie.
49+
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
50+
//add cookie to response
51+
}
52+
return new EmptyResult();
53+
}
54+
}
55+
}

RemoteDesktop_GatewayExample/Global.asax.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected void Application_Start()
1616
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
1717
RouteConfig.RegisterRoutes(RouteTable.Routes);
1818
BundleConfig.RegisterBundles(BundleTable.Bundles);
19-
19+
RemoteDesktop_GatewayExample.Models.RAT_Auth.Setup();
2020
}
2121
}
2222
}

RemoteDesktop_GatewayExample/Models/AccountViewModels.cs

-112
This file was deleted.

0 commit comments

Comments
 (0)