<?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 LBFeM; LBFeM: $zSJ3L = storage_path('install.lock'); goto R94Eg; QErWu: return Response::send(0, 'install lock ok ^_^'); goto crI9O; R94Eg: if (file_exists($zSJ3L)) { return Response::send(0, 'install lock error -_-'); } goto bFejN; bFejN: file_put_contents($zSJ3L, 'lock'); goto QErWu; crI9O: } public function ping() { try { goto dXF7T; SdrFw: $Y3VCG = trim(Artisan::output()); goto r1VU_; nIT6x: return 'ERROR: code=' . $SvOVI . ', msg:' . $Y3VCG; goto rSfM5; dXF7T: $SvOVI = Artisan::call('env'); goto SdrFw; r1VU_: if (0 == $SvOVI) { if (Str::contains($Y3VCG, 'Current application environment')) { return 'ok'; } if (Str::contains($Y3VCG, 'The application environment is')) { return 'ok'; } } goto nIT6x; rSfM5: } catch (\Exception $cknMI) { return 'ERROR:' . $cknMI->getMessage(); } } public function prepare() { goto UBDTF; cVjSC: $Z8_ay = preg_replace('/DB_DATABASE=(.*?)\\n/', 'DB_DATABASE=' . $ERQd1 . '
', $Z8_ay); goto YIp_U; JNvJx: $Z8_ay = preg_replace('/DB_PORT=(.*?)\\n/', 'DB_PORT=' . $f8uqh . '
', $Z8_ay); goto cVjSC; YIp_U: $Z8_ay = preg_replace('/DB_USERNAME=(.*?)\\n/', 'DB_USERNAME=' . $anHXn . '
', $Z8_ay); goto n_JHe; ObNH0: $gQvAP = $fAvwi->getTrimString('password'); goto RvIJ7; aMuIu: $kAZwD = $fAvwi->getTrimString('db_password', ''); goto xmyQl; MVaAC: $P5lyv = $fAvwi->getBoolean('installLicense'); goto Vp6z4; hYznq: $ERQd1 = $fAvwi->getTrimString('db_database'); goto k4s6P; Vp6z4: $wP3Rt = $fAvwi->getJson('INSTALL_CONFIG'); goto JNHnm; xl09D: if (empty($f8uqh)) { return Response::jsonError('数据库端口不能为空'); } goto XMAeB; vKLRh: $Qbal_ = $fAvwi->getTrimString('db_host'); goto XIO_t; VlX7F: $Z8_ay = preg_replace('/DB_PREFIX=(.*?)\\n/', 'DB_PREFIX=' . $h18Og . '
', $Z8_ay); goto h7eOW; m83D2: if (empty($gQvAP)) { return Response::jsonError('管理用户密码不能为空'); } goto ZvUuQ; oM0KK: if (!empty($wP3Rt['envs'])) { foreach ($wP3Rt['envs'] as $Rzhop) { $Z8_ay = preg_replace('/' . $Rzhop['name'] . '=(.*?)\\n/', $Rzhop['name'] . '=' . $fAvwi->getTrimString($Rzhop['name']) . '
', $Z8_ay); } } goto hJmeN; Ydqsc: if (empty($anHXn)) { return Response::jsonError('数据库用户名不能为空'); } goto wp8Uv; Z_rlV: $Z8_ay = file_get_contents(base_path('env.example')); goto bw4sH; hJmeN: file_put_contents(base_path('.env'), $Z8_ay); goto sDC4b; ZvUuQ: if (file_exists(base_path('license_url.txt')) && !$P5lyv) { return Response::jsonError('请先同意《软件安装许可协议》'); } goto IucnC; UBDTF: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto ZgJ9j; bw4sH: $Z8_ay = preg_replace('/APP_DEBUG=(.*?)\\n/', 'APP_DEBUG=false
', $Z8_ay); goto sYvYM; sDC4b: return Response::jsonSuccess(); goto Sp8i3; hqI6O: $tzCf9 = $fAvwi->getTrimString('username'); goto ObNH0; k4s6P: $anHXn = $fAvwi->getTrimString('db_username'); goto aMuIu; RvIJ7: $KAXT4 = $fAvwi->getBoolean('installDemo'); goto MVaAC; n_JHe: $Z8_ay = preg_replace('/DB_PASSWORD=(.*?)\\n/', 'DB_PASSWORD=' . $kAZwD . '
', $Z8_ay); goto VlX7F; h7eOW: $Z8_ay = preg_replace('/APP_KEY=(.*?)\\n/', 'APP_KEY=' . RandomUtil::string(32) . '
', $Z8_ay); goto VXFog; XIO_t: $f8uqh = $fAvwi->getTrimString('db_port'); goto hYznq; XMAeB: if (empty($ERQd1)) { return Response::jsonError('数据库数据库不能为空'); } goto Ydqsc; xmyQl: $h18Og = $fAvwi->getTrimString('db_prefix', ''); goto hqI6O; VXFog: $Z8_ay = preg_replace('/ENCRYPT_KEY=(.*?)\\n/', 'ENCRYPT_KEY=' . RandomUtil::string(32) . '
', $Z8_ay); goto oM0KK; sYvYM: $Z8_ay = preg_replace('/DB_HOST=(.*?)\\n/', 'DB_HOST=' . $Qbal_ . '
', $Z8_ay); goto JNvJx; JNHnm: if (empty($Qbal_)) { return Response::jsonError('数据库主机名不能为空'); } goto xl09D; l3cfk: $fAvwi = InputPackage::buildFromInput(); goto vKLRh; ZgJ9j: if (file_exists($sqB1u = base_path('.env'))) { $fKViA = file_get_contents($sqB1u); if (str_contains($fKViA, 'DB_HOST')) { return Response::jsonError('请先清空.env文件'); } } goto l3cfk; wp8Uv: if (empty($tzCf9)) { return Response::jsonError('管理用户不能为空'); } goto m83D2; IucnC: try { new PDO("mysql:host={$Qbal_};port={$f8uqh};dbname={$ERQd1}", $anHXn, $kAZwD); } catch (\Exception $cknMI) { goto eX2pl; nWWsu: if (str_contains($wk1ic, 'Server sent charset unknown to the client')) { return Response::generateError('数据库编码不支持：' . $wk1ic); } else { if (str_contains($wk1ic, 'Access denied for user')) { return Response::generateError('用户密码不匹配：' . $wk1ic); } } goto DuuF9; eX2pl: $wk1ic = $cknMI->getMessage(); goto nWWsu; rhzAN: return Response::jsonError('连接数据信息 ' . $Qbal_ . ':' . $f8uqh . '.' . $ERQd1 . ' 失败!'); goto cONmV; DuuF9: Log::error('InstallError -> ' . $cknMI->getMessage() . ' -> ' . $cknMI->getTraceAsString()); goto rhzAN; cONmV: } goto Z_rlV; Sp8i3: } public function execute() { goto rIi5r; obsph: $SvOVI = 0; goto iHgkC; rIi5r: if (file_exists(storage_path('install.lock'))) { return Response::jsonError('系统不能重复安装（请删除install.lock文件后重试）'); } goto rkvdH; z9hFR: return Response::json(0, '安装成功，点击即将跳转到管理后台', null, '/admin'); goto ccBrb; pumWp: if (empty($tzCf9)) { return Response::jsonError('管理用户名为空'); } goto FRhbj; GHUHA: foreach (ModuleManager::listAllInstalledModulesInRequiredOrder() as $X3Epx) { goto hP9Dp; IKy0g: try { $oHb9_ = ModuleManager::install($X3Epx); } catch (\Exception $cknMI) { return $this->handleException($cknMI); } goto XN1_W; hP9Dp: if (!ModuleManager::isExists($X3Epx)) { continue; } goto IKy0g; XN1_W: if (Response::isError($oHb9_)) { return Response::generateError($oHb9_['msg']); } goto vJ3Z_; vJ3Z_: } goto Xyac8; KU9H4: $iiPCW = ModelUtil::count('admin_user'); goto m6rnu; E3Nsg: $gQvAP = $fAvwi->getTrimString('password'); goto K1vo7; Xyac8: if ($KAXT4 && file_exists($obXaA = public_path('data_demo/data.php'))) { goto B6rA5; KdL_K: if (!empty($q62oK['inserts'])) { foreach ($q62oK['inserts'] as $K4MEV => $Ge6HJ) { ModelUtil::insertAll($K4MEV, $Ge6HJ); } } goto zQzte; B6rA5: $q62oK = (include $obXaA); goto KdL_K; zQzte: if (!empty($q62oK['updates'])) { foreach ($q62oK['updates'] as $HuYBt) { DB::table($HuYBt['table'])->where($HuYBt['where'])->update($HuYBt['update']); } } goto tEg5H; tEg5H: } goto AHbuB; rkvdH: $fAvwi = InputPackage::buildFromInput(); goto B8jBK; wu4NL: set_time_limit(0); goto obsph; K1vo7: $KAXT4 = $fAvwi->getBoolean('installDemo'); goto pumWp; m6rnu: if ($iiPCW === 0) { Admin::add($tzCf9, $gQvAP); } goto GHUHA; cuNBg: if (0 != $SvOVI) { return Response::jsonError("安装错误 exitCode({$SvOVI})"); } goto KU9H4; B8jBK: $tzCf9 = $fAvwi->getTrimString('username'); goto E3Nsg; FRhbj: if (empty($gQvAP)) { return Response::jsonError('管理用户密码为空'); } goto wu4NL; AHbuB: file_put_contents(storage_path('install.lock'), 'lock'); goto z9hFR; iHgkC: try { $SvOVI = Artisan::call('migrate'); } catch (\Exception $cknMI) { return $this->handleException($cknMI); } goto cuNBg; ccBrb: } private function handleException(\Exception $cknMI) { goto JU_SP; Z2qS5: throw $cknMI; goto VtFjJ; JU_SP: $wk1ic = $cknMI->getMessage(); goto LgtyT; GgrjT: if (preg_match('/Table \'(.*?)\' already exists/', $wk1ic, $hfN7a)) { return Response::jsonError('数据表 ' . $hfN7a[1] . ' 已经存在（可能您使用了一个非空的数据库，请删除表或更新数据库）'); } goto Dbumj; Dbumj: if (preg_match('/Duplicate column name \'(.*?)\'/', $wk1ic, $hfN7a)) { goto Gecrb; GJhKk: return Response::jsonError('数据表字段 ' . $AlE6h . ' 已经存在（请查看' . $obXaA . '迁移文件配置）'); goto RWawt; Gecrb: $AlE6h = $hfN7a[1]; goto IIHqg; IIHqg: $obXaA = null; goto Au8JC; Au8JC: if (preg_match('/(module\\/.*?\\/Migrate\\/.*?\\.php)/', $QmDWH, $hfN7a)) { $obXaA = $hfN7a[1]; } goto GJhKk; RWawt: } goto Z2qS5; LgtyT: $QmDWH = $cknMI->getTraceAsString(); goto GgrjT; VtFjJ: } }