web.php 22 KB

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