-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthVaultix.pm
More file actions
187 lines (165 loc) · 4.92 KB
/
AuthVaultix.pm
File metadata and controls
187 lines (165 loc) · 4.92 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package AuthVaultix;
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use POSIX qw(strftime);
# Global Vars (Static style)
my $BASE_URL = "https://authvaultix.com/api/1.0/"; # API endpoint
our $AppInitialized = "no";
our $SessionID = "none";
our ($Name, $OwnerID, $Secret, $Version);
our %AppInfo;
our %UserData;
# API Setup
sub Api {
my ($name, $ownerid, $secret, $version) = @_;
unless ($name && $ownerid && $secret && $version) {
die "Missing API credentials.\n";
}
$Name = $name;
$OwnerID = $ownerid;
$Secret = $secret;
$Version = $version;
}
# Init
sub Init {
my %payload = (
type => "init",
name => $Name,
ownerid => $OwnerID,
secret => $Secret,
ver => $Version # API expects "ver", not "version"
);
my $resp = _send_request(\%payload);
if ($resp->{success}) {
$AppInitialized = "yes";
$SessionID = $resp->{sessionid};
%AppInfo = %{ $resp->{appinfo} };
print "Initialized Successfully!\n";
} else {
die "Init Failed: $resp->{message}\n";
}
}
# Handle Response
sub _handle_response {
my ($resp, $msg) = @_;
if (!$resp) {
die "No response from server\n";
}
if ($resp->{success}) {
%UserData = %{ $resp->{info} };
print "$msg\n";
_print_user_info();
} else {
die "Error: $resp->{message}\n";
}
}
# Login
sub Login {
my ($username, $password) = @_;
_check_init();
my %payload = (
type => "login",
sessionid => $SessionID,
username => $username,
pass => $password,
hwid => _get_hwid(),
name => $Name,
ownerid => $OwnerID
);
my $resp = _send_request(\%payload); # endpoint removed
_handle_response($resp, "Logged in!");
}
# Register
sub Register {
my ($username, $password, $license) = @_;
_check_init();
my %payload = (
type => "register",
sessionid => $SessionID,
username => $username,
pass => $password,
key => $license, # MUST be "key"
hwid => _get_hwid(),
name => $Name,
ownerid => $OwnerID
);
my $resp = _send_request(\%payload); # endpoint removed
_handle_response($resp, "Registered Successfully!");
}
# License Login
sub License {
my ($license) = @_;
_check_init();
my %payload = (
type => "license",
sessionid => $SessionID,
key => $license,
hwid => _get_hwid(),
name => $Name,
ownerid => $OwnerID
);
my $resp = _send_request(\%payload);
_handle_response($resp, "License Login Successful!");
}
# Private Helpers
sub _send_request {
my ($payload_ref) = @_;
my $ua = LWP::UserAgent->new(
ssl_opts => { verify_hostname => 0 },
timeout => 15
);
# HEADERS (403 fix)
$ua->agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
$ua->default_header('Accept' => 'application/json');
$ua->default_header('Content-Type' => 'application/x-www-form-urlencoded');
my $response = $ua->post(
$BASE_URL,
Content => $payload_ref
);
# print "Status: " . $response->status_line . "\n"; # DEBUG (helpful)
my $raw = $response->decoded_content;
# print "Raw Response: $raw\n"; # remove later if not needed
if ($response->is_success) {
my $json = eval { decode_json($raw) };
if ($@) {
die "Invalid JSON from server:\n$raw\n";
}
return $json;
}
else {
die "HTTP Request Failed: " . $response->status_line . "\nResponse: $raw\n";
}
}
sub _print_user_info {
print "\n👤 User Info:\n";
print " Username: $UserData{username}\n" if $UserData{username};
print " IP: $UserData{ip}\n" if $UserData{ip};
print " HWID: $UserData{hwid}\n" if $UserData{hwid};
print " Created: " . _format_time($UserData{createdate}) . "\n" if $UserData{createdate};
if (ref($UserData{subscriptions}) eq 'ARRAY') {
print "\n Subscriptions:\n";
foreach my $sub (@{ $UserData{subscriptions} }) {
print " → $sub->{subscription} | Expiry: " . _format_time($sub->{expiry}) .
" | Left: $sub->{timeleft}s\n";
}
}
print "\n";
}
sub _check_init {
die "Please initialize app before using login/register/license.\n"
unless $AppInitialized eq "yes";
}
sub _get_hwid {
my $hwid = `wmic useraccount where name='%username%' get sid /value 2>nul`;
$hwid =~ s/SID=//;
chomp($hwid);
return $hwid || "UNKNOWN_HWID";
}
sub _format_time {
my ($unix) = @_;
return strftime("%d-%m-%Y %H:%M:%S", localtime($unix));
}
1;