m3 Security Fixes

This commit is contained in:
Mark Gregory
2026-09-16 17:16:25 +01:00
parent d68687f062
commit 8f37245e13
64 changed files with 4247 additions and 4426 deletions
+74 -79
View File
@@ -2,23 +2,18 @@
namespace Modules\M3\Http\Controllers\API;
use Modules\M3\Http\Controllers\Controller;
use Config;
use DB;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DB;
use Config;
use Str;
use Log;
use Http;
use Cache;
use DateTime;
use Smalot\PdfParser\Parser;
use File;
use Modules\M3\Helpers\Helper;
use Modules\M3\Http\Controllers\Controller;
use Str;
class TwoShipAPIs extends Controller
{
# TwoShipUpdateHold with URL Params
// TwoShipUpdateHold with URL Params
public function TwoShipUpdateHold(Request $request)
{
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
@@ -28,23 +23,23 @@ class TwoShipAPIs extends Controller
// dd($request->all());
// Log::info( $request->all() );
# Get The Calling User
// Get The Calling User
$SHUSER = m3_user() !== '' ? Str::upper(m3_user()) : 'WebUser';
$SHSOURCE = 'TwoShipUpdateHold';
$TwoShipErrors = '';
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$WHS = isset($urlParams["WHS"]) ? $urlParams["WHS"] : '';
$CO = isset($urlParams["COMPANY"]) ? $urlParams["COMPANY"] : '';
$MACPKR = isset($urlParams["MACPKR"]) ? $urlParams["MACPKR"] : '';
$urlParams = count($request->all()) > 0 ? $request->all() : '';
$WHS = isset($urlParams['WHS']) ? $urlParams['WHS'] : '';
$CO = isset($urlParams['COMPANY']) ? $urlParams['COMPANY'] : '';
$MACPKR = isset($urlParams['MACPKR']) ? $urlParams['MACPKR'] : '';
try {
if ($urlParams != '') {
$IncomingParams = ['CO' => $CO, 'WHS' => $WHS, 'MACPKR' => $MACPKR];
$IncomingParams = json_encode($IncomingParams);
# Write to Logs : Params In
// Write to Logs : Params In
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -55,37 +50,36 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# First Step : Get MACPKRs list if available
# select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr=233709) and a4shpaggcd<>0 and a4concmplt<>'y' and a4co=410 and a4whs=111
// First Step : Get MACPKRs list if available
// select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr=233709) and a4shpaggcd<>0 and a4concmplt<>'y' and a4co=410 and a4whs=111
$A4MACPKRSel = DB::connection(config('m3.connection', 'pgsql'))->select(
"select a4macpkr from icm688m1 where a4shpaggcd in (select a4shpaggcd from icm688m1 where a4macpkr={$MACPKR})
and a4shpaggcd<>0 and a4concmplt<>'y' and a4co='{$CO}' and a4whs='{$WHS}' "
and a4shpaggcd<>0 and a4concmplt<>'y' and a4co='{$CO}' and a4whs='{$WHS}' ",
);
// dd($A4MACPKRSel);
if (count($A4MACPKRSel)>0){
if (count($A4MACPKRSel) > 0) {
foreach ($A4MACPKRSel as $key => $A4MACPKRR) {
$A4MACPKRArr[] = $A4MACPKRR->A4MACPKR;
$A4MACPKRArr[] = $A4MACPKRR->A4MACPKR;
}
}
else{
} else {
$A4MACPKRArr[] = $MACPKR;
}
// dump($A4MACPKRArr);
# Call 2ship API with Params
// Call 2ship API with Params
$WS_key = Config::get('arrays.2Ship.TwoShip_Key');
$end_point = Config::get('arrays.2Ship.end_point');
$API = Config::get('arrays.2Ship.hold_update');
$ShipOnHoldOrder_url = $end_point . $API;
# Build Json Data
// Build Json Data
$data = [
'WS_Key' => $WS_key,
'OrderNumbers' => [implode(',', $A4MACPKRArr)],
@@ -103,82 +97,82 @@ class TwoShipAPIs extends Controller
// dump($json_string);
#######
# Initialise the cURL var
// ######
// Initialise the cURL var
$ch = curl_init();
# Get the response from cURL
// Get the response from cURL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $ShipOnHoldOrder_url);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
#When CURLOPT_SSL_VERIFYPEER is enabled (value=1), and the verification fails to prove that the certificate is authentic, the connection fails.
#When the option is zero, the peer certificate verification succeeds regardless.
// When CURLOPT_SSL_VERIFYPEER is enabled (value=1), and the verification fails to prove that the certificate is authentic, the connection fails.
// When the option is zero, the peer certificate verification succeeds regardless.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
#When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that the server is the server to which you meant to connect,
#or the connection fails. Simply put, it means it has to have the same name in the certificate as is in the URL you operate against.
// When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that the server is the server to which you meant to connect,
// or the connection fails. Simply put, it means it has to have the same name in the certificate as is in the URL you operate against.
# Set data content type
// Set data content type
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
[
'Content-Type: application/json',
'Content-Length: ' . strlen($json_string)
)
'Content-Length: ' . strlen($json_string),
],
);
# Post data
// Post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
# Set timeout
// Set timeout
curl_setopt($ch, CURLOPT_TIMEOUT, Config::get('arrays.PHPTimeOut'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::get('arrays.PHPTimeOut'));
# if set true, cURL will follow redirects
// if set true, cURL will follow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
# Execute the request
// Execute the request
$response = curl_exec($ch);
# Verifying error
// Verifying error
$info = curl_getinfo($ch);
# Get status
// Get status
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
# Output the error code
# $CurlError= curl_error($ch);
$CurlError = str_replace("'", " ", curl_error($ch));
// Output the error code
// $CurlError= curl_error($ch);
$CurlError = str_replace("'", ' ', curl_error($ch));
# Close the session
// Close the session
unset($ch);
// dump($response);
// dump($status);
// dump($CurlError);
if ($status == '200' && $CurlError=='') {
if ($status == '200' && $CurlError == '') {
$responseJSON = json_decode($response);
// dump($responseJSON);
if($responseJSON->Success==false){
$TwoShipErrors = '2Ship Error: '.$responseJSON->GlobalError;
if ($responseJSON->Success == false) {
$TwoShipErrors = '2Ship Error: ' . $responseJSON->GlobalError;
}
} else {
$TwoShipErrors = 'Error: No Response from 2Ship';
$TwoShipErrors .= ' -Curl Error: '.$CurlError;
$TwoShipErrors .= ' -Curl Error: ' . $CurlError;
}
# Validate response From 2Ship
# Error
// Validate response From 2Ship
// Error
if ($TwoShipErrors != '') {
// dump($TwoShipErrors);
# Write to Logs : Error
// Write to Logs : Error
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -189,20 +183,20 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Send Response
// Send Response
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Status: '.$status . '-' . $TwoShipErrors
'message' => 'Status: ' . $status . '-' . $TwoShipErrors,
]);
}
# Success
else{
# Write to Logs : JSON
// Success
else {
// Write to Logs : JSON
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -213,27 +207,28 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Update ICM688M1 set a4concmplt to 'y'
// Update ICM688M1 set a4concmplt to 'y'
DB::connection(config('m3.connection', 'pgsql'))->table('icm688m1')
->whereIn('A4MACPKR',$A4MACPKRArr)
->where('A4CO',$CO)
->where('A4WHS',$WHS)
->update(['A4CONCMPLT'=>'Y']);
->whereIn('A4MACPKR', $A4MACPKRArr)
->where('A4CO', $CO)
->where('A4WHS', $WHS)
->update(['A4CONCMPLT' => 'Y']);
}
# Send Response
// Send Response
return response()->json([
'code' => '200',
'status' => 'Success'
'status' => 'Success',
]);
}
# Error : No URL params
// Error : No URL params
else {
# Write to Logs Out : Error
// Write to Logs Out : Error
$MACPKR = isset($MACPKR) ? $MACPKR : '000000';
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
@@ -245,23 +240,23 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
# Return Error
// Return Error
return response()->json([
'code' => '405',
'status' => 'Error',
'message' => 'No URL Parameters Sent'
'message' => 'No URL Parameters Sent',
]);
}
} catch (\Throwable $th) {
# Write to Logs Out : Error
// Write to Logs Out : Error
$getCurlErrors = str_contains($th->getMessage(), 'cURL error');
if ($getCurlErrors) {
// dd($getCurlErrors);
# Write to Logs Out : Failed
// Write to Logs Out : Failed
$data = ['SHMACPKR' => $MACPKR,
'SHDT' => date('Y-m-d'),
'SHTIME' => date('H:i:s'),
@@ -272,17 +267,17 @@ class TwoShipAPIs extends Controller
'SHUSER' => $SHUSER,
'SHSOURCE' => $SHSOURCE,
'SHCO' => $CO,
'SHWHS' => $WHS
'SHWHS' => $WHS,
];
Helper::logToICM699M($data);
return response()->json([
'code' => '405',
'status' => 'error',
'message' => 'Curl Error: Communication with 2Ship Timed Out.'
'message' => 'Curl Error: Communication with 2Ship Timed Out.',
]);
}
}
}
# End TwoShipUpdateHold
// End TwoShipUpdateHold
}