<?php
/**
* TMITStore Maintenance Script
* Run once, then DELETE this file!
* URL: https://yourdomain.com/maintain.php?token=tmit_maintain_2024
*/
if (($_GET['token'] ?? '') !== 'tmit_maintain_2024') {
http_response_code(403);
die('<h2>403 Forbidden</h2>');
}
header('Content-Type: text/html; charset=UTF-8');
// ── Auto-detect Laravel root ──────────────────────────────────────────────
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
$appRoot = realpath(__DIR__ . '/..'); // standard or local
} elseif (file_exists(__DIR__ . '/../ecommerce/vendor/autoload.php')) {
$appRoot = realpath(__DIR__ . '/../ecommerce'); // split deploy
} else {
die('<p style="color:red">❌ Laravel root not found!</p>');
}
$webRoot = dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']);
// public_html path
$publicHtml = $_SERVER['DOCUMENT_ROOT'];
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TMITStore Maintenance</title>
<style>
body{font-family:monospace;background:#1a1a2e;color:#eee;padding:30px}
.box{background:#16213e;border-radius:12px;padding:30px;max-width:750px;margin:0 auto}
h2{color:#e63946}.ok{color:#4ade80}.fail{color:#f87171}.warn{color:#fbbf24}.info{color:#60a5fa}
p{margin:6px 0;font-size:14px}hr{border-color:#333;margin:16px 0}
.done{background:#0f3460;border-radius:8px;padding:16px;margin-top:20px}
pre{background:#0a0a1a;padding:12px;border-radius:6px;overflow-x:auto;font-size:12px}
</style>
</head>
<body><div class="box">
<h2>🔧 TMITStore Maintenance</h2>
<p class="info">App Root: <strong><?= $appRoot ?></strong></p>
<p class="info">Public: <strong><?= __DIR__ ?></strong></p>
<?php
// ─────────────────────────────────────────────────────────────────────────────
// 1. Create license folder + validator.php
// ─────────────────────────────────────────────────────────────────────────────
echo '<hr><p><strong>1. License Server File</strong></p>';
$licenseDir = $publicHtml . '/license';
$validatorFile = $licenseDir . '/validator.php';
if (!is_dir($licenseDir)) {
if (@mkdir($licenseDir, 0755, true)) {
echo "<p class='ok'>✅ /license folder created.</p>";
} else {
echo "<p class='fail'>❌ Could not create /license folder.</p>";
}
} else {
echo "<p class='ok'>✅ /license folder already exists.</p>";
}
$validatorContent = <<<'PHP'
<?php
define('LICENSE_SECRET', 'TMIT_LIC_SECRET_2024_K9mPxZvR');
$licenses = [
'tmitstore.top' => 'TMIT-OWNER-0001',
'localhost' => 'TMIT-DEV-LOCAL',
'127.0.0.1' => 'TMIT-DEV-LOCAL',
// নতুন customer যোগ করতে নিচে লাইন যোগ করো:
// 'customer.com' => 'TMIT-XXXX-YYYY',
];
header('Content-Type: application/json; charset=UTF-8');
header('X-Robots-Tag: noindex, nofollow');
header('Cache-Control: no-store');
$secret = trim($_REQUEST['secret'] ?? '');
if ($secret !== LICENSE_SECRET) {
http_response_code(403);
echo json_encode(['valid' => false, 'message' => 'Forbidden']);
exit;
}
$domain = strtolower(trim($_REQUEST['domain'] ?? ''));
$domain = preg_replace('/^www\./i', '', $domain);
$domain = explode(':', $domain)[0];
if (empty($domain)) {
echo json_encode(['valid' => false, 'message' => 'No domain']);
exit;
}
if (!array_key_exists($domain, $licenses)) {
echo json_encode(['valid' => false, 'message' => 'Domain not licensed', 'domain' => $domain]);
exit;
}
$code = trim($_REQUEST['code'] ?? '');
if (!empty($code) && $licenses[$domain] !== $code) {
echo json_encode(['valid' => false, 'message' => 'Invalid purchase code']);
exit;
}
echo json_encode(['valid' => true, 'message' => 'Licensed', 'domain' => $domain]);
PHP;
if (@file_put_contents($validatorFile, $validatorContent) !== false) {
echo "<p class='ok'>✅ validator.php created at: <code>$validatorFile</code></p>";
} else {
echo "<p class='fail'>❌ Could not write validator.php (permission issue?)</p>";
}
// ─────────────────────────────────────────────────────────────────────────────
// 2. Update .env — LICENSE settings
// ─────────────────────────────────────────────────────────────────────────────
echo '<hr><p><strong>2. Update .env — License Settings</strong></p>';
$envFile = $appRoot . '/.env';
if (file_exists($envFile)) {
$env = file_get_contents($envFile);
$host = $_SERVER['HTTP_HOST'] ?? 'tmitstore.top';
$host = preg_replace('/^www\./i', '', $host);
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$licUrl = $scheme . '://' . $host . '/license/validator.php';
$updates = [
'LICENSE_SERVER_URL' => $licUrl,
'LICENSE_PURCHASE_CODE'=> 'TMIT-OWNER-0001',
'LICENSE_SECRET_KEY' => 'TMIT_LIC_SECRET_2024_K9mPxZvR',
];
foreach ($updates as $key => $value) {
if (preg_match('/^' . $key . '=/m', $env)) {
$env = preg_replace('/^' . $key . '=.*/m', $key . '=' . $value, $env);
echo "<p class='ok'>✅ Updated: <code>$key=$value</code></p>";
} else {
$env .= "\n$key=$value";
echo "<p class='ok'>✅ Added: <code>$key=$value</code></p>";
}
}
if (@file_put_contents($envFile, $env) !== false) {
echo "<p class='ok'>✅ .env saved.</p>";
} else {
echo "<p class='fail'>❌ Could not write .env file.</p>";
}
} else {
echo "<p class='fail'>❌ .env file not found at: $envFile</p>";
}
// ─────────────────────────────────────────────────────────────────────────────
// 3. Clear all caches
// ─────────────────────────────────────────────────────────────────────────────
echo '<hr><p><strong>3. Clear Cache</strong></p>';
$cacheDirs = [
$appRoot . '/storage/framework/cache/data',
$appRoot . '/storage/framework/views',
$appRoot . '/bootstrap/cache',
];
$totalCleared = 0;
foreach ($cacheDirs as $dir) {
if (!is_dir($dir)) continue;
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)
);
$count = 0;
foreach ($files as $file) {
if ($file->isFile() && $file->getExtension() !== 'gitignore') {
if (@unlink($file->getPathname())) $count++;
}
}
$totalCleared += $count;
$label = str_replace($appRoot, '', $dir);
echo "<p class='ok'>✅ Cleared $count files from <code>$label</code></p>";
}
echo "<p class='info'>Total cleared: $totalCleared files</p>";
// ─────────────────────────────────────────────────────────────────────────────
// 4. Storage Symlink
// ─────────────────────────────────────────────────────────────────────────────
echo '<hr><p><strong>4. Storage Symlink</strong></p>';
$symlinkTarget = $appRoot . '/storage/app/public';
$symlinkPath = __DIR__ . '/storage';
if (is_link($symlinkPath)) {
echo "<p class='ok'>✅ Storage symlink already exists.</p>";
} elseif (is_dir($symlinkPath)) {
$files = array_diff(scandir($symlinkPath), ['.', '..']);
if (empty($files)) {
rmdir($symlinkPath);
if (@symlink($symlinkTarget, $symlinkPath)) {
echo "<p class='ok'>✅ Old empty folder removed, symlink created.</p>";
} else {
echo "<p class='fail'>❌ Symlink failed. Run via SSH: <code>ln -s $symlinkTarget $symlinkPath</code></p>";
}
} else {
echo "<p class='warn'>⚠️ Storage folder has files. Delete manually then re-run.</p>";
}
} else {
if (@symlink($symlinkTarget, $symlinkPath)) {
echo "<p class='ok'>✅ Storage symlink created.</p>";
} else {
echo "<p class='fail'>❌ Symlink failed. Run via SSH: <code>ln -s $symlinkTarget $symlinkPath</code></p>";
}
}
// ─────────────────────────────────────────────────────────────────────────────
// 5. Test license validator
// ─────────────────────────────────────────────────────────────────────────────
echo '<hr><p><strong>5. License Self-Test</strong></p>';
$host = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST'] ?? 'tmitstore.top');
$testUrl = 'https://' . $host . '/license/validator.php?secret=TMIT_LIC_SECRET_2024_K9mPxZvR&domain=' . $host;
$ctx = stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]);
$result = @file_get_contents($testUrl, false, $ctx);
if ($result !== false) {
$data = json_decode($result, true);
if (!empty($data['valid'])) {
echo "<p class='ok'>✅ License check passed! Domain <code>$host</code> is licensed.</p>";
} else {
echo "<p class='fail'>❌ License check failed: " . ($data['message'] ?? 'unknown') . "</p>";
}
echo "<pre>" . htmlspecialchars($result) . "</pre>";
} else {
echo "<p class='warn'>⚠️ Could not self-test (URL may not be accessible yet).</p>";
echo "<p class='info'>Manually check: <code>$testUrl</code></p>";
}
?>
<hr>
<div class="done">
<p class="ok" style="font-size:18px;font-weight:bold">✅ Maintenance Complete!</p>
<p class="warn">⚠️ <strong>এই ফাইলটা এখনই DELETE করো:</strong> <code>maintain.php</code></p>
</div>
</div></body></html>