<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\Web\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use ModStart\Admin\Auth\Admin; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Response; use ModStart\Core\Util\RandomUtil; use ModStart\Module\ModuleManager; use PDO; class InstallController extends Controller { public function lock() { goto fXFsH; A2bsa: return Response::send(0, 'install lock ok ^_^'); goto oE2JV; wtpF6: if (file_exists($NCgsi)) { return Response::send(0, 'install lock error -_-'); } goto mxUvN; mxUvN: file_put_contents($NCgsi, 'lock'); goto A2bsa; fXFsH: $NCgsi = storage_path('install.lock'); goto wtpF6; oE2JV: } public function ping() { try { goto Nvo5c; Nvo5c: $N3esS = Artisan::call('env'); goto g_BID; oRVce: return 'ERROR: code=' . $N3esS . ', msg:' . $LqrPH; goto M5QzX; Bs_AZ: if (0 == $N3esS) { if (Str::contains($LqrPH, 'Current application environment')) { return 'ok'; } if (Str::contains($LqrPH, 'The application environment is')) { return 'ok'; } } goto oRVce; g_BID: $LqrPH = trim(Artisan::output()); goto Bs_AZ; M5QzX: } catch (\Exception $hSVcc) { return 'ERROR:' . $hSVcc->getMessage(); } } public function prepare() { goto IgFb4; RoTkU: $PLWro = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $O1Eva . '
', $PLWro); goto yO9Ar; C4YCj: $Ylazq = InputPackage::buildFromInput(); goto qvta0; qKHjm: $jHQBV = $Ylazq->getJson('INSTALL_CONFIG'); goto XLit0; XLit0: if (empty($aBqix)) { return Response::jsonError('数据库主机名不能为空'); } goto Y0JEG; TNyN0: $O1Eva = $Ylazq->getTrimString('db_username'); goto FfBnt; qvta0: $aBqix = $Ylazq->getTrimString('db_host'); goto Ffksq; CL7xD: $pN92M = $Ylazq->getBoolean('installDemo'); goto CBOLl; lPCcJ: $PLWro = preg_replace('/ENCRYPT_KEY=(.*?)\\n/', 'ENCRYPT_KEY=' . RandomUtil::string(32) . '
', $PLWro); goto OOy0n; nykb2: $DeYh3 = $Ylazq->getTrimString('db_database'); goto TNyN0; o4cHs: try { new PDO("mysql:host={$aBqix};port={$bFXGb};dbname={$DeYh3}", $O1Eva, $oL8Xd); } catch (\Exception $hSVcc) { goto beFgt; NuYVC: return Response::jsonError('连接数据信息 ' . $aBqix . ':' . $bFXGb . '.' . $DeYh3 . ' 失败!'); goto flpch; DjCUl: Log::error('InstallError -> ' . $hSVcc->getMessage() . ' -> ' . $hSVcc->getTraceAsString()); goto NuYVC; hohSw: if (str_contains($axEh6, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $axEh6); } else { if (str_contains($axEh6, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $axEh6); } } goto DjCUl; beFgt: $axEh6 = $hSVcc->getMessage(); goto hohSw; flpch: } goto XqXQ9; zqGAA: $PLWro = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $aBqix . '
', $PLWro); goto d1IiZ; JZ0yO: if (file_exists($nn3RA = base_path('.env'))) { $eTwx_ = file_get_contents($nn3RA); if (str_contains($eTwx_, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto C4YCj; zgNLu: if (file_exists(base_path('license_url.txt')) && !$DBGL3) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto o4cHs; TS7dW: return Response::jsonSuccess(); goto a89UN; ONQ4W: $cBZ1v = $Ylazq->getTrimString('password'); goto CL7xD; YKyS6: if (empty($DeYh3)) { return Response::jsonError('数据库数据库不能为空'); } goto Emu2Y; QU7G1: $W05fv = $Ylazq->getTrimString('db_prefix', ''); goto mvO4w; Ffksq: $bFXGb = $Ylazq->getTrimString('db_port'); goto nykb2; yO9Ar: $PLWro = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $oL8Xd . '
', $PLWro); goto MOGMG; d1IiZ: $PLWro = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $bFXGb . '
', $PLWro); goto yEeYi; XqXQ9: $PLWro = file_get_contents(base_path('env.example')); goto FxnKH; Y0JEG: if (empty($bFXGb)) { return Response::jsonError('数据库端口不能为空'); } goto YKyS6; yEeYi: $PLWro = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $DeYh3 . '
', $PLWro); goto RoTkU; BR0hW: file_put_contents(base_path('.env'), $PLWro); goto TS7dW; FfBnt: $oL8Xd = $Ylazq->getTrimString('db_password', ''); goto QU7G1; CBOLl: $DBGL3 = $Ylazq->getBoolean('installLicense'); goto qKHjm; Emu2Y: if (empty($O1Eva)) { return Response::jsonError('数据库用户名不能为空'); } goto WbWLF; cTYpb: $PLWro = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $PLWro); goto lPCcJ; MOGMG: $PLWro = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $W05fv . '
', $PLWro); goto cTYpb; FxnKH: $PLWro = preg_replace('/APP_DEBUG=(.*?)\\n/', 'APP_DEBUG=false
', $PLWro); goto zqGAA; OOy0n: if (!empty($jHQBV['envs'])) { foreach ($jHQBV['envs'] as $iVRWU) { $PLWro = preg_replace('/' . $iVRWU['name'] . '=(.*?)\\n/', $iVRWU['name'] . '=' . $Ylazq->getTrimString($iVRWU['name']) . '
', $PLWro); } } goto BR0hW; dmQmP: if (empty($cBZ1v)) { return Response::jsonError('管理用户密码不能为空'); } goto zgNLu; WbWLF: if (empty($aek5y)) { return Response::jsonError('管理用户不能为空'); } goto dmQmP; IgFb4: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto JZ0yO; mvO4w: $aek5y = $Ylazq->getTrimString('username'); goto ONQ4W; a89UN: } public function execute() { goto n2w2S; GMmCq: set_time_limit(0); goto whCKd; n2w2S: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto BiVBU; rwYXG: $fgNkb = ModelUtil::count('admin_user'); goto pNtiM; hf8Qw: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto Y8874; AJkuB: $cBZ1v = $Ylazq->getTrimString('password'); goto nUMFX; cWPdV: file_put_contents(storage_path('install.lock'), 'lock'); goto hf8Qw; whCKd: $N3esS = 0; goto nnBZz; nUMFX: $pN92M = $Ylazq->getBoolean('installDemo'); goto HeKwB; NmJ8c: if (0 != $N3esS) { return Response::jsonError("安装错误 exitCode({$N3esS})"); } goto rwYXG; nnBZz: try { $N3esS = Artisan::call('migrate'); } catch (\Exception $hSVcc) { return $this->handleException($hSVcc); } goto NmJ8c; BiVBU: $Ylazq = InputPackage::buildFromInput(); goto t48dH; pNtiM: if ($fgNkb === 0) { Admin::add($aek5y, $cBZ1v); } goto CcQOj; arEuc: if (empty($cBZ1v)) { return Response::jsonError('管理用户密码为空'); } goto GMmCq; CcQOj: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $WQ9HU) { goto eaO1S; fV42q: try { $Gs3Xd = ModuleManager::install($WQ9HU); } catch (\Exception $hSVcc) { return $this->handleException($hSVcc); } goto Taxv2; eaO1S: if (!ModuleManager::isExists($WQ9HU)) { continue; } goto fV42q; Taxv2: if (Response::isError($Gs3Xd)) { return Response::generateError($Gs3Xd['msg']); } goto fNKky; fNKky: } goto cVICl; t48dH: $aek5y = $Ylazq->getTrimString('username'); goto AJkuB; HeKwB: if (empty($aek5y)) { return Response::jsonError('管理用户名为空'); } goto arEuc; cVICl: if ($pN92M && file_exists($x_XbT = public_path('data_demo/data.php'))) { goto Mu3mO; rlobh: if (!empty($smBDO['updates'])) { foreach ($smBDO['updates'] as $dE7kJ) { DB::table($dE7kJ['table'])->where($dE7kJ['where'])->update($dE7kJ['update']); } } goto NRBCo; Mu3mO: $smBDO = (include $x_XbT); goto RDXWk; RDXWk: if (!empty($smBDO['inserts'])) { foreach ($smBDO['inserts'] as $EeFZ9 => $qhpxU) { ModelUtil::insertAll($EeFZ9, $qhpxU); } } goto rlobh; NRBCo: } goto cWPdV; Y8874: } private function handleException(\Exception $hSVcc) { goto RopOt; RopOt: $axEh6 = $hSVcc->getMessage(); goto ZXX1e; Q1pfU: if (preg_match('/Table \'(.*?)\' already exists/', $axEh6, $Qie0V)) { return Response::jsonError('数据表 ' . $Qie0V[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto ek2iQ; ZXX1e: $wcheO = $hSVcc->getTraceAsString(); goto Q1pfU; ek2iQ: if (preg_match('/Duplicate column name \'(.*?)\'/', $axEh6, $Qie0V)) { goto MtbpG; ry7Fe: $x_XbT = null; goto bFETe; bFETe: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $wcheO, $Qie0V)) { $x_XbT = $Qie0V[1]; } goto KMv8d; KMv8d: return Response::jsonError('数据表字段 ' . $iuKOG . ' 已经存在（请查看' . $x_XbT . '迁移文件配置）'); goto h38dv; MtbpG: $iuKOG = $Qie0V[1]; goto ry7Fe; h38dv: } goto BIued; BIued: throw $hSVcc; goto ebzTL; ebzTL: } }