-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.php
More file actions
433 lines (388 loc) · 18.8 KB
/
patch.php
File metadata and controls
433 lines (388 loc) · 18.8 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
// Bật hiển thị tất cả lỗi để dễ dàng gỡ lỗi
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Bản đồ chứa tên hàm và đường dẫn URL tới mã nguồn mới
const FUNCTION_GIST_MAP = [
'checkAddonLicense' => 'https://code10k.com/functions/checkAddonLicense.php',
'CMSNT_check_license' => 'https://code10k.com/functions/CMSNT_check_license.php',
'checkAddon' => 'https://code10k.com/functions/checkAddon.php',
'feature_enabled' => 'https://code10k.com/functions/feature_enabled.php',
];
// Cấu hình cho từng dự án: gồm đường dẫn, API kiểm tra phiên bản và các hàm cần cập nhật
$projects_config = [
'SHOPCLONE7_ENCRYPTION' => [
'path' => 'libs/helper.php',
'version_api_url' => 'https://api.cmsnt.co/version.php?version=SHOPCLONE7_ENCRYPTION',
'functions_to_update' => ['checkAddon', 'CMSNT_check_license'],
],
'SMMPANEL2_ENCRYPTION' => [
'path' => 'libs/helper.php',
'version_api_url' => 'https://api.cmsnt.co/version.php?version=SMMPANEL2_ENCRYPTION',
'functions_to_update' => ['checkAddonLicense', 'checkAddon', 'CMSNT_check_license'],
],
'SHOPCLONE6' => [
'path' => 'libs/helper.php',
'version_api_url' => 'https://api.cmsnt.co/version.php?version=SHOPCLONE6',
'functions_to_update' => ['CMSNT_check_license', 'checkAddon'],
],
'SMMPANELV1' => [
'path' => '../app/Helpers/Funcs.php',
'version_api_url' => 'https://updates.baocms.net/smmpanel-v1/index.php?route=check-update&hash=e01cc7e1e3957ff1cec61d5de0b8c964&secret=e01cc7e1e3957ff1cec61d5de0b8c964',
'functions_to_update' => ['CMSNT_check_license', 'feature_enabled'],
],
'SHOPNICK3' => [
'path' => '../app/Helpers/Helper2.php',
'version_api_url' => 'https://updates.baocms.net/shopnickv3/index.php?route=check-update&hash=e01cc7e1e3957ff1cec61d5de0b8c964&secret=e01cc7e1e3957ff1cec61d5de0b8c964',
'functions_to_update' => ['CMSNT_check_license', 'feature_enabled'],
],
];
// Danh sách dự án sử dụng API định dạng của baocms.net
$baocms_list = ["SMMPANELV1", "SHOPNICK3"];
// Thiết lập mặc định cho tên dự án và phiên bản
$default_project = "UNSUPPORTED_PROJECT";
$default_version = "N/A";
// Nếu tồn tại file config.php thì trích xuất thông tin project và version
if (file_exists('config.php')) {
$config_file_content = file_get_contents('config.php');
if ($config_file_content !== false) {
if (preg_match("/'project'\s*=>\s*'(.*?)'/", $config_file_content, $matches_project)) {
$default_project = $matches_project[1];
}
if (preg_match("/'version'\s*=>\s*'(.*?)'/", $config_file_content, $matches_version)) {
$default_version = $matches_version[1];
}
}
}
// Nếu không xác định được dự án, sử dụng phương án thay thế
if ($default_project === "UNSUPPORTED_PROJECT") {
if (file_exists($projects_config['SHOPNICK3']['path'] ?? '')) {
$default_project = 'SHOPNICK3';
} else if (file_exists($projects_config['SMMPANELV1']['path'] ?? '')) {
$default_project = 'SMMPANELV1';
}
}
// Nếu yêu cầu lấy danh sách phiên bản (GET với action=get_versions)
if (isset($_GET['action']) && $_GET['action'] === 'get_versions') {
header('Content-Type: application/json');
$latest_versions = [];
foreach ($projects_config as $project_name => $details) {
$version_api_url = $details['version_api_url'];
$version_data = @file_get_contents($version_api_url);
// Nếu là dự án dùng định dạng baocms.net, giải mã JSON
if (in_array($project_name, $baocms_list)) {
$decoded_data = json_decode($version_data, true);
$version_name = $decoded_data['data']['version_name'] ?? 'N/A';
$version_code = $decoded_data['data']['version_code'] ?? 'N/A';
$version_data = $version_name . ' (' . $version_code . ')';
}
$latest_versions[$project_name] = ($version_data !== false) ? trim($version_data) : 'N/A';
}
echo json_encode($latest_versions);
exit;
}
// Nếu là yêu cầu POST (như khi gửi form)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
$project_to_update = $_POST['project'] ?? $default_project;
if (!isset($projects_config[$project_to_update])) {
echo json_encode(['status' => 'error', 'message' => "Dự án không hợp lệ hoặc không được hỗ trợ."]);
exit;
}
$file_path = $projects_config[$project_to_update]['path'];
$functions_to_replace = $projects_config[$project_to_update]['functions_to_update'];
// Hàm thay thế mã cho một hàm cụ thể
function replace_function($code, $function_name, $new_code)
{
$pattern = '/function\s+' . preg_quote($function_name) . '\s*\(.*?\)\s*\{.*?\n\}/s';
if (preg_match($pattern, $code)) {
return preg_replace($pattern, $new_code, $code);
} else {
return "FUNCTION_NOT_FOUND: $function_name";
}
}
// Kiểm tra file có tồn tại và đọc được không
if (!file_exists($file_path) || !is_readable($file_path)) {
echo json_encode(['status' => 'error', 'message' => "Không thể truy cập file '$file_path'."]);
exit;
}
$code = file_get_contents($file_path);
if ($code === false) {
echo json_encode(['status' => 'error', 'message' => "Không thể đọc nội dung file '$file_path'."]);
exit;
}
$errors = [];
foreach ($functions_to_replace as $func_name) {
if (isset(FUNCTION_GIST_MAP[$func_name])) {
$url = FUNCTION_GIST_MAP[$func_name];
$new_code = @file_get_contents($url);
if ($new_code === false) {
$errors[] = "Không thể tải mã mới cho hàm '$func_name' từ URL '$url'.";
continue;
}
$result_code = replace_function($code, $func_name, $new_code);
if (strpos($result_code, 'FUNCTION_NOT_FOUND:') === 0) {
$errors[] = "Không tìm thấy hàm '$func_name' trong tệp.";
} else {
$code = $result_code;
}
} else {
$errors[] = "Không tìm thấy URL cho hàm '$func_name'. Vui lòng kiểm tra FUNCTION_GIST_MAP.";
}
}
if (file_put_contents($file_path, $code) === false) {
$errors[] = "Không thể ghi nội dung vào file '$file_path'. Hãy kiểm tra quyền ghi.";
}
if (empty($errors)) {
echo json_encode(['status' => 'success', 'message' => "Cập nhật tất cả hàm cho dự án '$project_to_update' thành công."]);
} else {
echo json_encode(['status' => 'error', 'message' => "Hoàn tất cập nhật nhưng có lỗi: " . implode(" ", $errors)]);
}
exit;
}
// Mặc định khi truy cập GET không có action
?>
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bảng Cập Nhật Dự Án - PHUONGIT98</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@500;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Lexend', Arial, sans-serif;
background: #f6f8fa;
}
.panel {
background: #fff;
border-radius: 18px;
box-shadow: 0 4px 28px 0 rgba(80, 99, 122, 0.10);
border: 1px solid #e5e7eb;
}
.readme-content {
font-family: 'Lexend', Arial, sans-serif;
max-height: 480px;
overflow-y: auto;
}
.readme-content h1,
.readme-content h2,
.readme-content h3 {
font-weight: 700;
margin-top: 1.1em;
}
.readme-content h1 {
font-size: 1.6rem;
}
.readme-content h2 {
font-size: 1.25rem;
}
.readme-content h3 {
font-size: 1.1rem;
}
.readme-content p {
margin: 0.5em 0;
}
.readme-content ul,
.readme-content ol {
margin-left: 1.2em;
margin-bottom: 1em;
}
.readme-content code,
.readme-content pre {
background: #f1f1f2;
border-radius: 4px;
padding: 2px 6px;
font-size: 0.98em;
}
.readme-content pre {
padding: 12px;
margin: 1em 0;
overflow-x: auto;
}
/* Custom scrollbar for README */
.readme-content::-webkit-scrollbar {
width: 6px;
}
.readme-content::-webkit-scrollbar-thumb {
background: #d1d5db;
border-radius: 8px;
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center px-2 py-8">
<div class="panel max-w-2xl w-full mx-auto p-7 flex flex-col gap-8">
<!-- Title -->
<div class="flex flex-col items-center gap-2 mb-2">
<span class="text-xl font-bold text-slate-800 tracking-tight">CMSNT Patch Panel</span>
<span class="text-base text-slate-500">Công cụ cập nhật & null sản phẩm CMSNT</span>
</div>
<!-- Project Info & Update Form -->
<form id="updateForm" class="flex flex-col gap-4" autocomplete="off">
<div class="flex flex-col gap-1">
<label for="projectNameDisplay" class="text-sm font-semibold text-slate-700 mb-1">Tên dự án:</label>
<input type="text" id="projectNameDisplay"
class="bg-slate-50 border border-slate-200 rounded-lg px-4 py-2 text-base font-medium text-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-300 transition"
readonly>
<input type="hidden" id="hiddenProjectInput" name="project">
<input type="hidden" id="hiddenVersionInput" value="<?php echo $default_version; ?>">
</div>
<button type="submit" id="runButton"
class="relative bg-slate-800 text-white font-bold py-2 rounded-lg shadow-sm flex items-center justify-center gap-2 text-base mt-1 tracking-wide hover:bg-slate-700 transition-all focus:outline-none focus:ring-2 focus:ring-slate-400">
<svg class="-ml-1" width="20" height="20" fill="none">
<circle cx="10" cy="10" r="9" stroke="#bdbdbd" stroke-width="2" />
<path d="M7 13l3-6m3 6l-3-6" stroke="#fff" stroke-width="2" stroke-linecap="round" />
</svg>
Chạy cập nhật
</button>
<div id="runButtonSpinner" class="hidden animate-spin rounded-full h-7 w-7 border-4 border-slate-200 border-t-slate-500 mx-auto"></div>
</form>
<div id="message" class="hidden"></div>
<!-- Version Info -->
<div>
<div class="flex items-center justify-between">
<h2 class="text-base font-semibold text-slate-700">Phiên bản các dự án</h2>
</div>
<div id="versionsContainer" class="flex flex-wrap gap-2 mt-2">
<div id="versionsLoadingSpinner" class="animate-spin rounded-full h-6 w-6 border-4 border-slate-200 border-t-slate-400"></div>
</div>
</div>
<!-- README.md Hiển thị đẹp -->
<div>
<h2 class="text-base font-semibold text-slate-700 mb-2">README & Hướng dẫn sử dụng</h2>
<div id="additionalInfoContent" class="readme-content bg-slate-50 border border-slate-200 rounded-lg p-4 text-slate-800 shadow-inner text-base leading-relaxed">Đang tải README...</div>
</div>
<!-- Support Contact -->
<div class="text-center mt-2">
<div class="flex flex-col md:flex-row items-center justify-center gap-3">
<a href="https://t.me/phuongit98" target="_blank"
class="px-4 py-2 rounded-full bg-slate-700 text-white font-semibold shadow hover:bg-slate-600 transition">Telegram: @PHUONGIT98</a>
<a href="https://code10k.com" target="_blank"
class="px-4 py-2 rounded-full bg-slate-500 text-white font-semibold shadow hover:bg-slate-600 transition">Website: code10k.com</a>
</div>
</div>
<!-- Footer -->
<div class="text-slate-400 text-xs text-center mt-7 pt-4 border-t border-slate-100">
© 2025 PHUONGIT98 Panel.
</div>
</div>
<script>
const defaultProjectName = "<?php echo $default_project; ?>";
const defaultProjectVersion = document.getElementById('hiddenVersionInput').value;
const additionalInfoGistUrl = "/README.md";
const projectNameDisplay = document.getElementById('projectNameDisplay');
const hiddenProjectInput = document.getElementById('hiddenProjectInput');
const updateForm = document.getElementById('updateForm');
const runButton = document.getElementById('runButton');
const runButtonSpinner = document.getElementById('runButtonSpinner');
const messageDiv = document.getElementById('message');
const versionsContainer = document.getElementById('versionsContainer');
const versionsLoadingSpinner = document.getElementById('versionsLoadingSpinner');
const additionalInfoContent = document.getElementById('additionalInfoContent');
projectNameDisplay.value = defaultProjectName;
hiddenProjectInput.value = defaultProjectName;
async function displayAllVersions() {
versionsContainer.innerHTML = '';
versionsContainer.appendChild(versionsLoadingSpinner);
versionsLoadingSpinner.classList.remove('hidden');
try {
const response = await fetch(window.location.href + '?action=get_versions');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const allLatestVersions = await response.json();
versionsContainer.innerHTML = '';
versionsLoadingSpinner.classList.add('hidden');
if (Object.keys(allLatestVersions).length === 0) {
versionsContainer.innerHTML = '<p class="text-slate-400 text-center">Không có dữ liệu phiên bản.</p>';
return;
}
for (const projectName in allLatestVersions) {
const latestVersion = allLatestVersions[projectName];
const isCurrent = projectName === defaultProjectName && defaultProjectVersion !== 'N/A';
const box = document.createElement('div');
box.className =
'border rounded-lg px-3 py-2 bg-slate-50 font-semibold text-slate-700 text-sm flex flex-col items-center ' +
(isCurrent ? 'border-slate-500 bg-slate-100 shadow' : 'border-slate-200');
box.innerHTML = `
<div>${projectName}</div>
<div class="text-xs mt-1 text-slate-600">
Version: <span class="font-semibold">${latestVersion}</span>
${isCurrent ? `<span class="ml-1 text-slate-800">(Đang dùng: <b>${defaultProjectVersion}</b>)</span>` : ''}
</div>
`;
versionsContainer.appendChild(box);
}
} catch (error) {
versionsContainer.innerHTML = '<p class="text-red-500">Lỗi tải phiên bản.</p>';
versionsLoadingSpinner.classList.add('hidden');
}
}
async function fetchAdditionalInfo() {
additionalInfoContent.textContent = 'Đang tải README...';
try {
const response = await fetch(additionalInfoGistUrl);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const markdownText = await response.text();
additionalInfoContent.innerHTML = marked.parse(markdownText);
} catch (error) {
additionalInfoContent.innerHTML = '<p class="text-red-500">Lỗi tải README.md.</p>';
}
}
document.addEventListener('DOMContentLoaded', () => {
displayAllVersions();
fetchAdditionalInfo();
});
updateForm.addEventListener('submit', async function(event) {
event.preventDefault();
messageDiv.classList.add('hidden');
messageDiv.className = '';
messageDiv.textContent = '';
runButton.classList.add('invisible');
runButtonSpinner.classList.remove('hidden');
const projectToUpdate = hiddenProjectInput.value;
if (!projectToUpdate) {
showMessage('Không tìm thấy dự án để cập nhật. Kiểm tra lại config.php.', 'error');
runButton.classList.remove('invisible');
runButtonSpinner.classList.add('hidden');
return;
}
try {
const response = await fetch(window.location.href, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `project=${encodeURIComponent(projectToUpdate)}`
});
const result = await response.json();
if (response.ok) {
if (result.status === 'success') {
showMessage(result.message, 'success');
} else if (result.status === 'error') {
showMessage(result.message, 'error');
} else {
showMessage('Update complete, but response is unclear. Please check logs.', 'success');
}
} else {
showMessage(`Server error: ${response.status} ${response.statusText}\n${result.message || ''}`, 'error');
}
} catch (error) {
showMessage(`Không thể kết nối máy chủ: ${error.message}`, 'error');
} finally {
runButton.classList.remove('invisible');
runButtonSpinner.classList.add('hidden');
}
});
function showMessage(text, type) {
messageDiv.textContent = text;
messageDiv.classList.remove('hidden');
if (type === 'success') {
messageDiv.className = 'bg-green-50 border border-green-200 text-green-800 rounded-lg p-4 font-semibold mt-2 shadow';
} else {
messageDiv.className = 'bg-red-50 border border-red-200 text-red-700 rounded-lg p-4 font-semibold mt-2 shadow';
}
}
</script>
</body>
</html>