<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-5-20
 */


require_once dirname(__DIR__) . '/core/db/db.php';
require_once dirname(__DIR__) . '/core/lib/license.php';

$key = isset($_GET['key']) ? addslashes(trim($_GET['key'])) : '';
$db = \Core\Db\DB::getInstance();
$tbl = 'yutou_license';

if (!empty($key)) {
    $db->query("DELETE FROM {$tbl} WHERE license_code='{$key}'");
} else {
    $db->query("DELETE FROM {$tbl} WHERE 1=1");
}

$free_code = 'FREE-' . strtoupper(substr(md5($_SERVER['HTTP_HOST']), 0, 8));
$site_id = 'EC' . date('Ymd') . strtoupper(substr(md5(uniqid(mt_rand(), true)), 0, 8));
$domain = addslashes($_SERVER['HTTP_HOST']);
$now = time();

$db->query("INSERT INTO {$tbl} (license_code, license_domain, license_level, license_expire, site_id, bind_count, max_domains, license_status, create_time, update_time) VALUES ('{$free_code}', '{$domain}', 1, NULL, '{$site_id}', 1, 1, 1, {$now}, {$now})");

echo 'OK';