This repository was archived by the owner on Jul 3, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathuclientmachine.pas
More file actions
168 lines (149 loc) · 4.1 KB
/
Copy pathuclientmachine.pas
File metadata and controls
168 lines (149 loc) · 4.1 KB
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
unit UClientMachine;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, HTTPSend, UVNCView, Forms, UClientStatusThread,
ssl_openssl;
type
TClientMachine = class
private
FOnShowStatus: TShowStatusEvent;
room, name, ip, mac, hostMac, hostIp, serverURL, globalPw: string;
inet, id, isLocked: integer;
online: boolean;
VNC: TVNCView;
procedure doMachineRequest(param: string);
procedure showStatus(status: string);
function sendRequest(url, params: string): string;
function MemStreamToString(Strm: TMemoryStream): AnsiString;
public
constructor create(croom, cname, cip, cmac, chostMac, chostIp, cserverURL, cglobalPw: string; cinet, cid: integer; cscroll: TScrollBox);
function getName:string;
procedure lock(mode: boolean);
procedure lockInet(mode: boolean);
procedure shutdown;
procedure wake;
procedure reposition;
procedure updateStatus;
property OnShowStatus: TShowStatusEvent read FOnShowStatus write FOnShowStatus;
end;
implementation
constructor TClientMachine.create(croom, cname, cip, cmac, chostMac, chostIp, cserverURL, cglobalPw: string; cinet, cid: integer; cscroll: TScrollBox);
begin
room:=croom;
name:=cname;
ip:=cip;
mac:=cmac;
inet:=cinet;
hostMac:=chostMac;
hostIp:=chostIp;
serverURL:=cserverURL;
globalPw:=cglobalPw;
online:=false;
isLocked:=2;
id:=cid;
VNC:=TVNCView.create(id, name, ip, room, cscroll);
end;
function TClientMachine.getName:string;
begin
result:=name;
end;
procedure TClientMachine.lock(mode: boolean);
begin
if (online) then begin
if (mode) then begin
doMachineRequest('lock');
end
else begin
doMachineRequest('unlock');
end;
end;
end;
procedure TClientMachine.lockInet(mode: boolean);
begin
if (mode = true) then begin
sendRequest('https://'+serverURL+'/client.php', 'usage=internet&globalpw='+globalPW+'&machine='+hostMac+'&ip='+hostIp+'&task=single&lock=0&target='+mac);
end
else begin
sendRequest('https://'+serverURL+'/client.php', 'usage=internet&globalpw='+globalPW+'&machine='+hostMac+'&ip='+hostIp+'&task=single&lock=1&target='+mac);
end;
end;
procedure TClientMachine.shutdown;
begin
if (online) then begin
doMachineRequest('shutdown');
end;
end;
procedure TClientMachine.wake;
begin
sendRequest('https://'+serverURL+'/client.php', 'usage=wake&globalpw='+globalPW+'&machine='+hostMac+'&ip='+hostIp+'&targetMac='+mac+'&targetIp='+ip);
end;
procedure TClientMachine.reposition;
begin
VNC.reposition;
end;
procedure TClientMachine.doMachineRequest(param: string);
begin
if (online = true) then begin
sendRequest('http://'+ip+':34567/'+room+'/'+name+'/'+param, '');
end;
end;
procedure TClientMachine.updateStatus;
var
thread: TClientStatusThread;
begin
thread:=TClientStatusThread.create(ip);
thread.OnShowStatus:=@ShowStatus;
thread.resume;
end;
procedure TClientMachine.showStatus(status: string);
var
response, inetVal: string;
begin
response:=sendRequest('https://'+serverURL+'/client.php', 'usage=checkinet&globalpw='+globalPW+'&machine='+hostMac+'&ip='+hostIp+'&hwaddr='+mac);
if (response = '1') then begin
inetVal:='1';
end
else begin
inetVal:='0';
end;
if (status = '0') then begin
online:=false;
isLocked:=2;
VNC.setActive(false);
end
else if (status = '1') then begin
online:=true;
isLocked:=1;
VNC.setActive(true);
end
else if (status = '2') then begin
online:=true;
isLocked:=0;
VNC.setActive(true);
end;
if Assigned(FOnShowStatus) then
begin
FOnShowStatus(status+'&'+IntToStr(id)+'&'+inetVal);
end;
end;
function TClientMachine.sendRequest(url, params: string): string;
var
Response: TMemoryStream;
begin
Response := TMemoryStream.Create;
try
if HttpPostURL(url, params, Response) then
result:=MemStreamToString(Response);
finally
Response.Free;
end;
end;
function TClientMachine.MemStreamToString(Strm: TMemoryStream): AnsiString;
begin
if Strm <> nil then begin
Strm.Position := 0;
SetString(Result, PChar(Strm.Memory), Strm.Size);
end;
end;
end.