1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-09 11:42:28 +01:00

Add feature to set allowed domain

Now admin can set a comma separated list of allowd domain in .env file
under ALLOWED_DOMAINS entry to restrict link shortening to a certain
doamins. If not set any, all domains would pass this filter and the app
would function like before.
This commit is contained in:
Mostafa Ahangarha 2021-06-23 09:40:30 +04:30
parent 6e73538257
commit 9f9772c3e8

View File

@ -37,6 +37,28 @@ class LinkController extends Controller {
$creator = session('username');
$link_ip = $request->ip();
$is_allowd_domain = false;
if (!env('ALLOWED_DOMAINS'))
{
$is_allowd_domain = true;
} else {
foreach (explode(',', env('ALLOWED_DOMAINS')) as $allowed_domain)
{
if (substr($long_url, 0, strlen($allowed_domain)) === $allowed_domain)
{
$is_allowd_domain = true;
break;
}
}
}
if (!$is_allowd_domain)
{
return self::renderError('Domain is not allowed!');
}
try {
$short_url = LinkFactory::createLink($long_url, $is_secret, $custom_ending, $link_ip, $creator);
}