SMS and secure link : GWM
This commit is contained in:
parent
7497d8e72a
commit
495f920326
@ -12,7 +12,7 @@ use CodeIgniter\Filters\InvalidChars;
|
|||||||
use CodeIgniter\Filters\PageCache;
|
use CodeIgniter\Filters\PageCache;
|
||||||
use CodeIgniter\Filters\PerformanceMetrics;
|
use CodeIgniter\Filters\PerformanceMetrics;
|
||||||
use CodeIgniter\Filters\SecureHeaders;
|
use CodeIgniter\Filters\SecureHeaders;
|
||||||
|
use App\Filters\SignedUrlFilter;
|
||||||
class Filters extends BaseFilters
|
class Filters extends BaseFilters
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -34,6 +34,7 @@ class Filters extends BaseFilters
|
|||||||
'forcehttps' => ForceHTTPS::class,
|
'forcehttps' => ForceHTTPS::class,
|
||||||
'pagecache' => PageCache::class,
|
'pagecache' => PageCache::class,
|
||||||
'performance' => PerformanceMetrics::class,
|
'performance' => PerformanceMetrics::class,
|
||||||
|
'signedUrl' => SignedUrlFilter::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class Logger extends BaseConfig
|
|||||||
*
|
*
|
||||||
* @var int|list<int>
|
* @var int|list<int>
|
||||||
*/
|
*/
|
||||||
public $threshold = (ENVIRONMENT === 'production') ? 4 : 9;
|
public $threshold = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
|
|||||||
@ -98,4 +98,6 @@ use CodeIgniter\Router\RouteCollection;
|
|||||||
$routes->post('status_branch','BranchController::status_branch');
|
$routes->post('status_branch','BranchController::status_branch');
|
||||||
|
|
||||||
|
|
||||||
|
$routes->get('sendSms','TestController::sendSms');
|
||||||
|
$routes->get('protected-page', 'TestController::protectedPage', ['filter' => 'signedUrl']);
|
||||||
|
$routes->get('sendUrl', 'TestController::sendUrl');
|
||||||
49
app/Controllers/TestController.php
Normal file
49
app/Controllers/TestController.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use CodeIgniter\Controller;
|
||||||
|
|
||||||
|
class TestController extends Controller
|
||||||
|
{
|
||||||
|
public function sendSms()
|
||||||
|
{
|
||||||
|
$apiKey = 'HgvlULWCIrs'; // Your API key
|
||||||
|
$mobileNumbers = '9894638731'; // Recipient mobile numbers
|
||||||
|
$DLTTemplateID = '1107171922342349877'; // DLT Template ID
|
||||||
|
$senderId = 'LDRAJ'; // Sender ID
|
||||||
|
$message = 'Dear Gowtham, 986532 is OTP to approve Service group for service name purposes.';
|
||||||
|
$serviceName = 'TEMPLATE_BASED'; // Service name
|
||||||
|
|
||||||
|
// URL encode the message
|
||||||
|
$encodedMessage = urlencode($message);
|
||||||
|
|
||||||
|
// Initialize cURL
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
// Set cURL options
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=$apiKey&MobileNo=$mobileNumbers&SenderID=$senderId&Message=$encodedMessage&ServiceName=$serviceName&DLTTemplateID=$DLTTemplateID");
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||||
|
|
||||||
|
// Execute cURL request and get the response
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// Output the response (for testing purposes)
|
||||||
|
return $this->response->setJSON(['response' => $output]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendUrl()
|
||||||
|
{
|
||||||
|
helper('url');
|
||||||
|
$signedUrl = generate_signed_url('protected-page', [], 36000);
|
||||||
|
// Send the $signedUrl to your client (e.g., via email)
|
||||||
|
|
||||||
|
return $this->response->setJSON(['url' => $signedUrl]);
|
||||||
|
}
|
||||||
|
public function protectedPage(){
|
||||||
|
echo "This is protectedPage";
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Filters/SignedUrlFilter.php
Normal file
44
app/Filters/SignedUrlFilter.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\Filters\FilterInterface;
|
||||||
|
use Config\Services;
|
||||||
|
class SignedUrlFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
public function before(RequestInterface $request, $arguments = null)
|
||||||
|
{
|
||||||
|
$secretKey = 'your-secret-key'; // Change this to your secret key
|
||||||
|
$expires = $request->getGet('expires');
|
||||||
|
$signature = $request->getGet('signature');
|
||||||
|
|
||||||
|
if (!$expires || !$signature) {
|
||||||
|
return Services::response()->setStatusCode(403)->setBody('Forbidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time() > $expires) {
|
||||||
|
$body = view('expired_link');
|
||||||
|
return Services::response()->setStatusCode(403)->setBody($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
$queryParams = $request->getGet();
|
||||||
|
unset($queryParams['signature']);
|
||||||
|
$route = $request->getPath();
|
||||||
|
$expectedSignature = hash_hmac('sha256', $route . '?' . http_build_query($queryParams), $secretKey);
|
||||||
|
|
||||||
|
if (!hash_equals($expectedSignature, $signature)) {
|
||||||
|
return Services::response()->setStatusCode(403)->setBody('Invalid signature');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; // Allow the request
|
||||||
|
}
|
||||||
|
|
||||||
|
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||||
|
{
|
||||||
|
// Do nothing here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
15
app/Helpers/url_helper.php
Normal file
15
app/Helpers/url_helper.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Config\Services;
|
||||||
|
|
||||||
|
if (!function_exists('generate_signed_url')) {
|
||||||
|
function generate_signed_url($route, $params = [], $expiresIn = 3600)
|
||||||
|
{
|
||||||
|
$secretKey = 'your-secret-key'; // Change this to your secret key
|
||||||
|
$expiresAt = time() + $expiresIn;
|
||||||
|
$params['expires'] = $expiresAt;
|
||||||
|
$signature = hash_hmac('sha256', $route . '?' . http_build_query($params), $secretKey);
|
||||||
|
$params['signature'] = $signature;
|
||||||
|
return base_url($route . '?' . http_build_query($params));
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Views/expired_link.php
Normal file
35
app/Views/expired_link.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Link Expired</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
.text{
|
||||||
|
font-size: large;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<img src="<?= base_url('public/assets/images/404.gif') ?>" alt="Link Expired">
|
||||||
|
<p class="text">Link expired</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
public/assets/images/404.gif
Normal file
BIN
public/assets/images/404.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
Loading…
Reference in New Issue
Block a user