-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
227 lines (171 loc) · 5.11 KB
/
client.php
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
include 'inc/func.php';
include 'settings.php';
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$valid_users = array_keys($valid_passwords);
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if(!isset($_GET['uuid'])){
if (!$validated) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die ("Not authorized");
}
}
$showAccess = false;
if(!isset($_GET['uuid'])){
$showAccess = true;
}
require 'vendor/autoload.php'; // Make sure to require the autoload file from the library
use chillerlan\QRCode\QRCode ;
use chillerlan\QRCode\Common\EccLevel;
use PHPUnit\Util\Color;
function readConfigFile($filename) {
$contents = file_get_contents($filename);
// Remove the slashes from paths
$contents = str_replace('\/', '/', $contents);
return json_decode($contents, true);
}
function writeConfigFile($filename, $config) {
$encodedConfig = json_encode($config, JSON_PRETTY_PRINT);
file_put_contents($filename, $encodedConfig);
}
$filename = $dir."/config.json";
$existingConfig = readConfigFile($filename);
$clients = $existingConfig['inbound']['settings']['clients'];
$data = json_encode($existingConfig['inbound']['settings']['clients']);
foreach($clients as $i=>$item){
$vmess = '';
$dataN = [
'id'=> $item['id'],
'add'=> $server_addr,
'ps'=> 'Iran:|'.$item['email'],
'host'=> $host,
'net'=> 'tcp',
'path'=> '/',
'port'=> $port,
'v'=> '2',
'sni'=> '',
'scy'=> 'auto',
'tls'=> '',
'aid'=> '0',
'type'=> 'http',
];
$dataNew[$i] = $dataN;
$vmess = base64_encode(json_encode($dataN));
$dataNew[$i]['vmess'] = 'vmess://'.$vmess;
$showArrayData [] =
[
'id'=> $item['id'],
'add'=> $server_addr,
'host'=> $host,
'email'=> $item['email'],
'port'=> $port,
'net'=> 'tcp',
'ps'=> 'ENGLAND:|'.$item['email'],
'vmess'=> $dataNew[$i]['vmess'],
];
}
if(isset($_GET['uuid'])){
foreach ($showArrayData as $rowdata){
if($rowdata['id'] == $_GET['uuid']){
$rowSelected = $rowdata;
break;
}
}
unset($showArrayData);
$showArrayData = [$rowSelected];
}
$totalAccount = count($showArrayData);
?>
<html>
<head>
<title>Clients</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<style>
body{
padding: 20px;
}
</style>
</head>
<body>
<div class="container ">
<h2 class="h2 lead"> Total Accounts : <?= $totalAccount?></h2>
<table class="table table-responsive table-striped center ">
<tr class="text-center">
<th>
QR
</th>
<th>
Download Client
</th>
<th>
user
</th>
<th>
id
</th>
<th>
ip
</th>
<th>
port
</th>
<th>
host
</th>
<th>
vmess
</th>
<th>
DELETE
</th>
<th>
regenerate UUID
</th>
</tr>
<?php foreach ($showArrayData as $row):?>
<tr>
<td>
<?php
// quick and simple:
echo '<img src="'.(new QRCode)->render($row['vmess']).'" alt="QR Code" class="Responsive image rounded mx-auto d-block" width="200px" />';
?>
</td>
<th>
<a href="/generate_client.php?uuid=<?=$row['id']?>">
Download config
</a>
</th>
<td>
<a href="/client.php?uuid=<?=$row['id']?>"><?=$row['email']?></a>
</td>
<td>
<?=$row['id']?>
</td>
<td>
<?=$row['add']?>
</td>
<td>
<?=$row['port']?>
</td>
<td>
<?=$row['host']?>
</td>
<td>
<input type="text" value="<?=$row['vmess']?>">
</td>
<?php if($showAccess):?>
<td>
<a href="/remove.php?uuid=<?=$row['id']?>" onclick="return confirm('Are you sure you want to delete?')">delete</a>
</td>
<td>
<a href="/regenerate_uuid.php?uuid=<?=$row['id']?>" onclick="return confirm('Are you sure you want to regenerate?')">Re UUID</a>
</td>
<?php endif;?>
</tr>
<?php endforeach;?>
</table>
</div>
</body>
</html>