<?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 qHaHA; XYLzF: file_put_contents($HIZil, 'lock'); goto Sravb; TQRfW: if (file_exists($HIZil)) { return Response::send(0, 'install lock error -_-'); } goto XYLzF; qHaHA: $HIZil = storage_path('install.lock'); goto TQRfW; Sravb: return Response::send(0, 'install lock ok ^_^'); goto ODBoX; ODBoX: } public function ping() { try { goto zAuIe; tYYv9: $JZ6r5 = trim(Artisan::output()); goto Q7Z3Q; Q7Z3Q: if (0 == $LAwgR) { if (Str::contains($JZ6r5, 'Current application environment')) { return 'ok'; } if (Str::contains($JZ6r5, 'The application environment is')) { return 'ok'; } } goto p66Hc; zAuIe: $LAwgR = Artisan::call('env'); goto tYYv9; p66Hc: return 'ERROR: code=' . $LAwgR . ', msg:' . $JZ6r5; goto w5Lal; w5Lal: } catch (\Exception $Q19lV) { return 'ERROR:' . $Q19lV->getMessage(); } } public function prepare() { goto wg8Wv; U3ZCQ: $jVCDn = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $EBLs2 . '
', $jVCDn); goto cnqR1; Q494X: $W2c9F = $OPo_x->getTrimString('db_password', ''); goto TaoML; U0dGQ: if (!empty($U1MSj['envs'])) { foreach ($U1MSj['envs'] as $WmdMf) { $jVCDn = preg_replace('/' . $WmdMf['name'] . '=(.*?)\\n/', $WmdMf['name'] . '=' . $OPo_x->getTrimString($WmdMf['name']) . '
', $jVCDn); } } goto hFR8n; RauRd: $jVCDn = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $bJnDe . '
', $jVCDn); goto mnvL2; Umb2T: $wJyCj = $OPo_x->getTrimString('password'); goto NlrIG; DGPoY: $OPo_x = InputPackage::buildFromInput(); goto gvYUU; nNeOD: if (empty($nR8ui)) { return Response::jsonError('数据库端口不能为空'); } goto BuJ9Z; rTl2X: $XZEIM = $OPo_x->getBoolean('installLicense'); goto P8h2N; gvYUU: $bJnDe = $OPo_x->getTrimString('db_host'); goto iLiYb; mFD3r: $jVCDn = file_get_contents(base_path('env.example')); goto RauRd; hFR8n: file_put_contents(base_path('.env'), $jVCDn); goto XnEUr; nzkpI: if (file_exists($v0yP9 = base_path('.env'))) { $ZA40Q = file_get_contents($v0yP9); if (str_contains($ZA40Q, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto DGPoY; NlrIG: $plEpl = $OPo_x->getBoolean('installDemo'); goto rTl2X; rKpUl: if (empty($EBLs2)) { return Response::jsonError('数据库用户名不能为空'); } goto Vl2cl; cnqR1: $jVCDn = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $W2c9F . '
', $jVCDn); goto DJpXT; P8h2N: $U1MSj = $OPo_x->getJson('INSTALL_CONFIG'); goto dFZni; wg8Wv: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto nzkpI; Vl2cl: if (empty($TVXpt)) { return Response::jsonError('管理用户不能为空'); } goto NQedd; FFc_T: $TVXpt = $OPo_x->getTrimString('username'); goto Umb2T; txCSM: try { new PDO("mysql:host={$bJnDe};port={$nR8ui};dbname={$CJ18w}", $EBLs2, $W2c9F); } catch (\Exception $Q19lV) { goto wTr1P; rPgcV: Log::error('InstallError -> ' . $Q19lV->getMessage() . ' -> ' . $Q19lV->getTraceAsString()); goto YUEZQ; wTr1P: $pwDm3 = $Q19lV->getMessage(); goto enFnL; YUEZQ: return Response::jsonError('连接数据信息 ' . $bJnDe . ':' . $nR8ui . '.' . $CJ18w . ' 失败!'); goto D9hMK; enFnL: if (str_contains($pwDm3, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $pwDm3); } else { if (str_contains($pwDm3, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $pwDm3); } } goto rPgcV; D9hMK: } goto mFD3r; TaoML: $XX2iK = $OPo_x->getTrimString('db_prefix', ''); goto FFc_T; FpVpQ: $EBLs2 = $OPo_x->getTrimString('db_username'); goto Q494X; mnvL2: $jVCDn = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $nR8ui . '
', $jVCDn); goto utoYc; NQedd: if (empty($wJyCj)) { return Response::jsonError('管理用户密码不能为空'); } goto Vbn0_; DJpXT: $jVCDn = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $XX2iK . '
', $jVCDn); goto RUadO; dFZni: if (empty($bJnDe)) { return Response::jsonError('数据库主机名不能为空'); } goto nNeOD; iLiYb: $nR8ui = $OPo_x->getTrimString('db_port'); goto PUbnv; XnEUr: return Response::jsonSuccess(); goto wwrao; PUbnv: $CJ18w = $OPo_x->getTrimString('db_database'); goto FpVpQ; BuJ9Z: if (empty($CJ18w)) { return Response::jsonError('数据库数据库不能为空'); } goto rKpUl; utoYc: $jVCDn = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $CJ18w . '
', $jVCDn); goto U3ZCQ; Vbn0_: if (file_exists(base_path('license_url.txt')) && !$XZEIM) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto txCSM; RUadO: $jVCDn = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $jVCDn); goto U0dGQ; wwrao: } public function execute() { goto ntCX3; bo8XP: $lHvAH = ModelUtil::count('admin_user'); goto Q2EZt; YK_eD: $TVXpt = $OPo_x->getTrimString('username'); goto Av034; fNV8L: $LAwgR = 0; goto t7o3J; oY1Ey: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $LLvXr) { goto iv_0O; iv_0O: if (!ModuleManager::isExists($LLvXr)) { continue; } goto iejwf; iejwf: try { $yCUD1 = ModuleManager::install($LLvXr); } catch (\Exception $Q19lV) { return $this->handleException($Q19lV); } goto icuv_; icuv_: if (Response::isError($yCUD1)) { return Response::generateError($yCUD1['msg']); } goto MLTal; MLTal: } goto aS3p5; baNn6: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto O7RC2; slR_J: if (empty($TVXpt)) { return Response::jsonError('管理用户名为空'); } goto N8SAg; XOmTA: $OPo_x = InputPackage::buildFromInput(); goto YK_eD; Av034: $wJyCj = $OPo_x->getTrimString('password'); goto U0MQ7; DZD_x: file_put_contents(storage_path('install.lock'), 'lock'); goto baNn6; ntCX3: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto XOmTA; Q2EZt: if ($lHvAH === 0) { Admin::add($TVXpt, $wJyCj); } goto oY1Ey; CzULW: if (0 != $LAwgR) { return Response::jsonError("安装错误 exitCode({$LAwgR})"); } goto bo8XP; t7o3J: try { $LAwgR = Artisan::call('migrate'); } catch (\Exception $Q19lV) { return $this->handleException($Q19lV); } goto CzULW; aS3p5: if ($plEpl && file_exists($rZJie = public_path('data_demo/data.php'))) { goto av189; av189: $xJzrK = (include $rZJie); goto xVF20; xVF20: if (!empty($xJzrK['inserts'])) { foreach ($xJzrK['inserts'] as $TNrxH => $i7_Nb) { ModelUtil::insertAll($TNrxH, $i7_Nb); } } goto ckvR1; ckvR1: if (!empty($xJzrK['updates'])) { foreach ($xJzrK['updates'] as $gH1Sv) { DB::table($gH1Sv['table'])->where($gH1Sv['where'])->update($gH1Sv['update']); } } goto IKiOB; IKiOB: } goto DZD_x; U0MQ7: $plEpl = $OPo_x->getBoolean('installDemo'); goto slR_J; N8SAg: if (empty($wJyCj)) { return Response::jsonError('管理用户密码为空'); } goto fNV8L; O7RC2: } private function handleException(\Exception $Q19lV) { goto at6dV; YbIfE: if (preg_match('/Table \'(.*?)\' already exists/', $pwDm3, $okKGo)) { return Response::jsonError('数据表 ' . $okKGo[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto R4XL0; R4XL0: if (preg_match('/Duplicate column name \'(.*?)\'/', $pwDm3, $okKGo)) { goto uQm3v; uQm3v: $aR4e2 = $okKGo[1]; goto J_Hno; J_Hno: $rZJie = null; goto BTA53; u9Ez_: return Response::jsonError('数据表字段 ' . $aR4e2 . ' 已经存在（请查看' . $rZJie . '迁移文件配置）'); goto Hmtcs; BTA53: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $NuiyW, $okKGo)) { $rZJie = $okKGo[1]; } goto u9Ez_; Hmtcs: } goto WK8jh; WK8jh: throw $Q19lV; goto C14xo; VxGlP: $NuiyW = $Q19lV->getTraceAsString(); goto YbIfE; at6dV: $pwDm3 = $Q19lV->getMessage(); goto VxGlP; C14xo: } }