1
+ package KeyAuth ;
2
+
3
+ require HTTP::Request;
4
+
5
+ use JSON::MaybeXS qw( encode_json) ;
6
+ use JSON;
7
+ use LWP::UserAgent;
8
+ use Time::Piece;
9
+ use Win32;
10
+
11
+ $Initialized = false;
12
+ my $sessionid = " Null Session" ;
13
+
14
+ my $name = " " ;
15
+ my $ownerid = " " ;
16
+ my $version = " 1.0" ;
17
+
18
+ $AppInfo {' numUsers' } = " " ;
19
+ $AppInfo {' numOnlineUsers' } = " " ;
20
+ $AppInfo {' numKeys' } = " " ;
21
+ $AppInfo {' version' } = $version ;
22
+ $AppInfo {' customerPanelLink' } = " " ;
23
+
24
+ $user_data {' username' } = " " ;
25
+ $user_data {' ip' } = " " ;
26
+ $user_data {' hwid' } = " " ;
27
+ $user_data {' createdate' } = " " ;
28
+ $user_data {' lastlogin' } = " " ;
29
+
30
+ %user_data_Subscriptions = ( );
31
+
32
+ sub Api {
33
+ $appname = $_ [0];
34
+ $appownerid = $_ [1];
35
+ $appsecret = $_ [2];
36
+ $appversion = $_ [3];
37
+
38
+ print ($appname , $appownerid , $appsecret , $appversion );
39
+
40
+ if (!$appname || !$appownerid || !$appsecret || !$appversion ) {
41
+ print (" \n Error: Application is not set up correctly." );
42
+ exit (0);
43
+ };
44
+
45
+ $name = $appname ;
46
+ $ownerid = $appownerid ;
47
+ $version = $appversion ;
48
+ }
49
+
50
+ sub Init {
51
+ my $url = " https://keyauth.win/api/1.1/?type=init&name=${name} &ownerid=${ownerid} &ver=${version} " ;
52
+ $response = Req($url );
53
+
54
+ if ($response -> decoded_content =~ " KeyAuth_Invalid" ) {
55
+ print (" Error: Application not found" );
56
+ exit (0);
57
+ }
58
+
59
+ my $json = decode_json($response -> content);
60
+
61
+ if ($json -> {' success' }) {
62
+
63
+ $Initialized = true;
64
+ $sessionid = $json -> {' sessionid' };
65
+ Load_AppInfo(encode_json($json -> {' appinfo' }));
66
+ } elsif ($json -> {' message' } == " invalidver" ) {
67
+ print (" Error: Invalid version" );
68
+ exit (0);
69
+ } else {
70
+ print (" Error: " . $json -> {' message' });
71
+ exit (0);
72
+ }
73
+ }
74
+
75
+ sub Upgrade {
76
+ $Username = $_ [0];
77
+ $Key = $_ [1];
78
+
79
+ my $url = " https://keyauth.win/api/1.1/?type=upgrade&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &key=${Key} &username=${Username} " ;
80
+ $response = Req($url );
81
+ my $json = decode_json($response -> content);
82
+
83
+ if ($json -> {' success' }) {
84
+ print (" Successfully upgraded!" );
85
+ exit (0);
86
+ } else {
87
+ print (" Error: " . $json -> {' message' });
88
+ exit (0);
89
+ }
90
+ }
91
+
92
+ sub Login {
93
+ $Username = $_ [0];
94
+ $Password = $_ [1];
95
+
96
+ $hwid = GetHwid();
97
+
98
+ my $url = " https://keyauth.win/api/1.1/?type=login&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &username=${Username} &pass=${Password} &hwid=${hwid} " ;
99
+ $response = Req($url );
100
+ my $json = decode_json($response -> content);
101
+
102
+ if ($json -> {' success' }) {
103
+ Load_UserData(encode_json($json -> {' info' }));
104
+ } else {
105
+ print (" \n Error: " . $json -> {' message' });
106
+ exit (0);
107
+ }
108
+ }
109
+
110
+ sub Register {
111
+ $Username = $_ [0];
112
+ $Password = $_ [1];
113
+ $Key = $_ [2];
114
+
115
+ $hwid = GetHwid();
116
+
117
+ my $url = " https://keyauth.win/api/1.1/?type=register&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &username=${Username} &pass=${Password} &key=${Key} &hwid=${hwid} " ;
118
+ $response = Req($url );
119
+ my $json = decode_json($response -> content);
120
+
121
+ if ($json -> {' success' }) {
122
+ Load_UserData(encode_json($json -> {' info' }));
123
+ } else {
124
+ print (" \n Error: " . $json -> {' message' });
125
+ exit (0);
126
+ }
127
+ }
128
+
129
+ sub License {
130
+ $key = $_ [0];
131
+
132
+ $hwid = GetHwid();
133
+
134
+ my $url = " https://keyauth.win/api/1.1/?type=license&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &key=${key} &hwid=${hwid} " ;
135
+ $response = Req($url );
136
+ my $json = decode_json($response -> content);
137
+
138
+ if ($json -> {' success' }) {
139
+ Load_UserData(encode_json($json -> {' info' }));
140
+ } else {
141
+ print (" \n Error: " . $json -> {' message' });
142
+ exit (0);
143
+ }
144
+ }
145
+
146
+ sub Var {
147
+ $varid = $_ [0];
148
+
149
+ my $url = " https://keyauth.win/api/1.1/?type=var&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &varid=${varid} " ;
150
+ $response = Req($url );
151
+ my $json = decode_json($response -> content);
152
+
153
+ if ($json -> {' success' }) {
154
+ return $json -> {' message' };
155
+ } else {
156
+ return " " ;
157
+ }
158
+ }
159
+
160
+ sub Setvar {
161
+ $varid = $_ [0];
162
+ $data = $_ [1];
163
+
164
+ my $url = " https://keyauth.win/api/1.1/?type=setvar&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &var=${varid} &data=${data} " ;
165
+ $response = Req($url );
166
+ my $json = decode_json($response -> content);
167
+
168
+ if ($json -> {' success' }) {
169
+ return true;
170
+ } else {
171
+ return false;
172
+ }
173
+ }
174
+
175
+ sub Getvar {
176
+ $varid = $_ [0];
177
+
178
+ my $url = " https://keyauth.win/api/1.1/?type=getvar&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &var=${varid} " ;
179
+ $response = Req($url );
180
+ my $json = decode_json($response -> content);
181
+
182
+ if ($json -> {' success' }) {
183
+ return $json -> {' message' };
184
+ } else {
185
+ return " " ;
186
+ }
187
+ }
188
+
189
+ sub Check {
190
+ $hwid = GetHwid();
191
+
192
+ my $url = " https://keyauth.win/api/1.1/?type=check&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &hwid=${hwid} " ;
193
+ $response = Req($url );
194
+ my $json = decode_json($response -> content);
195
+
196
+ if ($json -> {' success' }) {
197
+ return true;
198
+ } else {
199
+ return false;
200
+ }
201
+ }
202
+
203
+ sub CheckBlacklist {
204
+ $hwid = GetHwid();
205
+
206
+ my $url = " https://keyauth.win/api/1.1/?type=check&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &hwid=${hwid} " ;
207
+ $response = Req($url );
208
+ my $json = decode_json($response -> content);
209
+
210
+ if ($json -> {' success' }) {
211
+ return true;
212
+ } else {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ sub Webhook {
218
+ $webid = $_ [0];
219
+ $params = $_ [1];
220
+
221
+ my $url = " https://keyauth.win/api/1.1/?type=webhook&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &webid=${webid} ¶ms=${params} " ;
222
+ $response = Req($url );
223
+ my $json = decode_json($response -> content);
224
+
225
+ if ($json -> {' success' }) {
226
+ return $json -> {' message' };
227
+ } else {
228
+ return " " ;
229
+ }
230
+ }
231
+
232
+ sub Log {
233
+ $message = $_ [0];
234
+ $PcUser = Win32::LoginName || " UNKNOWN" ;
235
+ $hwid = GetHwid();
236
+
237
+ my $url = " https://keyauth.win/api/1.1/?type=log&name=${name} &ownerid=${ownerid} &sessionid=${sessionid} &hwid=${hwid} &pcuser=${PcUser} &message=${message} " ;
238
+ $response = Req($url );
239
+ }
240
+
241
+ sub Load_UserData {
242
+ $EncodedJson = $_ [0];
243
+ my $json = decode_json($EncodedJson );
244
+
245
+ $user_data {' username' } = $json -> {' username' };
246
+ $user_data {' ip' } = $json -> {' ip' };
247
+ $user_data {' hwid' } = $json -> {' hwid' };
248
+ $user_data {' createdate' } = $json -> {' createdate' };
249
+ $user_data {' lastlogin' } = $json -> {' lastlogin' };
250
+
251
+ %user_data_Subscriptions = encode_json($json -> {' subscriptions' });
252
+ }
253
+
254
+ sub Load_AppInfo {
255
+ $EncodedJson = $_ [0];
256
+ my $json = decode_json($EncodedJson );
257
+
258
+ $AppInfo {' numUsers' } = $json -> {' numUsers' };
259
+ $AppInfo {' numOnlineUsers' } = $json -> {' numOnlineUsers' };
260
+ $AppInfo {' numKeys' } = $json -> {' numKeys' };
261
+ $AppInfo {' version' } = $json -> {' version' };
262
+ $AppInfo {' customerPanelLink' } = $json -> {' customerPanelLink' };
263
+ }
264
+
265
+ sub Req {
266
+ $url = $_ [0];
267
+ my $header = [' Content-Type' => ' application/x-www-form-urlencoded' ];
268
+
269
+ my $r = HTTP::Request-> new(' POST' , $url , $header );
270
+ $ua = LWP::UserAgent-> new;
271
+ $response = $ua -> request($r );
272
+ return $response ;
273
+ }
274
+
275
+ sub UnixToDate {
276
+ $unix = $_ [0];
277
+ $time = localtime ($unix )-> strftime(' %F %T' );
278
+ return $time ;
279
+ }
280
+
281
+ sub GetHwid {
282
+ $hwid = " PERL_EXAMPLE" ;
283
+ return $hwid ;
284
+ }
285
+
286
+ sub ClearConsole {
287
+ system (" cls" );
288
+ }
289
+
290
+ return 1;
0 commit comments