web.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. use App\Facades\ProApiCacheFacade;
  3. use App\Helpers\File;
  4. use App\Helpers\Utils;
  5. use App\Exports\Type1Export;
  6. use App\Http\Controllers\BarcodeController;
  7. use App\Http\Controllers\CaptchaServiceController;
  8. use App\Http\Controllers\DBUpdateController;
  9. use App\Http\Controllers\EnvSettingController;
  10. use App\Imports\Type1Import;
  11. use App\Services\CallApiService;
  12. use Illuminate\Http\Request;
  13. use App\Models\Parameter\FormA;
  14. use App\Models\Parameter\FormB;
  15. use App\Models\Parameter\Modal;
  16. use App\Models\Parameter\Manual;
  17. use Barryvdh\DomPDF\Facade as PDF;
  18. use App\Models\Parameter\ListMedia1;
  19. use Illuminate\Support\Str;
  20. use Maatwebsite\Excel\Facades\Excel;
  21. use Illuminate\Support\Facades\Route;
  22. use Intervention\Image\Facades\Image;
  23. use Illuminate\Support\Facades\Artisan;
  24. use Illuminate\Support\Facades\Storage;
  25. use App\Http\Controllers\Api\ApiController;
  26. use App\Http\Controllers\DashboardController;
  27. use App\Http\Controllers\Auth\LoginController;
  28. use App\Http\Controllers\Auth\SocialController;
  29. use App\Http\Controllers\CountryCodeController;
  30. /*
  31. |--------------------------------------------------------------------------
  32. | Web Routes
  33. |--------------------------------------------------------------------------
  34. |
  35. | Here is where you can register web routes for your application. These
  36. | routes are loaded by the RouteServiceProvider within a group which
  37. | contains the "web" middleware group. Now create something great!
  38. |
  39. */
  40. Route::middleware(['check.logout'])->group(function () {
  41. Route::get('/checkphp', function () {
  42. return phpinfo();
  43. });
  44. Route::get(env('USER_LOGIN_ROUTE', '/user-login') ?: '/user-login', [LoginController::class, 'index'])->middleware('check.gate.token')->name('user-login');
  45. Route::post('/login', [LoginController::class, 'login'])->middleware('check.gate.token')->name('login.post');
  46. Route::get('/db-update', [DBUpdateController::class, 'index'])->name('db-update.index');
  47. Route::post('/db-update', [DBUpdateController::class, 'store'])->name('db-update.store');
  48. });
  49. Route::middleware(['check.login'])->group(function () {
  50. Route::get('/dabory/erp', [DashboardController::class, 'index'])->name('dashboard');
  51. Route::get('/user-logout', [LoginController::class, 'logout'])->name('user-logout');
  52. Route::post('/cert/mail', [\App\Http\Controllers\CertController::class, 'mail']);
  53. Route::post('/cert/mobile', [\App\Http\Controllers\CertController::class, 'mobile']);
  54. Route::post('/superuser-email-change', function () {
  55. $mailCert = session()->get('mailCert');
  56. $smsCertCurrent = session()->get('smsCert.current');
  57. $smsCertNew = session()->get('smsCert.new');
  58. if (request('Type') === 0 && request('EmailVerifyNumber', '??????') != $mailCert['number']) {
  59. return response()->json(['error' => true, 'message' => '메일 인증번호 오류']);
  60. }
  61. if (request('Type') === 1 && request('MobileVerifyNumber', '??????') != $smsCertCurrent['number']) {
  62. return response()->json(['error' => true, 'message' => '현재 모바일폰에서 확인한 인증번호 오류']);
  63. }
  64. if (request('Type') === 2 && request('NewMobileVerifyNumber', '??????') != $smsCertNew['number']) {
  65. return response()->json(['error' => true, 'message' => '변경 관리자 모바일폰에서 확인한 인증번호 오류']);
  66. }
  67. return response()->json(['error' => false, 'message' => 'Success']);
  68. });
  69. Route::get('/user-query-turbo/{table}', function ($table) {
  70. $response = app(CallApiService::class)->callApi([
  71. 'url' => 'query-turbo',
  72. 'data' => [
  73. 'TableName' => $table,
  74. 'QueryVars' => [
  75. 'MyFilter' => '',
  76. 'QueryName' => '',
  77. 'FilterName' => '',
  78. 'FilterValue' => '',
  79. 'SimpleFilter' => 'mx.id between 1 and 10000',
  80. 'SubSimpleFilter' => '',
  81. 'IsntPagination' => true,
  82. 'TestMode' => '',
  83. ]
  84. ],
  85. ]);
  86. if (app(CallApiService::class)->verifyApiError($response)) {
  87. return response([
  88. 'body' => 'Api Server Error',
  89. 'apiStatus' => 500
  90. ], 200);
  91. }
  92. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  93. return redirect()->back();
  94. })->name('user.query.turbo');
  95. // Route::post('/ajax/get-data', [ApiController::class, 'getData']);
  96. Route::get('/country-code', [CountryCodeController::class, 'store']);
  97. Route::get('/change-sort-menu/{sort_menu_id}', function ($sortMenuId) {
  98. $sortMenuPage = Utils::getSortMenu()['Page'] ?? [];
  99. $filterSortMenu = collect($sortMenuPage)->filter(function ($sortMenu) use($sortMenuId) {
  100. return $sortMenu['Id'] === (int)$sortMenuId;
  101. })->first();
  102. session()->put('user.SortMenu', $filterSortMenu);
  103. return redirect()->to($filterSortMenu['C4']);
  104. })->name('change-sort-menu');
  105. });
  106. // admin, pro 공용
  107. // Route::get('/dabory/ssologin/callback', [DaborySSOController::class, 'login'])->middleware('check.gate.token')->name('dabory.ssologin.login');
  108. // Route::get('/dabory/ssologin', [DaborySSOController::class, 'redirectToProvider'])->middleware('check.gate.token')->name('dabory.redirectToProvider');
  109. Route::get('/social/{provider}/callback', [SocialController::class, 'login'])->middleware('check.gate.token')->name('social.login');
  110. Route::post('/social/{provider}/callback', [SocialController::class, 'login'])->middleware('check.gate.token');
  111. Route::get('/social/{provider}', [SocialController::class, 'redirectToProvider'])->middleware('check.gate.token')->name('social.redirectToProvider');
  112. Route::post('/ajax/get-data', [ApiController::class, 'getData']);
  113. Route::post('/find-gate-token', function () {
  114. if (! request()->has('app_name')) {
  115. return response('error', 500);
  116. }
  117. $appName = request('app_name');
  118. if (session()->has("GateToken.$appName")) {
  119. return response(session()->get("GateToken.$appName"), 200);
  120. }
  121. return response(session()->get("GateToken.$appName"), 200);
  122. });
  123. Route::post('/md5', function () {
  124. return md5(request('str'));
  125. });
  126. Route::get('/generate-keys', function () {
  127. $keyPair = sodium_crypto_box_keypair();
  128. $publicKey = sodium_crypto_box_publickey($keyPair);
  129. return array(base64_encode($publicKey),base64_encode($keyPair));
  130. });
  131. Route::get('/extract-keys', function () {
  132. $keyPair = base64_decode(request('key_pair'));
  133. $publicKey = sodium_crypto_box_publickey($keyPair);
  134. return base64_encode($publicKey);
  135. });
  136. Route::post('/crypto/sodium', function () {
  137. $data = json_decode(request()->getContent(), true);
  138. $decrypted = $data['decrypted'];
  139. if ($data['json_encode']) {
  140. $decrypted = json_encode( $decrypted );
  141. }
  142. return base64_encode(sodium_crypto_box_seal($decrypted,
  143. base64_decode( $data['public_key'] )));
  144. });
  145. Route::get('/user-clear-cache', function () {
  146. Artisan::call('event:clear');
  147. Artisan::call('cache:clear');
  148. Artisan::call('optimize:clear');
  149. Artisan::call('route:clear');
  150. Artisan::call('view:clear');
  151. // Storage::deleteDirectory('dabory-footage/users/' . session('user')['UserId']);
  152. Storage::deleteDirectory('dabory-footage/users');
  153. Storage::deleteDirectory('dabory-footage/pro');
  154. Storage::deleteDirectory('dabory-footage/basic/slip-form-init');
  155. Storage::deleteDirectory('dabory-footage/members');
  156. ProApiCacheFacade::deleteCachedDirectory();
  157. app(\App\Services\CacheService::class)->putMainMenu();
  158. app(\App\Services\CacheService::class)->putEtcBrand();
  159. app(\App\Services\CacheService::class)->putSetup();
  160. return redirect()->back();
  161. })->name('user.clear.cache');
  162. Route::post('/clear-menu-cache', function () {
  163. Storage::deleteDirectory('dabory-footage/users/' . session('user')['UserId'] . '/user-menu');
  164. });
  165. Route::get('/506', function () {
  166. return view('errors.506');
  167. })->name('506');
  168. // js에서 에러 예외처리 할 때 사용
  169. Route::get('/505', function () {
  170. session()->flush();
  171. return view('errors.505');
  172. })->name('505');
  173. Route::get('/503', function () {
  174. session()->flush();
  175. return view('errors.503');
  176. })->name('503');
  177. Route::get('/600', function () {
  178. session()->flush();
  179. return view('errors.600');
  180. })->name('600');
  181. Route::get('/pro-route-std', function () {
  182. return view('pro-route-std');
  183. })->name('pro-route-std');
  184. Route::get('/pro-route-custom', function () {
  185. return view('pro-route-custom');
  186. })->name('pro-route-custom');
  187. Route::get('/captcha-validation', [CaptchaServiceController::class, 'capthcaFormValidate']);
  188. Route::get('/reload-captcha', [CaptchaServiceController::class, 'reloadCaptcha']);
  189. Route::get('/test', function () {
  190. return view('eyetest-more');
  191. });
  192. Route::get('/eyetest-more-ui', function () {
  193. return view('front.dabory.erp.test-ui.eyetest-more-ui');
  194. });
  195. // demo gettext
  196. Route::get('/demo-gettext', function () {
  197. // return _e('admin');
  198. // return _e('file moved');
  199. return _e('%s file moved to %s', 'aaa.php', 'bbb.php');
  200. });
  201. // test-tailwind-css
  202. Route::get('/tailwind-css-test', function () {
  203. return view('main.tailwind-css-test');
  204. });
  205. // 테스트떄문에 에러토큰으로 변경 (GateToken Not Found Test)
  206. Route::post('/token-change', function () {
  207. session()->put('GateToken.erp', 'duoICbFSNRRoxXoIaC0G');
  208. return response('');
  209. });
  210. Route::get('/test/image-ui', function () {
  211. return view('test.image-ui');
  212. });
  213. Route::get('/geolocation', function () {
  214. return view('geolocation');
  215. });
  216. Route::get('/barcode/{listToken}', [BarcodeController::class, 'index'])->name('barcode');
  217. Route::middleware('check.gate.token')->group(function () {
  218. Route::post('/blades', function () {
  219. if (request('data')) {
  220. $key = request('key') ?? 'moealSetFile';
  221. if (empty(request('class_name'))) {
  222. return view(request('path_to_blade'), [$key => request('data')]);
  223. } else {
  224. return view(request('path_to_blade'), array_merge(request('class_name'), [$key => request('data')]));
  225. }
  226. }
  227. return view(request('path_to_blade'));
  228. });
  229. Route::post('/pro-skin-directories', function () {
  230. $directories = App\Helpers\File::getSkinDirectories();
  231. return response($directories, 200);
  232. });
  233. Route::post('/breadcrumb', function () {
  234. $breadcrumb = breadcrumb(request('igroup_code'));
  235. return response($breadcrumb, 200);
  236. });
  237. Route::post('/set-general-info', [EnvSettingController::class, 'setGeneralInfo']);
  238. Route::post('/set-aws-s3', [EnvSettingController::class, 'setAwsS3']);
  239. Route::post('/set-aligo-text-send', [EnvSettingController::class, 'setAligoTextSend']);
  240. Route::post('/excel-import', function (Request $request) {
  241. if (!$request->hasFile('file')) {
  242. return response('error', 500);
  243. }
  244. $data = Excel::toArray(new Type1Import, $request->file('file'));
  245. return response($data, 200);
  246. });
  247. Route::post('/sub-image-upload', function (Request $request) {
  248. $formExt = pathinfo(request('form_file_path'), PATHINFO_EXTENSION);
  249. $toExt = pathinfo(request('to_file_path'), PATHINFO_EXTENSION);
  250. if ($formExt !== $toExt) {
  251. Storage::disk(getDisk())->delete(request('form_file_path'));
  252. return response('보정 파일과 이전 파일의 확장자가 다릅니다.', 202);
  253. }
  254. Storage::disk(getDisk())->delete(request('to_file_path'));
  255. Storage::disk(getDisk())->move(request('form_file_path'), request('to_file_path'));
  256. return response('success', 200);
  257. });
  258. Route::post('/sub-image-correction', function (Request $request) {
  259. if (!$request->hasFile('file')) {
  260. return response('error', 500);
  261. }
  262. $path = '/uploads';
  263. $response = Storage::disk(getDisk())->put($path, $request->file('file'), ['visibility' => 'public']);
  264. return response($response, 200);
  265. });
  266. Route::post('/file-exists', function () {
  267. if (Storage::disk(getDisk())->exists(request('file_path'))) {
  268. return response(true, 200);
  269. }
  270. return response(false, 200);
  271. });
  272. Route::post('/seo-meta-file-list', function (Request $request) {
  273. $publicPath = public_path();
  274. $files = \File::files($publicPath);
  275. // Filter root files (not in subdirectories)
  276. $rootFiles = array_filter($files, function ($file) use ($publicPath) {
  277. return $file->getPath() == $publicPath;
  278. });
  279. // Extract only the names of the root files
  280. $rootFileNames = array_map(function ($file) {
  281. return $file->getFilename();
  282. }, $rootFiles);
  283. return $rootFileNames;
  284. });
  285. Route::post('/seo-meta-file-upload', function (Request $request) {
  286. if (!$request->hasFile('file')) {
  287. return response('error', 500);
  288. }
  289. $file = $request->file('file');
  290. $file->storeAs('/', request('fileName'), ['disk' => 'erp']);
  291. return response($file, 201);
  292. });
  293. Route::post('/upload-batch', function (Request $request) {
  294. $mediaList = request('media_list');
  295. foreach ($mediaList as $media) {
  296. $mediaPath = substr($media['path'], '1') . $media['name'];
  297. try {
  298. $file = File::pathToUploadedFile(Storage::disk(getDisk())->path($mediaPath));
  299. } catch (Exception $e) {
  300. return response([
  301. 'body' => $media['path'] . $media['name'] . ' 파일이 존재하지 않아서 Upload Batch 실행 취소했습니다',
  302. 'apiStatus' => 501
  303. ], 200);
  304. }
  305. $image = Image::make($file);
  306. $mediaAct = app(CallApiService::class)->callApi([
  307. 'url' => 'media-act',
  308. 'data' => [
  309. 'Page' => [
  310. [
  311. 'Id' => $media['media_id'],
  312. 'FileUrl' => "/{$mediaPath}",
  313. 'FileSize' => (int)round($image->filesize() / 1024),
  314. 'MediaWidth' => $image->width(),
  315. 'MediaHeight' => $image->height(),
  316. ]
  317. ],
  318. ],
  319. ]);
  320. if (app(CallApiService::class)->verifyApiError($mediaAct)) {
  321. return response([
  322. 'body' => 'Api Server Error',
  323. 'apiStatus' => 500
  324. ], 200);
  325. }
  326. $bdPage = app(App\Services\MediaLibraryService::class)
  327. ->makeImageBd($file, $media, request('is_crop_image'));
  328. $mediaBdPage = collect($bdPage)->map(function ($item) use ($media) {
  329. return [
  330. 'Id' => 0,
  331. 'MediaId' => $media['media_id'],
  332. 'ImageType' => $item['ImageType'],
  333. 'BdFileUrl' => $item['BdFileUrl'],
  334. 'BdFileSize' => (int)$item['BdFileSize'],
  335. 'BdWidth' => $item['BdWidth'],
  336. 'BdHeight' => $item['BdHeight'],
  337. ];
  338. })->toArray();
  339. if (count($mediaBdPage) > 0) {
  340. $mediaBdAct = app(CallApiService::class)->callApi([
  341. 'url' => 'media-bd-act',
  342. 'data' => [
  343. 'Page' => $mediaBdPage
  344. ],
  345. ]);
  346. if (app(CallApiService::class)->verifyApiError($mediaBdAct)) {
  347. return response([
  348. 'body' => 'Api Server Error',
  349. 'apiStatus' => 500
  350. ], 200);
  351. }
  352. }
  353. }
  354. return response('success', 201);
  355. });
  356. Route::post('/post-attached-files', function (Request $request) {
  357. $mediaLibraryService = app(App\Services\MediaLibraryService::class);
  358. $mediaLibraryService->setGateToken(session('GateToken')['main']);
  359. $setup = $mediaLibraryService->getSetup('post');
  360. $path = $mediaLibraryService->getCurrSetupFilePath($setup);
  361. $attachedFiles = '';
  362. for ($i = 0; $i < $request['fileCount']; $i++) {
  363. $file = $request->file('file' . $i);
  364. $file->storeAs($path, $file->getClientOriginalName(), ['disk' => getDisk()]);
  365. $attachedFiles .= $path . $file->getClientOriginalName() . '|';
  366. }
  367. $attachedFiles = rtrim($attachedFiles, '|');
  368. return response()->json($attachedFiles);
  369. });
  370. Route::post('/file-upload', function (Request $request) {
  371. if (!$request->hasFile('file')) {
  372. return response('error', 500);
  373. }
  374. $media = json_decode(request('media'), true);
  375. $file = $request->file('file');
  376. $file->storeAs($media['path'], $media['name'], ['disk' => getDisk()]);
  377. $bdPage = [];
  378. if ($media['type'] == 'image') {
  379. $fileExtension = Str::lower($file->extension());
  380. if ($fileExtension === 'gif' || $fileExtension === 'webp' || $fileExtension === 'svg') {
  381. $bdPage = app(App\Services\MediaLibraryService::class)->makeGifBd($file, $media);
  382. } else {
  383. $bdPage = app(App\Services\MediaLibraryService::class)->makeImageBd($file, $media);
  384. }
  385. }
  386. return response($bdPage, 201);
  387. });
  388. Route::post('/file-delete', function () {
  389. $file_path_list = json_decode(request('file_path_list'), true);
  390. Storage::disk(getDisk())->delete($file_path_list);
  391. return response('success', 200);
  392. });
  393. Route::post('/cache-api', function () {
  394. $cacheData = Utils::getParamCache(request('menu_code'), request('api_name'));
  395. if (request('query_name')) {
  396. $cacheData = Utils::getParamCache(request('menu_code'), request('api_name'), request('query_name'));
  397. }
  398. return $cacheData;
  399. });
  400. Route::post('/download/report', function () {
  401. $report = json_decode(request('report'), true);
  402. switch ($report['type']) {
  403. case 'pdf':
  404. $customPaper = array(0, 0, $report['size'], $report['size']);
  405. $table['head'] = $report['head'];
  406. $table['body'] = $report['body'];
  407. $pdf = PDF::loadView('pdf.table', compact('table'))->setPaper($customPaper, 'landscape');
  408. return $pdf->download("{$report['title']}.pdf");
  409. case 'excel':
  410. $report['body'] = collect($report['body'])->prepend($report['head']);
  411. return Excel::download(new Type1Export($report['body']), "{$report['title']}.xlsx");
  412. }
  413. });
  414. Route::post('/paras', function () {
  415. $themeDir = request('theme_dir', 'empty');
  416. $paraType = request('para_type');
  417. $pathToPara = request('path_to_para');
  418. $bpa = request('bpa', '');
  419. try {
  420. if ($paraType == 'modal') {
  421. $para = (new Modal($pathToPara, $themeDir))->getData();
  422. } else if ($paraType == 'formA') {
  423. $para = (new FormA($bpa, $pathToPara, $themeDir))->getData('data');
  424. } else if ($paraType == 'formB') {
  425. $para = (new FormB($bpa, $pathToPara, $themeDir))->getData('data');
  426. } else if ($paraType == 'manual') {
  427. $para = (new Manual($pathToPara, $bpa))->getData();
  428. } else if ($paraType == 'listMedia1') {
  429. $para = (new ListMedia1($bpa, $pathToPara))->getData('data');
  430. }
  431. } catch (Exception $e) {
  432. return response([
  433. 'body' => $e->getMessage(),
  434. 'apiStatus' => 404
  435. ], 200);
  436. }
  437. return $para;
  438. });
  439. });