Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit fefbf8e

Browse files
authored
Merge pull request #163 from ExpDev07/dev
Features
2 parents fd3550b + 8c0d45d commit fefbf8e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ VUE_APP_LOCALE=en-us
6060
OP_FW_SERVERS=c3s1.op-framework.com,c3s2.op-framework.com
6161
OP_FW_TOKEN=mytoken
6262
DEV_API_KEY=some_random_token
63+
64+
SOCKET_ROOT="C:\\path\\to\\legacyrp-admin-panel-sockets"

app/Helpers/GeneralHelper.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,25 @@ public static function randomElement(array $array, array $lastElement, string $c
6666

6767
return $newElement;
6868
}
69+
70+
/**
71+
* Creates a session file for authentication with the socket server
72+
*/
73+
public static function updateSocketSession()
74+
{
75+
$session = SessionHelper::getInstance();
76+
$key = $session->getSessionKey();
77+
78+
$dir = rtrim(rtrim(env('SOCKET_ROOT', ''), '/'), '\\');
79+
80+
if ($dir && file_exists($dir) && is_dir($dir)) {
81+
$dir .= '/sessions/';
82+
83+
if (!file_exists($dir)) {
84+
mkdir($dir);
85+
}
86+
87+
file_put_contents($dir . '/' . $key . '.session', json_encode($session->get('user')));
88+
}
89+
}
6990
}

app/Helpers/SessionHelper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,28 @@ public static function getInstance(): SessionHelper
175175
LoggingHelper::log($helper->sessionKey, $log);
176176
}
177177

178+
$uri = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
179+
180+
$extraDomains = [
181+
parse_url($uri, PHP_URL_HOST) . ':8080',
182+
parse_url($uri, PHP_URL_HOST) . ':8443',
183+
];
184+
178185
setcookie($key, $helper->sessionKey, [
179186
'expires' => time() + self::Lifetime,
180187
'secure' => true,
181188
'path' => '/',
182189
]);
183190

191+
foreach ($extraDomains as $domain) {
192+
setcookie($key, $helper->sessionKey, [
193+
'expires' => time() + self::Lifetime,
194+
'secure' => true,
195+
'path' => '/',
196+
'domain' => $domain,
197+
]);
198+
}
199+
184200
$helper->load();
185201
$helper->store();
186202

app/Http/Middleware/StaffMiddleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Middleware;
44

5+
use App\Helpers\GeneralHelper;
56
use App\Helpers\LoggingHelper;
67
use App\Helpers\SessionHelper;
78
use Closure;
@@ -35,6 +36,8 @@ public function handle(Request $request, Closure $next)
3536
return redirect('/login')->with('error',
3637
'You must be a staff member to access the dashboard! If you believe this is a mistake, contact a developer.'
3738
);
39+
} else {
40+
GeneralHelper::updateSocketSession();
3841
}
3942

4043
return $next($request);

0 commit comments

Comments
 (0)