web.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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/members');
  155. ProApiCacheFacade::deleteCachedDirectory();
  156. app(\App\Services\CacheService::class)->putMainMenu();
  157. app(\App\Services\CacheService::class)->putEtcBrand();
  158. app(\App\Services\CacheService::class)->putSetup();
  159. return redirect()->back();
  160. })->name('user.clear.cache');
  161. Route::post('/clear-menu-cache', function () {
  162. Storage::deleteDirectory('dabory-footage/users/' . session('user')['UserId'] . '/user-menu');
  163. });
  164. Route::get('/506', function () {
  165. return view('errors.506');
  166. })->name('506');
  167. // js에서 에러 예외처리 할 때 사용
  168. Route::get('/505', function () {
  169. session()->flush();
  170. return view('errors.505');
  171. })->name('505');
  172. Route::get('/503', function () {
  173. session()->flush();
  174. return view('errors.503');
  175. })->name('503');
  176. Route::get('/600', function () {
  177. session()->flush();
  178. return view('errors.600');
  179. })->name('600');
  180. Route::get('/pro-route-std', function () {
  181. return view('pro-route-std');
  182. })->name('pro-route-std');
  183. Route::get('/pro-route-custom', function () {
  184. return view('pro-route-custom');
  185. })->name('pro-route-custom');
  186. Route::get('/captcha-validation', [CaptchaServiceController::class, 'capthcaFormValidate']);
  187. Route::get('/reload-captcha', [CaptchaServiceController::class, 'reloadCaptcha']);
  188. Route::get('/test', function () {
  189. return view('eyetest-more');
  190. });
  191. Route::get('/eyetest-more-ui', function () {
  192. return view('front.dabory.erp.test-ui.eyetest-more-ui');
  193. });
  194. // demo gettext
  195. Route::get('/demo-gettext', function () {
  196. // return _e('admin');
  197. // return _e('file moved');
  198. return _e('%s file moved to %s', 'aaa.php', 'bbb.php');
  199. });
  200. // test-tailwind-css
  201. Route::get('/tailwind-css-test', function () {
  202. return view('main.tailwind-css-test');
  203. });
  204. // 테스트떄문에 에러토큰으로 변경 (GateToken Not Found Test)
  205. Route::post('/token-change', function () {
  206. session()->put('GateToken.erp', 'duoICbFSNRRoxXoIaC0G');
  207. return response('');
  208. });
  209. Route::get('/test/image-ui', function () {
  210. return view('test.image-ui');
  211. });
  212. Route::get('/geolocation', function () {
  213. return view('geolocation');
  214. });
  215. Route::get('/barcode/{listToken}', [BarcodeController::class, 'index'])->name('barcode');
  216. Route::middleware('check.gate.token')->group(function () {
  217. Route::post('/blades', function () {
  218. if (request('data')) {
  219. $key = request('key') ?? 'moealSetFile';
  220. if (empty(request('class_name'))) {
  221. return view(request('path_to_blade'), [$key => request('data')]);
  222. } else {
  223. return view(request('path_to_blade'), array_merge(request('class_name'), [$key => request('data')]));
  224. }
  225. }
  226. return view(request('path_to_blade'));
  227. });
  228. Route::post('/pro-skin-directories', function () {
  229. $directories = App\Helpers\File::getSkinDirectories();
  230. return response($directories, 200);
  231. });
  232. Route::post('/breadcrumb', function () {
  233. $breadcrumb = breadcrumb(request('igroup_code'));
  234. return response($breadcrumb, 200);
  235. });
  236. Route::post('/set-general-info', [EnvSettingController::class, 'setGeneralInfo']);
  237. Route::post('/set-aws-s3', [EnvSettingController::class, 'setAwsS3']);
  238. Route::post('/set-aligo-text-send', [EnvSettingController::class, 'setAligoTextSend']);
  239. Route::post('/excel-import', function (Request $request) {
  240. if (!$request->hasFile('file')) {
  241. return response('error', 500);
  242. }
  243. $data = Excel::toArray(new Type1Import, $request->file('file'));
  244. return response($data, 200);
  245. });
  246. Route::post('/sub-image-upload', function (Request $request) {
  247. $formExt = pathinfo(request('form_file_path'), PATHINFO_EXTENSION);
  248. $toExt = pathinfo(request('to_file_path'), PATHINFO_EXTENSION);
  249. if ($formExt !== $toExt) {
  250. Storage::disk(getDisk())->delete(request('form_file_path'));
  251. return response('보정 파일과 이전 파일의 확장자가 다릅니다.', 202);
  252. }
  253. Storage::disk(getDisk())->delete(request('to_file_path'));
  254. Storage::disk(getDisk())->move(request('form_file_path'), request('to_file_path'));
  255. return response('success', 200);
  256. });
  257. Route::post('/sub-image-correction', function (Request $request) {
  258. if (!$request->hasFile('file')) {
  259. return response('error', 500);
  260. }
  261. $path = '/uploads';
  262. $response = Storage::disk(getDisk())->put($path, $request->file('file'), ['visibility' => 'public']);
  263. return response($response, 200);
  264. });
  265. Route::post('/file-exists', function () {
  266. if (Storage::disk(getDisk())->exists(request('file_path'))) {
  267. return response(true, 200);
  268. }
  269. return response(false, 200);
  270. });
  271. Route::post('/seo-meta-file-list', function (Request $request) {
  272. $publicPath = public_path();
  273. $files = \File::files($publicPath);
  274. // Filter root files (not in subdirectories)
  275. $rootFiles = array_filter($files, function ($file) use ($publicPath) {
  276. return $file->getPath() == $publicPath;
  277. });
  278. // Extract only the names of the root files
  279. $rootFileNames = array_map(function ($file) {
  280. return $file->getFilename();
  281. }, $rootFiles);
  282. return $rootFileNames;
  283. });
  284. Route::post('/seo-meta-file-upload', function (Request $request) {
  285. if (!$request->hasFile('file')) {
  286. return response('error', 500);
  287. }
  288. $file = $request->file('file');
  289. $file->storeAs('/', request('fileName'), ['disk' => 'erp']);
  290. return response($file, 201);
  291. });
  292. Route::post('/upload-batch', function (Request $request) {
  293. $mediaList = request('media_list');
  294. foreach ($mediaList as $media) {
  295. $mediaPath = substr($media['path'], '1') . $media['name'];
  296. try {
  297. $file = File::pathToUploadedFile(Storage::disk(getDisk())->path($mediaPath));
  298. } catch (Exception $e) {
  299. return response([
  300. 'body' => $media['path'] . $media['name'] . ' 파일이 존재하지 않아서 Upload Batch 실행 취소했습니다',
  301. 'apiStatus' => 501
  302. ], 200);
  303. }
  304. $image = Image::make($file);
  305. $mediaAct = app(CallApiService::class)->callApi([
  306. 'url' => 'media-act',
  307. 'data' => [
  308. 'Page' => [
  309. [
  310. 'Id' => $media['media_id'],
  311. 'FileUrl' => "/{$mediaPath}",
  312. 'FileSize' => (int)round($image->filesize() / 1024),
  313. 'MediaWidth' => $image->width(),
  314. 'MediaHeight' => $image->height(),
  315. ]
  316. ],
  317. ],
  318. ]);
  319. if (app(CallApiService::class)->verifyApiError($mediaAct)) {
  320. return response([
  321. 'body' => 'Api Server Error',
  322. 'apiStatus' => 500
  323. ], 200);
  324. }
  325. $bdPage = app(App\Services\MediaLibraryService::class)
  326. ->makeImageBd($file, $media, request('is_crop_image'));
  327. $mediaBdPage = collect($bdPage)->map(function ($item) use ($media) {
  328. return [
  329. 'Id' => 0,
  330. 'MediaId' => $media['media_id'],
  331. 'ImageType' => $item['ImageType'],
  332. 'BdFileUrl' => $item['BdFileUrl'],
  333. 'BdFileSize' => (int)$item['BdFileSize'],
  334. 'BdWidth' => $item['BdWidth'],
  335. 'BdHeight' => $item['BdHeight'],
  336. ];
  337. })->toArray();
  338. if (count($mediaBdPage) > 0) {
  339. $mediaBdAct = app(CallApiService::class)->callApi([
  340. 'url' => 'media-bd-act',
  341. 'data' => [
  342. 'Page' => $mediaBdPage
  343. ],
  344. ]);
  345. if (app(CallApiService::class)->verifyApiError($mediaBdAct)) {
  346. return response([
  347. 'body' => 'Api Server Error',
  348. 'apiStatus' => 500
  349. ], 200);
  350. }
  351. }
  352. }
  353. return response('success', 201);
  354. });
  355. Route::post('/post-attached-files', function (Request $request) {
  356. $mediaLibraryService = app(App\Services\MediaLibraryService::class);
  357. $mediaLibraryService->setGateToken(session('GateToken')['main']);
  358. $setup = $mediaLibraryService->getSetup('post');
  359. $path = $mediaLibraryService->getCurrSetupFilePath($setup);
  360. $attachedFiles = '';
  361. for ($i = 0; $i < $request['fileCount']; $i++) {
  362. $file = $request->file('file' . $i);
  363. $file->storeAs($path, $file->getClientOriginalName(), ['disk' => getDisk()]);
  364. $attachedFiles .= $path . $file->getClientOriginalName() . '|';
  365. }
  366. $attachedFiles = rtrim($attachedFiles, '|');
  367. return response()->json($attachedFiles);
  368. });
  369. Route::post('/file-upload', function (Request $request) {
  370. if (!$request->hasFile('file')) {
  371. return response('error', 500);
  372. }
  373. $media = json_decode(request('media'), true);
  374. $file = $request->file('file');
  375. $file->storeAs($media['path'], $media['name'], ['disk' => getDisk()]);
  376. $bdPage = [];
  377. if ($media['type'] == 'image') {
  378. $fileExtension = Str::lower($file->extension());
  379. if ($fileExtension === 'gif' || $fileExtension === 'webp' || $fileExtension === 'svg') {
  380. $bdPage = app(App\Services\MediaLibraryService::class)->makeGifBd($file, $media);
  381. } else {
  382. $bdPage = app(App\Services\MediaLibraryService::class)->makeImageBd($file, $media);
  383. }
  384. }
  385. return response($bdPage, 201);
  386. });
  387. Route::post('/file-delete', function () {
  388. $file_path_list = json_decode(request('file_path_list'), true);
  389. Storage::disk(getDisk())->delete($file_path_list);
  390. return response('success', 200);
  391. });
  392. Route::post('/cache-api', function () {
  393. $cacheData = Utils::getParamCache(request('menu_code'), request('api_name'));
  394. if (request('query_name')) {
  395. $cacheData = Utils::getParamCache(request('menu_code'), request('api_name'), request('query_name'));
  396. }
  397. return $cacheData;
  398. });
  399. Route::post('/download/report', function () {
  400. $report = json_decode(request('report'), true);
  401. switch ($report['type']) {
  402. case 'pdf':
  403. $customPaper = array(0, 0, $report['size'], $report['size']);
  404. $table['head'] = $report['head'];
  405. $table['body'] = $report['body'];
  406. $pdf = PDF::loadView('pdf.table', compact('table'))->setPaper($customPaper, 'landscape');
  407. return $pdf->download("{$report['title']}.pdf");
  408. case 'excel':
  409. $report['body'] = collect($report['body'])->prepend($report['head']);
  410. return Excel::download(new Type1Export($report['body']), "{$report['title']}.xlsx");
  411. }
  412. });
  413. Route::post('/paras', function () {
  414. $themeDir = request('theme_dir', 'empty');
  415. $paraType = request('para_type');
  416. $pathToPara = request('path_to_para');
  417. $bpa = request('bpa', '');
  418. try {
  419. if ($paraType == 'modal') {
  420. $para = (new Modal($pathToPara, $themeDir))->getData();
  421. } else if ($paraType == 'formA') {
  422. $para = (new FormA($bpa, $pathToPara, $themeDir))->getData('data');
  423. } else if ($paraType == 'formB') {
  424. $para = (new FormB($bpa, $pathToPara, $themeDir))->getData('data');
  425. } else if ($paraType == 'manual') {
  426. $para = (new Manual($pathToPara, $bpa))->getData();
  427. } else if ($paraType == 'listMedia1') {
  428. $para = (new ListMedia1($bpa, $pathToPara))->getData('data');
  429. }
  430. } catch (Exception $e) {
  431. return response([
  432. 'body' => $e->getMessage(),
  433. 'apiStatus' => 404
  434. ], 200);
  435. }
  436. return $para;
  437. });
  438. });