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
@@ -1,30 +1,28 @@
<?php
namespace Modules\M3\Http\Controllers;
use DB;
use Config;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Support\Facades\Http; #added this for curl call to v4
use DateTime;
use DatePeriod;
use DateInterval;
use DB;
use Illuminate\Support\Facades\Http; // added this for curl call to v4
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Symfony\Component\HttpFoundation\Request;
class userPickingStats5 extends Controller
{
public static function index(Request $request)
{
public static function index(Request $request){
#618
# Get Logged User CO & WH. Legacy M3 profile data may not yet exist in PostgreSQL.
// 618
// Get Logged User CO & WH. Legacy M3 profile data may not yet exist in PostgreSQL.
$co = '';
$whs = '';
$user_array = [];
try {
if (\Illuminate\Support\Facades\Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) {
if (Schema::connection(config('m3.connection', 'pgsql'))->hasTable('icm428m')) {
$profile = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US','R428CO', 'R428WH')
->select('R428US', 'R428CO', 'R428WH')
->where('R428US', strtoupper((string) m3_user()))
->first();
$co = trim((string) ($profile->R428CO ?? ''));
@@ -48,42 +46,42 @@ class userPickingStats5 extends Controller
}
}
} catch (\Throwable $e) {
\Illuminate\Support\Facades\Log::warning('M3 picking user list unavailable', ['exception' => $e->getMessage()]);
Log::warning('M3 picking user list unavailable', ['exception' => $e->getMessage()]);
$user_array = [];
}
// Filter by date
if (isset($request->dates)) {
$date = explode (' - ', $request->dates);
$start = str_replace(array(' ', '-'), '', $date[0]);
$end = str_replace(array(' ', '-'), '', $date[1]);
$date = explode(' - ', $request->dates);
$start = str_replace([' ', '-'], '', $date[0]);
$end = str_replace([' ', '-'], '', $date[1]);
$starting = $date[0];
$ending = $date[1];
} else {
$start = date("Ymd", strtotime("-5 days"));
$end = date("Ymd");
$starting = date("Y-m-d", strtotime("-5 days"));
#$starting = "2021-11-01";
$ending = date("Y-m-d");
$start = date('Ymd', strtotime('-5 days'));
$end = date('Ymd');
$starting = date('Y-m-d', strtotime('-5 days'));
// $starting = "2021-11-01";
$ending = date('Y-m-d');
}
// calculate day difference between 2 dates
$str_date = new DateTime($starting);
$end_date = new DateTime($ending);
$interval = $str_date->diff($end_date);
$days = $interval->format('%a'); //retrieve number of days %a
#echo "diff=$days<br>";
$days = $interval->format('%a'); // retrieve number of days %a
// echo "diff=$days<br>";
$user=$request->user;
$user = $request->user;
// retrieve session user and pw, also the HTTP server host address and port
$username = $request->header('php-auth-user');
$pw = $request->header('php-auth-pw');
$username = $request->header('php-auth-user');
$pw = $request->header('php-auth-pw');
$http_host = $request->server('HTTP_HOST');
$urlStats4 = "http://$http_host/userPickingStats4";
// initialize arrays
$statistic5 = $totals_array = array();
$statistic5 = $totals_array = [];
// initialize totals
$totals_array['performance'] = 0;
$totals_array['blendedTargetLPH'] = 0;
@@ -93,53 +91,53 @@ class userPickingStats5 extends Controller
// loop for the days difference and passing proper date to v4 to get json encoded response
if (isset($request->dates)) {
for($x=0;$x<=$days;$x++) {
for ($x = 0; $x <= $days; $x++) {
$next_date = date("Y-m-d",strtotime($starting."+$x days"));
$next_date = date('Y-m-d', strtotime($starting . "+$x days"));
$parameters = ['dates'=>$next_date, 'user'=>$request->user, 'format'=>'json'];
#echo "<pre>"; print_r($parameters); echo "$urlStats4</pre>";
$parameters = ['dates' => $next_date, 'user' => $request->user, 'format' => 'json'];
// echo "<pre>"; print_r($parameters); echo "$urlStats4</pre>";
$response = Http::withBasicAuth($username, $pw)->get($urlStats4, $parameters);
#echo $response;
$statusCode = $response->status();
$response = Http::withBasicAuth($username, $pw)->get($urlStats4, $parameters);
// echo $response;
$statusCode = $response->status();
#echo "$statusCode json return=".$response->getBody()." <br>";
// echo "$statusCode json return=".$response->getBody()." <br>";
$statistic5[$x] = json_decode($response->getBody(),true);
$statistic5[$x] = json_decode($response->getBody(), true);
$totals_array['performance'] += isset($statistic5[$x]['performance'])?$statistic5[$x]['performance']:0;
$totals_array['blendedTargetLPH'] += isset($statistic5[$x]['blendedTargetLPH'])?$statistic5[$x]['blendedTargetLPH']:0;
$totals_array['actualLPH'] += isset($statistic5[$x]['actualLPH'])?$statistic5[$x]['actualLPH']:0;
$totals_array['grossHours'] += isset($statistic5[$x]['grossHours'])?$statistic5[$x]['grossHours']:0;
$totals_array['performance'] += isset($statistic5[$x]['performance']) ? $statistic5[$x]['performance'] : 0;
$totals_array['blendedTargetLPH'] += isset($statistic5[$x]['blendedTargetLPH']) ? $statistic5[$x]['blendedTargetLPH'] : 0;
$totals_array['actualLPH'] += isset($statistic5[$x]['actualLPH']) ? $statistic5[$x]['actualLPH'] : 0;
$totals_array['grossHours'] += isset($statistic5[$x]['grossHours']) ? $statistic5[$x]['grossHours'] : 0;
if(!isset($statistic5[$x]['day'])) {
if (! isset($statistic5[$x]['day'])) {
$statistic5[$x]['day'] = $next_date;
}
if(isset($statistic5[$x]['performance'])) {
if($statistic5[$x]['performance']>0) {
if (isset($statistic5[$x]['performance'])) {
if ($statistic5[$x]['performance'] > 0) {
$y++;
}
} else {
$statistic5[$x]['performance']=0;
$statistic5[$x]['performance'] = 0;
}
}
}
if($y>0) {
if ($y > 0) {
$totals_array['performance'] /= $y;
$totals_array['blendedTargetLPH'] /= $y;
$totals_array['actualLPH'] /= $y;
$totals_array['grossHours'] /= $y;
}
if($request->format=="json") {
echo "<pre>";
if ($request->format == 'json') {
echo '<pre>';
print_r($statistic5);
echo "</pre>";
}else{
#dd($statistic5);
#if($statistic5[1]!=null)
echo '</pre>';
} else {
// dd($statistic5);
// if($statistic5[1]!=null)
return view('m3::liberty-theme.pages.userPickingStats5', compact('statistic5', 'totals_array', 'user_array', 'user', 'starting', 'ending', 'request'));
}