Advertisement
Guest User

Untitled

a guest
Jun 9th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for SourceGuardian Encoder)
  6. *
  7. * @ Version : 5.0.1.0
  8. * @ Author : DeZender
  9. * @ Release on : 22.04.2022
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace App\Http\Controllers\StreamPlayApi\Integration;
  15.  
  16. class StalkerApiIntegrationController extends \App\Http\Controllers\Api\ApiController
  17. {
  18. private $serverRepository = null;
  19. private $streamRepository = null;
  20. private $seriesRepository = null;
  21. private $lineRepository = null;
  22. private $logger = null;
  23. private $idResolver = null;
  24. private $deviceSettingService = null;
  25. private $generalSettings = null;
  26. private $streamFormat = null;
  27. private $allowedNoAuth = ['stb_get_profile', 'stb_get_modules', 'stb_get_localization'];
  28.  
  29. public function __construct(\App\Http\Repositories\StreamingServerRepository $serverRepository, \App\Http\Repositories\StreamRepository $streamRepository, \App\Http\Repositories\SeriesRepository $seriesRepository, \App\Http\Repositories\LineRepository $lineRepository, \Psr\Log\LoggerInterface $logger, \App\Http\Services\UuidToIntResolver $idResolver, \App\Http\Repositories\SettingsRepository $generalSettings)
  30. {
  31. $this->serverRepository = $serverRepository;
  32. $this->streamRepository = new \App\Http\Services\PersistentCache\Repositories\ProxyRepository($streamRepository);
  33. $this->seriesRepository = new \App\Http\Services\PersistentCache\Repositories\ProxyRepository($seriesRepository);
  34. $this->lineRepository = $lineRepository;
  35. $this->logger = $logger;
  36. $this->idResolver = $idResolver;
  37. $this->streamFormat = '';
  38. $this->generalSettings = $generalSettings->magDevice();
  39. $this->localisationSettings = $generalSettings->localisation();
  40. }
  41.  
  42. private function getOrderBy($type)
  43. {
  44. return $this->generalSettings->default_ord[$type] ?? '';
  45. }
  46.  
  47. public function index(\Illuminate\Http\Request $request, \App\Http\Services\Device\AuthService $authService, \App\Http\Services\Device\SettingsService $deviceSettingService)
  48. {
  49. \is_cache_loaded();
  50. fad0d5ca831cd5aeba3a7c835dc7808f673843d63089d856f94f59ff8c9d06fcb();
  51.  
  52. if (!method_exists('\\Illuminate\\Redis\\RedisManager', 'persistent')) {
  53. echo 'Could not connect to Redis at 127.0.0.1:6379: Connection refused';
  54. exit();
  55. }
  56.  
  57. $type = $request->get('type');
  58. $action = $request->get('action');
  59. $method = $type . '_' . $action;
  60.  
  61. if (!method_exists($this, $method)) {
  62. return $this->respond([
  63. 'js' => []
  64. ]);
  65. }
  66.  
  67. $line = $request->input('__line');
  68. if (!$line && !in_array($method, $this->allowedNoAuth)) {
  69. return $this->respond([
  70. 'js' => ['Auth Required']
  71. ], 401);
  72. }
  73.  
  74. $authService->setRequest($request);
  75. $this->deviceSettingService = $deviceSettingService;
  76. $this->deviceSettingService->setDeviceId($authService->getDeviceId());
  77.  
  78. try {
  79. $response = ['js' => $this->{$method}($request)];
  80. }
  81. catch (\Symfony\Component\HttpKernel\Exception\HttpException $e) {
  82. throw $e;
  83. }
  84. catch (\Exception $e) {
  85. \Illuminate\Support\Facades\Log::error('Stalker api exception: ' . $e->getMessage() . ' ' . $e->getTraceAsString());
  86. $response = [
  87. 'js' => []
  88. ];
  89. }
  90.  
  91. return $this->respond($response);
  92. }
  93.  
  94. public function handshake(\Illuminate\Http\Request $request, \App\Http\Services\Device\AuthService $authService, \App\Http\Services\Subscriptions\TokenService $tokenService)
  95. {
  96. $authService->setRequest($request);
  97. $ip = $request->ip();
  98. $rateLimitService = new \App\Http\Services\RateLimit\RateLimitService($ip);
  99.  
  100. if ($rateLimitService->isTooManyAttempts()) {
  101. throw new \Symfony\Component\HttpKernel\Exception\HttpException(\Symfony\Component\HttpFoundation\Response::HTTP_TOO_MANY_REQUESTS, 'Too many attempts');
  102. }
  103.  
  104. $line = $authService->auth();
  105.  
  106. if (!$line) {
  107. $rateLimitService->registerAttempts();
  108. $token = strtoupper(md5(uniqid(rand(), true)));
  109. }
  110. else {
  111. $lineDto = new \App\Structs\Dto\LineDto($request, $line);
  112. $locks = \App\Http\Services\LineLock\LineLockFactory::createFromLine($line, $request);
  113. $this->checkLocks($locks, $lineDto, $line);
  114. $type = 'short';
  115. $token = $tokenService->generateToken($type, $line, 120)[0];
  116. }
  117.  
  118. $response = ['js' => $this->doHandshake($token)];
  119. return $this->respond($response);
  120. }
  121.  
  122. public function doHandshake($token)
  123. {
  124. $response['token'] = (string) $token;
  125. return $response;
  126. }
  127.  
  128. public function stb_log()
  129. {
  130. return true;
  131. }
  132.  
  133. public function stb_get_profile(\Illuminate\Http\Request $request)
  134. {
  135. $profile = $request->input('__line') ?: new \App\Models\Line();
  136. $profile['mac'] = $request->cookie('mac');
  137. $profile['ip'] = $request->ip();
  138. $settingsRepository = new \App\Http\Repositories\SettingsRepository();
  139. $profile['use_password'] = !$settingsRepository->magDevice()->disable_password;
  140. $line = $request->input('__line');
  141.  
  142. if ($line) {
  143. $lineDto = new \App\Structs\Dto\LineDto($request, $line);
  144. $locks = \App\Http\Services\LineLock\LineLockFactory::createFromLine($line, $request, ['stb']);
  145. $this->checkLocks($locks, $lineDto, $line);
  146. }
  147.  
  148. $serializer = new \App\Http\Serializers\StreamPlayApi\StalkerPlayer\ProfileSerializer($this->generalSettings);
  149. $response = $serializer->transform($profile);
  150. return $response;
  151. }
  152.  
  153. public function stb_get_localization(\Illuminate\Http\Request $request)
  154. {
  155. $localeLang = $this->deviceSettingService->getLang();
  156. if ($request->hasCookie('locale') && !!$request->cookie('locale')) {
  157. $localeLang = $request->cookie('locale');
  158. }
  159.  
  160. $serializer = new \App\Http\Serializers\StreamPlayApi\StalkerPlayer\LocalizationSerializer();
  161. ...............................................................
  162. ......................................
  163. ...............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement