<?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 xcz4t; zRJ1d: file_put_contents($ML53l, 'lock'); goto os3zh; os3zh: return Response::send(0, 'install lock ok ^_^'); goto i3o_v; N53x1: if (file_exists($ML53l)) { return Response::send(0, 'install lock error -_-'); } goto zRJ1d; xcz4t: $ML53l = storage_path('install.lock'); goto N53x1; i3o_v: } public function ping() { try { goto AeeDE; dX6le: return 'ERROR: code=' . $ppEQn . ', msg:' . $Q7EdD; goto gf5t7; I_BKB: if (0 == $ppEQn) { if (Str::contains($Q7EdD, 'Current application environment')) { return 'ok'; } if (Str::contains($Q7EdD, 'The application environment is')) { return 'ok'; } } goto dX6le; r3Ywn: $Q7EdD = trim(Artisan::output()); goto I_BKB; AeeDE: $ppEQn = Artisan::call('env'); goto r3Ywn; gf5t7: } catch (\Exception $RWZxh) { return 'ERROR:' . $RWZxh->getMessage(); } } public function prepare() { goto lvI0Y; sOjMo: $X1D0q = $tBuXm->getJson('INSTALL_CONFIG'); goto FByuo; kW9l0: $CQDIX = file_get_contents(base_path('env.example')); goto ZKa4Q; rA9cF: return Response::jsonSuccess(); goto iYEdm; PpzaE: if (!empty($X1D0q['envs'])) { foreach ($X1D0q['envs'] as $nrWoZ) { $CQDIX = preg_replace('/' . $nrWoZ['name'] . '=(.*?)\\n/', $nrWoZ['name'] . '=' . $tBuXm->getTrimString($nrWoZ['name']) . '
', $CQDIX); } } goto PbR8x; AcJrg: $CQDIX = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $sqhVu . '
', $CQDIX); goto bNSC3; uZ0Bq: if (empty($brUoS)) { return Response::jsonError('数据库端口不能为空'); } goto jWGfK; bNSC3: $CQDIX = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $CQDIX); goto PpzaE; Q8A31: if (file_exists($Kdiu6 = base_path('.env'))) { $V0Dls = file_get_contents($Kdiu6); if (str_contains($V0Dls, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto vVigs; G0y8D: $OorQQ = $tBuXm->getBoolean('installDemo'); goto m4Q0L; JIIQ4: try { new PDO("mysql:host={$Mtsce};port={$brUoS};dbname={$VegSa}", $eX5Y2, $ng9J5); } catch (\Exception $RWZxh) { goto uIB4Q; wH07S: Log::error('InstallError -> ' . $RWZxh->getMessage() . ' -> ' . $RWZxh->getTraceAsString()); goto RCK3p; uIB4Q: $trk4v = $RWZxh->getMessage(); goto tHr_P; tHr_P: if (str_contains($trk4v, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $trk4v); } else { if (str_contains($trk4v, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $trk4v); } } goto wH07S; RCK3p: return Response::jsonError('连接数据信息 ' . $Mtsce . ':' . $brUoS . '.' . $VegSa . ' 失败!'); goto up0nb; up0nb: } goto kW9l0; pvED2: $brUoS = $tBuXm->getTrimString('db_port'); goto BoUG0; wfGeU: $CQDIX = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $VegSa . '
', $CQDIX); goto f8cl2; nU1Th: $nfE6o = $tBuXm->getTrimString('username'); goto aWaQg; jWGfK: if (empty($VegSa)) { return Response::jsonError('数据库数据库不能为空'); } goto DcpHp; nwC8b: $sqhVu = $tBuXm->getTrimString('db_prefix', ''); goto nU1Th; tA9Pf: if (empty($nfE6o)) { return Response::jsonError('管理用户不能为空'); } goto ouK4S; ouK4S: if (empty($wxnHg)) { return Response::jsonError('管理用户密码不能为空'); } goto iUTXS; aWaQg: $wxnHg = $tBuXm->getTrimString('password'); goto G0y8D; ZKa4Q: $CQDIX = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $Mtsce . '
', $CQDIX); goto SRhNs; BoUG0: $VegSa = $tBuXm->getTrimString('db_database'); goto tUnud; tUnud: $eX5Y2 = $tBuXm->getTrimString('db_username'); goto cYrcR; lvI0Y: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto Q8A31; vVigs: $tBuXm = InputPackage::buildFromInput(); goto mXNSE; DcpHp: if (empty($eX5Y2)) { return Response::jsonError('数据库用户名不能为空'); } goto tA9Pf; iUTXS: if (file_exists(base_path('license_url.txt')) && !$QCOwp) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto JIIQ4; FByuo: if (empty($Mtsce)) { return Response::jsonError('数据库主机名不能为空'); } goto uZ0Bq; cvfSY: $CQDIX = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $ng9J5 . '
', $CQDIX); goto AcJrg; mXNSE: $Mtsce = $tBuXm->getTrimString('db_host'); goto pvED2; PbR8x: file_put_contents(base_path('.env'), $CQDIX); goto rA9cF; cYrcR: $ng9J5 = $tBuXm->getTrimString('db_password', ''); goto nwC8b; f8cl2: $CQDIX = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $eX5Y2 . '
', $CQDIX); goto cvfSY; m4Q0L: $QCOwp = $tBuXm->getBoolean('installLicense'); goto sOjMo; SRhNs: $CQDIX = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $brUoS . '
', $CQDIX); goto wfGeU; iYEdm: } public function execute() { goto z17Fv; v29zl: $wxnHg = $tBuXm->getTrimString('password'); goto E7oJh; JjzWU: try { $ppEQn = Artisan::call('migrate'); } catch (\Exception $RWZxh) { return $this->handleException($RWZxh); } goto rRXbO; BwPtM: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto LOeX2; Rnn9c: if ($OorQQ && file_exists($okURS = public_path('data_demo/data.php'))) { goto T1A9I; Eiw16: if (!empty($cwaKT['inserts'])) { foreach ($cwaKT['inserts'] as $hTN3M => $Y9WQp) { ModelUtil::insertAll($hTN3M, $Y9WQp); } } goto FC4Hd; FC4Hd: if (!empty($cwaKT['updates'])) { foreach ($cwaKT['updates'] as $rpy90) { DB::table($rpy90['table'])->where($rpy90['where'])->update($rpy90['update']); } } goto ILR63; T1A9I: $cwaKT = (include $okURS); goto Eiw16; ILR63: } goto hhKJM; S1115: if (empty($wxnHg)) { return Response::jsonError('管理用户密码为空'); } goto Ul6ft; E7oJh: $OorQQ = $tBuXm->getBoolean('installDemo'); goto MPUjx; B8PBX: if ($Roi7f === 0) { Admin::add($nfE6o, $wxnHg); } goto Lcn7w; z17Fv: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto f85zn; Lcn7w: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $FgH5V) { goto j5H0R; peNy2: if (Response::isError($ZrjxR)) { return Response::generateError($ZrjxR['msg']); } goto STIsk; wDzhL: try { $ZrjxR = ModuleManager::install($FgH5V); } catch (\Exception $RWZxh) { return $this->handleException($RWZxh); } goto peNy2; j5H0R: if (!ModuleManager::isExists($FgH5V)) { continue; } goto wDzhL; STIsk: } goto Rnn9c; RvsAd: $ppEQn = 0; goto JjzWU; X3O8r: $nfE6o = $tBuXm->getTrimString('username'); goto v29zl; Ul6ft: set_time_limit(0); goto RvsAd; hhKJM: file_put_contents(storage_path('install.lock'), 'lock'); goto BwPtM; rRXbO: if (0 != $ppEQn) { return Response::jsonError("安装错误 exitCode({$ppEQn})"); } goto YZjHt; MPUjx: if (empty($nfE6o)) { return Response::jsonError('管理用户名为空'); } goto S1115; YZjHt: $Roi7f = ModelUtil::count('admin_user'); goto B8PBX; f85zn: $tBuXm = InputPackage::buildFromInput(); goto X3O8r; LOeX2: } private function handleException(\Exception $RWZxh) { goto tGIfg; ow9kF: throw $RWZxh; goto Uky7D; dhV3D: $xHnws = $RWZxh->getTraceAsString(); goto LQxu9; LQxu9: if (preg_match('/Table \'(.*?)\' already exists/', $trk4v, $YpeHe)) { return Response::jsonError('数据表 ' . $YpeHe[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto kwvbo; tGIfg: $trk4v = $RWZxh->getMessage(); goto dhV3D; kwvbo: if (preg_match('/Duplicate column name \'(.*?)\'/', $trk4v, $YpeHe)) { goto w9a0C; RxCmN: return Response::jsonError('数据表字段 ' . $Wvq57 . ' 已经存在（请查看' . $okURS . '迁移文件配置）'); goto YwadC; HuXw1: $okURS = null; goto DLMyy; DLMyy: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $xHnws, $YpeHe)) { $okURS = $YpeHe[1]; } goto RxCmN; w9a0C: $Wvq57 = $YpeHe[1]; goto HuXw1; YwadC: } goto ow9kF; Uky7D: } }