<?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 rXmpa; rXmpa: $gdHgn = storage_path('install.lock'); goto uDgSp; dD3ys: return Response::send(0, 'install lock ok ^_^'); goto UESS8; Ng4if: file_put_contents($gdHgn, 'lock'); goto dD3ys; uDgSp: if (file_exists($gdHgn)) { return Response::send(0, 'install lock error -_-'); } goto Ng4if; UESS8: } public function ping() { try { goto mu1XM; mu1XM: $h0L7n = Artisan::call('env'); goto ZJQbV; Q7WXm: if (0 == $h0L7n) { if (Str::contains($Tvp0d, 'Current application environment')) { return 'ok'; } if (Str::contains($Tvp0d, 'The application environment is')) { return 'ok'; } } goto anIKm; ZJQbV: $Tvp0d = trim(Artisan::output()); goto Q7WXm; anIKm: return 'ERROR: code=' . $h0L7n . ', msg:' . $Tvp0d; goto zrCwH; zrCwH: } catch (\Exception $fWY9h) { return 'ERROR:' . $fWY9h->getMessage(); } } public function prepare() { goto bdrTp; elvPW: if (empty($yAgaL)) { return Response::jsonError('数据库主机名不能为空'); } goto x3YHk; TImzj: $fzNU0 = $Nw6ws->getBoolean('installLicense'); goto xCujx; gQN2q: $ZMPq_ = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $LGQ0V . '
', $ZMPq_); goto oYkxs; qeZwd: $f6vte = $Nw6ws->getTrimString('username'); goto VKPx_; Rvw4I: $ZMPq_ = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $ZMPq_); goto wkzF4; g0gJE: $ZMPq_ = file_get_contents(base_path('env.example')); goto gHJAH; z4dsJ: $FUVDX = $Nw6ws->getTrimString('db_prefix', ''); goto qeZwd; DcIZ1: if (empty($vuuUq)) { return Response::jsonError('数据库数据库不能为空'); } goto RYyk5; u4yxn: $vMxiX = $Nw6ws->getBoolean('installDemo'); goto TImzj; tZqEs: $ZMPq_ = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $vuuUq . '
', $ZMPq_); goto gQN2q; x3YHk: if (empty($rYHyt)) { return Response::jsonError('数据库端口不能为空'); } goto DcIZ1; wSrlD: try { new PDO("mysql:host={$yAgaL};port={$rYHyt};dbname={$vuuUq}", $LGQ0V, $bHRPl); } catch (\Exception $fWY9h) { goto NDm_C; JIXwM: if (str_contains($JGWZb, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $JGWZb); } else { if (str_contains($JGWZb, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $JGWZb); } } goto zj8ti; zj8ti: Log::error('InstallError -> ' . $fWY9h->getMessage() . ' -> ' . $fWY9h->getTraceAsString()); goto BBwRP; NDm_C: $JGWZb = $fWY9h->getMessage(); goto JIXwM; BBwRP: return Response::jsonError('连接数据信息 ' . $yAgaL . ':' . $rYHyt . '.' . $vuuUq . ' 失败!'); goto hUa7S; hUa7S: } goto g0gJE; mWfpR: return Response::jsonSuccess(); goto HGRXK; diuPR: if (empty($f6vte)) { return Response::jsonError('管理用户不能为空'); } goto aAm1w; bdrTp: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto M4fU_; uk_AX: if (file_exists(base_path('license_url.txt')) && !$fzNU0) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto wSrlD; DsB5Y: $ZMPq_ = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $rYHyt . '
', $ZMPq_); goto tZqEs; VKPx_: $iJwHS = $Nw6ws->getTrimString('password'); goto u4yxn; BRdTj: $bHRPl = $Nw6ws->getTrimString('db_password', ''); goto z4dsJ; wkzF4: if (!empty($kzY9U['envs'])) { foreach ($kzY9U['envs'] as $qfx0Y) { $ZMPq_ = preg_replace('/' . $qfx0Y['name'] . '=(.*?)\\n/', $qfx0Y['name'] . '=' . $Nw6ws->getTrimString($qfx0Y['name']) . '
', $ZMPq_); } } goto Otk1e; rluex: $rYHyt = $Nw6ws->getTrimString('db_port'); goto RQZh0; Otk1e: file_put_contents(base_path('.env'), $ZMPq_); goto mWfpR; pmjOI: $ZMPq_ = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $FUVDX . '
', $ZMPq_); goto Rvw4I; PCRV_: $LGQ0V = $Nw6ws->getTrimString('db_username'); goto BRdTj; gHJAH: $ZMPq_ = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $yAgaL . '
', $ZMPq_); goto DsB5Y; G7eNc: $yAgaL = $Nw6ws->getTrimString('db_host'); goto rluex; xCujx: $kzY9U = $Nw6ws->getJson('INSTALL_CONFIG'); goto elvPW; ZqmqV: $Nw6ws = InputPackage::buildFromInput(); goto G7eNc; RYyk5: if (empty($LGQ0V)) { return Response::jsonError('数据库用户名不能为空'); } goto diuPR; M4fU_: if (file_exists($ArHwJ = base_path('.env'))) { $MPmfx = file_get_contents($ArHwJ); if (str_contains($MPmfx, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto ZqmqV; oYkxs: $ZMPq_ = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $bHRPl . '
', $ZMPq_); goto pmjOI; RQZh0: $vuuUq = $Nw6ws->getTrimString('db_database'); goto PCRV_; aAm1w: if (empty($iJwHS)) { return Response::jsonError('管理用户密码不能为空'); } goto uk_AX; HGRXK: } public function execute() { goto MYCGF; JPIdx: if (empty($iJwHS)) { return Response::jsonError('管理用户密码为空'); } goto qGoqX; b1qpq: $f6vte = $Nw6ws->getTrimString('username'); goto h77L2; zhAgK: $v2yTD = ModelUtil::count('admin_user'); goto X4Yb3; Hur_x: try { $h0L7n = Artisan::call('migrate'); } catch (\Exception $fWY9h) { return $this->handleException($fWY9h); } goto WOFef; k6O4R: $h0L7n = 0; goto Hur_x; qo85B: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto kMEPi; m0fbW: file_put_contents(storage_path('install.lock'), 'lock'); goto qo85B; MYCGF: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto EcU0F; h77L2: $iJwHS = $Nw6ws->getTrimString('password'); goto G28vC; EcU0F: $Nw6ws = InputPackage::buildFromInput(); goto b1qpq; qGoqX: set_time_limit(0); goto k6O4R; NBUAB: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $lMMoV) { goto A_0gT; DF80v: try { $Ecj99 = ModuleManager::install($lMMoV); } catch (\Exception $fWY9h) { return $this->handleException($fWY9h); } goto bQNc0; bQNc0: if (Response::isError($Ecj99)) { return Response::generateError($Ecj99['msg']); } goto V_4D0; A_0gT: if (!ModuleManager::isExists($lMMoV)) { continue; } goto DF80v; V_4D0: } goto Zgd4D; Zgd4D: if ($vMxiX && file_exists($Jm77a = public_path('data_demo/data.php'))) { goto qa0S5; qa0S5: $Pg57y = (include $Jm77a); goto DhAEL; DhAEL: if (!empty($Pg57y['inserts'])) { foreach ($Pg57y['inserts'] as $tM63P => $XsrNI) { ModelUtil::insertAll($tM63P, $XsrNI); } } goto vendj; vendj: if (!empty($Pg57y['updates'])) { foreach ($Pg57y['updates'] as $HKoLA) { DB::table($HKoLA['table'])->where($HKoLA['where'])->update($HKoLA['update']); } } goto AUVTq; AUVTq: } goto m0fbW; G28vC: $vMxiX = $Nw6ws->getBoolean('installDemo'); goto RONPR; RONPR: if (empty($f6vte)) { return Response::jsonError('管理用户名为空'); } goto JPIdx; X4Yb3: if ($v2yTD === 0) { Admin::add($f6vte, $iJwHS); } goto NBUAB; WOFef: if (0 != $h0L7n) { return Response::jsonError("安装错误 exitCode({$h0L7n})"); } goto zhAgK; kMEPi: } private function handleException(\Exception $fWY9h) { goto tLZes; bsHrA: if (preg_match('/Duplicate column name \'(.*?)\'/', $JGWZb, $Uy2Nw)) { goto VWhe5; VWhe5: $UdGHQ = $Uy2Nw[1]; goto OTyrE; Vh6_N: return Response::jsonError('数据表字段 ' . $UdGHQ . ' 已经存在（请查看' . $Jm77a . '迁移文件配置）'); goto vWxEu; wOeVl: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $lKme2, $Uy2Nw)) { $Jm77a = $Uy2Nw[1]; } goto Vh6_N; OTyrE: $Jm77a = null; goto wOeVl; vWxEu: } goto MTAuU; VnoZT: if (preg_match('/Table \'(.*?)\' already exists/', $JGWZb, $Uy2Nw)) { return Response::jsonError('数据表 ' . $Uy2Nw[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto bsHrA; MTAuU: throw $fWY9h; goto Hj0ND; RgDQb: $lKme2 = $fWY9h->getTraceAsString(); goto VnoZT; tLZes: $JGWZb = $fWY9h->getMessage(); goto RgDQb; Hj0ND: } }