<?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 E2MYB; E2MYB: $dr468 = storage_path('install.lock'); goto TYZje; l7EZI: file_put_contents($dr468, 'lock'); goto YchvD; TYZje: if (file_exists($dr468)) { return Response::send(0, 'install lock error -_-'); } goto l7EZI; YchvD: return Response::send(0, 'install lock ok ^_^'); goto Vv6iU; Vv6iU: } public function ping() { try { goto VpfJH; VpfJH: $rx99h = Artisan::call('env'); goto U__MR; lRzXK: if (0 == $rx99h) { if (Str::contains($m8MNu, 'Current application environment')) { return 'ok'; } if (Str::contains($m8MNu, 'The application environment is')) { return 'ok'; } } goto jesuQ; U__MR: $m8MNu = trim(Artisan::output()); goto lRzXK; jesuQ: return 'ERROR: code=' . $rx99h . ', msg:' . $m8MNu; goto XAJqc; XAJqc: } catch (\Exception $se7TW) { return 'ERROR:' . $se7TW->getMessage(); } } public function prepare() { goto boBxh; jQxGJ: $YRYH_ = $Q9nmo->getJson('INSTALL_CONFIG'); goto sGVi8; JASuO: $p6Lnb = $Q9nmo->getBoolean('installLicense'); goto jQxGJ; r35FV: if (file_exists($A9UeD = base_path('.env'))) { $OfwYj = file_get_contents($A9UeD); if (str_contains($OfwYj, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto SBMLS; e7HyJ: $wlbVM = $Q9nmo->getTrimString('db_port'); goto C_QBi; YUpFk: $NGzbg = $Q9nmo->getTrimString('db_username'); goto QNN2U; Oizea: $b5Apd = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $b5Apd); goto spJ3_; spJ3_: if (!empty($YRYH_['envs'])) { foreach ($YRYH_['envs'] as $mfgxM) { $b5Apd = preg_replace('/' . $mfgxM['name'] . '=(.*?)\\n/', $mfgxM['name'] . '=' . $Q9nmo->getTrimString($mfgxM['name']) . '
', $b5Apd); } } goto sHfKD; JPww8: $ydZtn = $Q9nmo->getBoolean('installDemo'); goto JASuO; UoIHm: $yzR4u = $Q9nmo->getTrimString('password'); goto JPww8; Wq1gA: if (empty($wlbVM)) { return Response::jsonError('数据库端口不能为空'); } goto jS5z5; kU1sx: if (empty($BY7ng)) { return Response::jsonError('管理用户不能为空'); } goto qQn2u; l_DrU: $b5Apd = file_get_contents(base_path('env.example')); goto UNmPj; mFUb0: if (empty($NGzbg)) { return Response::jsonError('数据库用户名不能为空'); } goto kU1sx; boBxh: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto r35FV; Y4hO1: $b5Apd = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $NGzbg . '
', $b5Apd); goto oQgeA; NRl8d: if (file_exists(base_path('license_url.txt')) && !$p6Lnb) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto lda22; QNN2U: $rg_b0 = $Q9nmo->getTrimString('db_password', ''); goto Veqlc; hD03W: $b5Apd = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $qX8KE . '
', $b5Apd); goto Y4hO1; pGnpx: $BY7ng = $Q9nmo->getTrimString('username'); goto UoIHm; ofYpU: return Response::jsonSuccess(); goto q8p03; w4BE0: $b5Apd = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $T3E8f . '
', $b5Apd); goto Oizea; lda22: try { new PDO("mysql:host={$YfU6f};port={$wlbVM};dbname={$qX8KE}", $NGzbg, $rg_b0); } catch (\Exception $se7TW) { goto N5Zuc; TD5tF: if (str_contains($ZjKo3, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $ZjKo3); } else { if (str_contains($ZjKo3, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $ZjKo3); } } goto qUYYc; N5Zuc: $ZjKo3 = $se7TW->getMessage(); goto TD5tF; kqs_4: return Response::jsonError('连接数据信息 ' . $YfU6f . ':' . $wlbVM . '.' . $qX8KE . ' 失败!'); goto q7oSG; qUYYc: Log::error('InstallError -> ' . $se7TW->getMessage() . ' -> ' . $se7TW->getTraceAsString()); goto kqs_4; q7oSG: } goto l_DrU; sHfKD: file_put_contents(base_path('.env'), $b5Apd); goto ofYpU; SrNBE: $b5Apd = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $wlbVM . '
', $b5Apd); goto hD03W; Veqlc: $T3E8f = $Q9nmo->getTrimString('db_prefix', ''); goto pGnpx; SBMLS: $Q9nmo = InputPackage::buildFromInput(); goto qF1mF; qF1mF: $YfU6f = $Q9nmo->getTrimString('db_host'); goto e7HyJ; UNmPj: $b5Apd = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $YfU6f . '
', $b5Apd); goto SrNBE; oQgeA: $b5Apd = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $rg_b0 . '
', $b5Apd); goto w4BE0; jS5z5: if (empty($qX8KE)) { return Response::jsonError('数据库数据库不能为空'); } goto mFUb0; qQn2u: if (empty($yzR4u)) { return Response::jsonError('管理用户密码不能为空'); } goto NRl8d; sGVi8: if (empty($YfU6f)) { return Response::jsonError('数据库主机名不能为空'); } goto Wq1gA; C_QBi: $qX8KE = $Q9nmo->getTrimString('db_database'); goto YUpFk; q8p03: } public function execute() { goto nQ7db; d9CG4: if (0 != $rx99h) { return Response::jsonError("安装错误 exitCode({$rx99h})"); } goto qnEMn; Ct3fR: try { $rx99h = Artisan::call('migrate'); } catch (\Exception $se7TW) { return $this->handleException($se7TW); } goto d9CG4; DD1cf: if ($ydZtn && file_exists($SgkW3 = public_path('data_demo/data.php'))) { goto W_hgv; W_hgv: $MGhSY = (include $SgkW3); goto MDug4; MDug4: if (!empty($MGhSY['inserts'])) { foreach ($MGhSY['inserts'] as $pknhs => $ZzHwD) { ModelUtil::insertAll($pknhs, $ZzHwD); } } goto WDEhx; WDEhx: if (!empty($MGhSY['updates'])) { foreach ($MGhSY['updates'] as $gvTPQ) { DB::table($gvTPQ['table'])->where($gvTPQ['where'])->update($gvTPQ['update']); } } goto o22KF; o22KF: } goto IsniS; Ko99a: $BY7ng = $Q9nmo->getTrimString('username'); goto Dbo6u; nQ7db: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto tb2qK; sMGQz: set_time_limit(0); goto S8cDp; IsniS: file_put_contents(storage_path('install.lock'), 'lock'); goto t3mzg; uPJrT: if (empty($BY7ng)) { return Response::jsonError('管理用户名为空'); } goto G61ca; t3mzg: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto hlUOx; qnEMn: $hdRCv = ModelUtil::count('admin_user'); goto HJ1zX; HJ1zX: if ($hdRCv === 0) { Admin::add($BY7ng, $yzR4u); } goto eI7sN; eI7sN: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $Ua5sf) { goto er2Pb; uw2o3: if (Response::isError($om_hh)) { return Response::generateError($om_hh['msg']); } goto Fx2ey; Jdsa8: try { $om_hh = ModuleManager::install($Ua5sf); } catch (\Exception $se7TW) { return $this->handleException($se7TW); } goto uw2o3; er2Pb: if (!ModuleManager::isExists($Ua5sf)) { continue; } goto Jdsa8; Fx2ey: } goto DD1cf; qtL9M: $ydZtn = $Q9nmo->getBoolean('installDemo'); goto uPJrT; Dbo6u: $yzR4u = $Q9nmo->getTrimString('password'); goto qtL9M; G61ca: if (empty($yzR4u)) { return Response::jsonError('管理用户密码为空'); } goto sMGQz; S8cDp: $rx99h = 0; goto Ct3fR; tb2qK: $Q9nmo = InputPackage::buildFromInput(); goto Ko99a; hlUOx: } private function handleException(\Exception $se7TW) { goto lg4Ds; htCpX: if (preg_match('/Duplicate column name \'(.*?)\'/', $ZjKo3, $QuDiu)) { goto SNMMf; SNMMf: $TMEcx = $QuDiu[1]; goto kU0z9; xY_KH: return Response::jsonError('数据表字段 ' . $TMEcx . ' 已经存在（请查看' . $SgkW3 . '迁移文件配置）'); goto IP_7W; UiO79: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $JLxjr, $QuDiu)) { $SgkW3 = $QuDiu[1]; } goto xY_KH; kU0z9: $SgkW3 = null; goto UiO79; IP_7W: } goto mhcB3; lg4Ds: $ZjKo3 = $se7TW->getMessage(); goto EjI3d; EnYmX: if (preg_match('/Table \'(.*?)\' already exists/', $ZjKo3, $QuDiu)) { return Response::jsonError('数据表 ' . $QuDiu[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto htCpX; EjI3d: $JLxjr = $se7TW->getTraceAsString(); goto EnYmX; mhcB3: throw $se7TW; goto DfsHW; DfsHW: } }