<?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 FiXsg; dzx4D: if (file_exists($aGa_B)) { return Response::send(0, 'install lock error -_-'); } goto gWHSt; rRvr5: return Response::send(0, 'install lock ok ^_^'); goto bI3zk; gWHSt: file_put_contents($aGa_B, 'lock'); goto rRvr5; FiXsg: $aGa_B = storage_path('install.lock'); goto dzx4D; bI3zk: } public function ping() { try { goto bmDjA; bmDjA: $yTeE1 = Artisan::call('env'); goto cnRrT; HTGSc: return 'ERROR: code=' . $yTeE1 . ', msg:' . $Mrc1Z; goto LKxEH; cnRrT: $Mrc1Z = trim(Artisan::output()); goto eDdg9; eDdg9: if (0 == $yTeE1) { if (Str::contains($Mrc1Z, 'Current application environment')) { return 'ok'; } if (Str::contains($Mrc1Z, 'The application environment is')) { return 'ok'; } } goto HTGSc; LKxEH: } catch (\Exception $re7gC) { return 'ERROR:' . $re7gC->getMessage(); } } public function prepare() { goto KfWM0; W1_1i: $mEn8A = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $zIUOQ . '
', $mEn8A); goto DHYY3; OVNb6: $jSLXk = $i3uTh->getBoolean('installDemo'); goto Q8x8q; P8QcC: if (empty($Kb2J0)) { return Response::jsonError('数据库主机名不能为空'); } goto sR1LO; IrIg5: $mEn8A = file_get_contents(base_path('env.example')); goto j3R3z; OBzi_: $rt4Ku = $i3uTh->getTrimString('db_port'); goto kW4Cz; fQuK0: $mEn8A = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $mEn8A); goto c7lsc; B9M83: $i3uTh = InputPackage::buildFromInput(); goto pTpue; j3R3z: $mEn8A = preg_replace('/APP_DEBUG=(.*?)\\n/', 'APP_DEBUG=false
', $mEn8A); goto uS0Tq; sR1LO: if (empty($rt4Ku)) { return Response::jsonError('数据库端口不能为空'); } goto Tw55u; rgNyK: file_put_contents(base_path('.env'), $mEn8A); goto gp9vg; pTpue: $Kb2J0 = $i3uTh->getTrimString('db_host'); goto OBzi_; zGaMi: $nwrAH = $i3uTh->getTrimString('password'); goto OVNb6; DHYY3: $mEn8A = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $xzErn . '
', $mEn8A); goto aji8u; ZwE17: $mEn8A = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $rt4Ku . '
', $mEn8A); goto W1_1i; Tw55u: if (empty($zIUOQ)) { return Response::jsonError('数据库数据库不能为空'); } goto B8QZI; btdcV: $BG5oe = $i3uTh->getTrimString('username'); goto zGaMi; aji8u: $mEn8A = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $OGp1z . '
', $mEn8A); goto BMsU0; hBO62: if (file_exists($MtfSQ = base_path('.env'))) { $Ral1i = file_get_contents($MtfSQ); if (str_contains($Ral1i, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto B9M83; c7lsc: $mEn8A = preg_replace('/ENCRYPT_KEY=(.*?)\\n/', 'ENCRYPT_KEY=' . RandomUtil::string(32) . '
', $mEn8A); goto mGTR6; gp9vg: return Response::jsonSuccess(); goto nLhfv; IXxjT: if (empty($nwrAH)) { return Response::jsonError('管理用户密码不能为空'); } goto rfwYt; rfwYt: if (file_exists(base_path('license_url.txt')) && !$doAGc) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto CppmI; mGTR6: if (!empty($hdgn0['envs'])) { foreach ($hdgn0['envs'] as $WBvBM) { $mEn8A = preg_replace('/' . $WBvBM['name'] . '=(.*?)\\n/', $WBvBM['name'] . '=' . $i3uTh->getTrimString($WBvBM['name']) . '
', $mEn8A); } } goto rgNyK; Q8x8q: $doAGc = $i3uTh->getBoolean('installLicense'); goto pJotA; B8QZI: if (empty($xzErn)) { return Response::jsonError('数据库用户名不能为空'); } goto dtcHK; BMsU0: $mEn8A = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $mSPPl . '
', $mEn8A); goto fQuK0; CppmI: try { new PDO("mysql:host={$Kb2J0};port={$rt4Ku};dbname={$zIUOQ}", $xzErn, $OGp1z); } catch (\Exception $re7gC) { goto VYhZg; VYhZg: $Lo_ux = $re7gC->getMessage(); goto XYuk5; xjXzA: return Response::jsonError('连接数据信息 ' . $Kb2J0 . ':' . $rt4Ku . '.' . $zIUOQ . ' 失败!'); goto tkTzC; nE_Aw: Log::error('InstallError -> ' . $re7gC->getMessage() . ' -> ' . $re7gC->getTraceAsString()); goto xjXzA; XYuk5: if (str_contains($Lo_ux, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $Lo_ux); } else { if (str_contains($Lo_ux, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $Lo_ux); } } goto nE_Aw; tkTzC: } goto IrIg5; iPz7l: $mSPPl = $i3uTh->getTrimString('db_prefix', ''); goto btdcV; KfWM0: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto hBO62; CNUr0: $OGp1z = $i3uTh->getTrimString('db_password', ''); goto iPz7l; dtcHK: if (empty($BG5oe)) { return Response::jsonError('管理用户不能为空'); } goto IXxjT; pJotA: $hdgn0 = $i3uTh->getJson('INSTALL_CONFIG'); goto P8QcC; kW4Cz: $zIUOQ = $i3uTh->getTrimString('db_database'); goto scxqj; uS0Tq: $mEn8A = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $Kb2J0 . '
', $mEn8A); goto ZwE17; scxqj: $xzErn = $i3uTh->getTrimString('db_username'); goto CNUr0; nLhfv: } public function execute() { goto FA3N7; uCVE9: $yTeE1 = 0; goto djuSK; PxPho: $i3uTh = InputPackage::buildFromInput(); goto aK_Rv; djuSK: try { $yTeE1 = Artisan::call('migrate'); } catch (\Exception $re7gC) { return $this->handleException($re7gC); } goto kYMPs; IXVwm: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto TTAKY; n7hB7: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $z_J2N) { goto Tck4N; PO8Y6: try { $gMg9x = ModuleManager::install($z_J2N); } catch (\Exception $re7gC) { return $this->handleException($re7gC); } goto uCJIj; Tck4N: if (!ModuleManager::isExists($z_J2N)) { continue; } goto PO8Y6; uCJIj: if (Response::isError($gMg9x)) { return Response::generateError($gMg9x['msg']); } goto GGxg6; GGxg6: } goto TrPHK; aK_Rv: $BG5oe = $i3uTh->getTrimString('username'); goto oBt9o; UYIgt: if (empty($BG5oe)) { return Response::jsonError('管理用户名为空'); } goto pwAlv; mEYMg: $jSLXk = $i3uTh->getBoolean('installDemo'); goto UYIgt; oBt9o: $nwrAH = $i3uTh->getTrimString('password'); goto mEYMg; TrPHK: if ($jSLXk && file_exists($wjJPd = public_path('data_demo/data.php'))) { goto tR3ky; yxUPz: if (!empty($GpXwG['updates'])) { foreach ($GpXwG['updates'] as $ksviT) { DB::table($ksviT['table'])->where($ksviT['where'])->update($ksviT['update']); } } goto yBJOh; wFqcD: if (!empty($GpXwG['inserts'])) { foreach ($GpXwG['inserts'] as $gCb7f => $b3yWT) { ModelUtil::insertAll($gCb7f, $b3yWT); } } goto yxUPz; tR3ky: $GpXwG = (include $wjJPd); goto wFqcD; yBJOh: } goto ses_f; FA3N7: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto PxPho; ses_f: file_put_contents(storage_path('install.lock'), 'lock'); goto IXVwm; pwAlv: if (empty($nwrAH)) { return Response::jsonError('管理用户密码为空'); } goto fdyNf; N6OEn: if ($PSNbS === 0) { Admin::add($BG5oe, $nwrAH); } goto n7hB7; fdyNf: set_time_limit(0); goto uCVE9; PYY0D: $PSNbS = ModelUtil::count('admin_user'); goto N6OEn; kYMPs: if (0 != $yTeE1) { return Response::jsonError("安装错误 exitCode({$yTeE1})"); } goto PYY0D; TTAKY: } private function handleException(\Exception $re7gC) { goto QecYT; FLHJT: if (preg_match('/Duplicate column name \'(.*?)\'/', $Lo_ux, $oxpiO)) { goto nR_Gd; NY56k: return Response::jsonError('数据表字段 ' . $A02Yi . ' 已经存在（请查看' . $wjJPd . '迁移文件配置）'); goto qp3B1; aTJMB: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $gjALn, $oxpiO)) { $wjJPd = $oxpiO[1]; } goto NY56k; ZZlas: $wjJPd = null; goto aTJMB; nR_Gd: $A02Yi = $oxpiO[1]; goto ZZlas; qp3B1: } goto zdfGz; eP43U: $gjALn = $re7gC->getTraceAsString(); goto lSIWn; lSIWn: if (preg_match('/Table \'(.*?)\' already exists/', $Lo_ux, $oxpiO)) { return Response::jsonError('数据表 ' . $oxpiO[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto FLHJT; zdfGz: throw $re7gC; goto YxmiZ; QecYT: $Lo_ux = $re7gC->getMessage(); goto eP43U; YxmiZ: } }