diff --git a/Dockerfile b/Dockerfile index b572ff689..4a240d7e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 LABEL maintainer="Brady Wetherington " # No need to add `apt-get clean` here, reference: @@ -14,16 +14,16 @@ RUN export DEBIAN_FRONTEND=noninteractive; \ apt-utils \ apache2 \ apache2-bin \ -libapache2-mod-php7.4 \ -php7.4-curl \ -php7.4-ldap \ -php7.4-mysql \ -php7.4-gd \ -php7.4-xml \ -php7.4-mbstring \ -php7.4-zip \ -php7.4-bcmath \ -php7.4-redis \ +libapache2-mod-php8.1 \ +php8.1-curl \ +php8.1-ldap \ +php8.1-mysql \ +php8.1-gd \ +php8.1-xml \ +php8.1-mbstring \ +php8.1-zip \ +php8.1-bcmath \ +php8.1-redis \ php-memcached \ patch \ curl \ @@ -40,7 +40,7 @@ autoconf \ libc-dev \ pkg-config \ libmcrypt-dev \ -php7.4-dev \ +php8.1-dev \ ca-certificates \ unzip \ dnsutils \ @@ -50,16 +50,16 @@ dnsutils \ RUN curl -L -O https://github.com/pear/pearweb_phars/raw/master/go-pear.phar RUN php go-pear.phar -RUN pecl install mcrypt-1.0.3 +RUN pecl install mcrypt -RUN bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.4/mods-available/mcrypt.ini" +RUN bash -c "echo extension=/usr/lib/php/20210902/mcrypt.so > /etc/php/8.1/mods-available/mcrypt.ini" RUN phpenmod mcrypt RUN phpenmod gd RUN phpenmod bcmath -RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.4/apache2/php.ini -RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.4/cli/php.ini +RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/8.1/apache2/php.ini +RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/8.1/cli/php.ini RUN useradd -m --uid 1000 --gid 50 docker diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 93dba995a..62a928f8a 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,34 +1,34 @@ -FROM alpine:3.14.2 +FROM alpine:3.17.3 # Apache + PHP RUN apk add --no-cache \ apache2 \ - php7 \ - php7-common \ - php7-apache2 \ - php7-curl \ - php7-ldap \ - php7-mysqli \ - php7-gd \ - php7-xml \ - php7-mbstring \ - php7-zip \ - php7-ctype \ - php7-tokenizer \ - php7-pdo_mysql \ - php7-openssl \ - php7-bcmath \ - php7-phar \ - php7-json \ - php7-iconv \ - php7-fileinfo \ - php7-simplexml \ - php7-session \ - php7-dom \ - php7-xmlwriter \ - php7-xmlreader \ - php7-sodium \ - php7-redis \ - php7-pecl-memcached \ + php81 \ + php81-common \ + php81-apache2 \ + php81-curl \ + php81-ldap \ + php81-mysqli \ + php81-gd \ + php81-xml \ + php81-mbstring \ + php81-zip \ + php81-ctype \ + php81-tokenizer \ + php81-pdo_mysql \ + php81-openssl \ + php81-bcmath \ + php81-phar \ + php81-json \ + php81-iconv \ + php81-fileinfo \ + php81-simplexml \ + php81-session \ + php81-dom \ + php81-xmlwriter \ + php81-xmlreader \ + php81-sodium \ + php81-redis \ + php81-pecl-memcached \ curl \ wget \ vim \ @@ -41,7 +41,7 @@ COPY docker/column-statistics.cnf /etc/mysql/conf.d/column-statistics.cnf # Where apache's PID lives RUN mkdir -p /run/apache2 && chown apache:apache /run/apache2 -RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php7/php.ini +RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php81/php.ini COPY docker/000-default-2.4.conf /etc/apache2/conf.d/default.conf # Enable mod_rewrite diff --git a/Dockerfile.fpm-alpine b/Dockerfile.fpm-alpine index 3bb4566ff..77302524d 100644 --- a/Dockerfile.fpm-alpine +++ b/Dockerfile.fpm-alpine @@ -1,8 +1,8 @@ ARG ENVIRONMENT=production -ARG SNIPEIT_RELEASE=5.1.3 -ARG PHP_VERSION=7.4.16 -ARG PHP_ALPINE_VERSION=3.13 -ARG COMPOSER_VERSION=2.0.11 +ARG SNIPEIT_RELEASE=6.1.0 +ARG PHP_VERSION=8.2 +ARG PHP_ALPINE_VERSION=3.17 +ARG COMPOSER_VERSION=2 # Cannot use arguments with 'COPY --from' workaround # https://github.com/moby/moby/issues/34482#issuecomment-454716952 @@ -52,7 +52,7 @@ RUN { \ # Install php extensions inside docker containers easily # https://github.com/mlocati/docker-php-extension-installer -COPY --from=mlocati/php-extension-installer:1.2.19 /usr/bin/install-php-extensions /usr/local/bin/ +COPY --from=mlocati/php-extension-installer:2.1.15 /usr/bin/install-php-extensions /usr/local/bin/ RUN set -eux; \ install-php-extensions \ bcmath \ diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index dc2130e98..2ca8fcd9e 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -80,12 +80,9 @@ class AccessoriesController extends Controller $accessories->where('notes','=',$request->input('notes')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($accessories) && ($request->get('offset') > $accessories->count())) ? $accessories->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $accessories->count()) ? $accessories->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort_override = $request->input('sort'); diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index e38d5382f..3896d26d8 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -55,12 +55,9 @@ class AssetMaintenancesController extends Controller } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($maintenances) && ($request->get('offset') > $maintenances->count())) ? $maintenances->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $maintenances->count()) ? $maintenances->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $allowed_columns = [ 'id', diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 5e9b3ad78..39e7b3d13 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -78,12 +78,9 @@ class AssetModelsController extends Controller $assetmodels->TextSearch($request->input('search')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($assetmodels) && ($request->get('offset') > $assetmodels->count())) ? $assetmodels->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $assetmodels->count()) ? $assetmodels->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'models.created_at'; diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bad194796..275490294 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -199,13 +199,9 @@ class AssetsController extends Controller $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($assets) && ($request->get('offset') > $assets->count())) ? $assets->count() : $request->get('offset', 0); - - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index 91b0d7f7d..d00138ee3 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -67,8 +67,6 @@ class CategoriesController extends Controller $categories = $categories->withCount('showableAssets as assets_count'); } - - if ($request->filled('search')) { $categories = $categories->TextSearch($request->input('search')); } @@ -93,14 +91,9 @@ class CategoriesController extends Controller $categories->where('checkin_email', '=', $request->input('checkin_email')); } - - - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($categories) && ($request->get('offset') > $categories->count())) ? $categories->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $categories->count()) ? $categories->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count'; diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index 11f584567..efb445029 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -48,12 +48,10 @@ class CompaniesController extends Controller } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($companies) && ($request->get('offset') > $companies->count())) ? $companies->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $companies->count()) ? $companies->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index bf281d6b2..ddf412a44 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -72,14 +72,10 @@ class ComponentsController extends Controller $components->where('notes','=',$request->input('notes')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($components) && ($request->get('offset') > $components->count())) ? $components->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $components->count()) ? $components->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); - - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort_override = $request->input('sort'); $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index e9a069c37..a075fce56 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -84,12 +84,10 @@ class ConsumablesController extends Controller } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($consumables) && ($request->get('offset') > $consumables->count())) ? $consumables->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $consumables->count()) ? $consumables->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); $allowed_columns = ['id', 'name', 'order_number', 'min_amt', 'purchase_date', 'purchase_cost', 'company', 'category', 'model_number', 'item_no', 'manufacturer', 'location', 'qty', 'image']; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 09e367736..e804aa42c 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -58,12 +58,10 @@ class DepartmentsController extends Controller $departments->where('location_id', '=', $request->input('location_id')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($departments) && ($request->get('offset') > $departments->count())) ? $departments->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $departments->count()) ? $departments->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 2dd6b9d8e..90bf26ac4 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -28,12 +28,10 @@ class DepreciationsController extends Controller $depreciations = $depreciations->TextSearch($request->input('search')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($depreciations) && ($request->get('offset') > $depreciations->count())) ? $depreciations->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $depreciations->count()) ? $depreciations->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/GroupsController.php b/app/Http/Controllers/Api/GroupsController.php index 0e5d391e5..4a00a78c7 100644 --- a/app/Http/Controllers/Api/GroupsController.php +++ b/app/Http/Controllers/Api/GroupsController.php @@ -35,12 +35,9 @@ class GroupsController extends Controller $groups->where('name', '=', $request->input('name')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($groups) && ($request->get('offset') > $groups->count())) ? $groups->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $groups->count()) ? $groups->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php index 759f11e95..0afc64337 100644 --- a/app/Http/Controllers/Api/LicenseSeatsController.php +++ b/app/Http/Controllers/Api/LicenseSeatsController.php @@ -39,8 +39,10 @@ class LicenseSeatsController extends Controller } $total = $seats->count(); - $offset = (($seats) && (request('offset') >= $total)) ? 0 : request('offset', 0); - $limit = request('limit', 50); + + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $seats->count()) ? $seats->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $seats = $seats->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 6e67f07ee..9320aa27b 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -94,12 +94,9 @@ class LicensesController extends Controller $licenses->onlyTrashed(); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($licenses) && ($request->get('offset') > $licenses->count())) ? $licenses->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $licenses->count()) ? $licenses->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 3a8df1058..14e97a984 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -78,14 +78,24 @@ class LocationsController extends Controller $locations->where('locations.country', '=', $request->input('country')); } - $offset = (($locations) && (request('offset') > $locations->count())) ? $locations->count() : request('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; + \Log::debug('Max in env: '.config('app.max_results')); + \Log::debug('Original requested offset: '.$request->input('offset')); + \Log::debug('Intval offset: '.intval($request->input('offset'))); + \Log::debug('Modified offset: '.$offset); + \Log::debug('Original requested limit: '.$request->input('limit')); + \Log::debug('Intval limit: '.intval($request->input('limit'))); + \Log::debug('Modified limit: '.$limit); + \Log::debug('Total results: '.$locations->count()); + \Log::debug('------------------------------'); + + switch ($request->input('sort')) { case 'parent': $locations->OrderParent($order); diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index e88ef5fed..f0a02484e 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -57,12 +57,9 @@ class ManufacturersController extends Controller $manufacturers->where('support_email', '=', $request->input('support_email')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($manufacturers) && ($request->get('offset') > $manufacturers->count())) ? $manufacturers->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $manufacturers->count()) ? $manufacturers->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php index a2c0c1a90..fc55de4d6 100644 --- a/app/Http/Controllers/Api/PredefinedKitsController.php +++ b/app/Http/Controllers/Api/PredefinedKitsController.php @@ -29,8 +29,10 @@ class PredefinedKitsController extends Controller $kits = $kits->TextSearch($request->input('search')); } - $offset = $request->input('offset', 0); - $limit = $request->input('limit', 50); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $kits->count()) ? $kits->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $order = $request->input('order') === 'desc' ? 'desc' : 'asc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'name'; $kits->orderBy($sort, $order); diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index f42a2d0f8..18772b55e 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -54,15 +54,16 @@ class ReportsController extends Controller 'note', ]; + + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + + $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $order = ($request->input('order') == 'asc') ? 'asc' : 'desc'; - $offset = request('offset', 0); $total = $actionlogs->count(); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); - - $actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get(); return response()->json((new ActionlogsTransformer)->transformActionlogs($actionlogs, $total), 200, ['Content-Type' => 'application/json;charset=utf8'], JSON_UNESCAPED_UNICODE); diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index 76055f2d9..d37204ac9 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -50,12 +50,9 @@ class StatuslabelsController extends Controller } } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($statuslabels) && ($request->get('offset') > $statuslabels->count())) ? $statuslabels->count() : $request->get('offset', 0); - - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $statuslabels->count()) ? $statuslabels->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index f73f15049..0a1710d18 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -74,12 +74,10 @@ class SuppliersController extends Controller $suppliers->where('notes', '=', $request->input('notes')); } - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($suppliers) && ($request->get('offset') > $suppliers->count())) ? $suppliers->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $suppliers->count()) ? $suppliers->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index ff18b8791..060858128 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -193,12 +193,10 @@ class UsersController extends Controller $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which - // case we override with the actual count, so we should return 0 items. - $offset = (($users) && ($request->get('offset') > $users->count())) ? $users->count() : $request->get('offset', 0); + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $users->count()) ? $users->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - // Check to make sure the limit is not higher than the max allowed - ((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results'); switch ($request->input('sort')) { diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index 53af19758..5fdc09bdb 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -29,26 +29,26 @@ class AssetSeeder extends Seeder $this->locationIds = Location::all()->pluck('id'); $this->supplierIds = Supplier::all()->pluck('id'); - Asset::factory()->count(1000)->laptopMbp()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(2000)->laptopMbp()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(50)->laptopMbpPending()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(50)->laptopMbpArchived()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(50)->laptopAir()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(5)->laptopSurface()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(50)->laptopSurface()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(5)->laptopXps()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(5)->laptopSpectre()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(5)->laptopZenbook()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(3)->laptopYoga()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(50)->laptopZenbook()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(30)->laptopYoga()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(30)->desktopMacpro()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(30)->desktopLenovoI5()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(30)->desktopOptiplex()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(5)->confPolycom()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(2)->confPolycomcx()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(12)->tabletIpad()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(4)->tabletTab3()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(50)->confPolycom()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(20)->confPolycomcx()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(30)->tabletIpad()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(10)->tabletTab3()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(27)->phoneIphone11()->state(new Sequence($this->getState()))->create(); Asset::factory()->count(40)->phoneIphone12()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(10)->ultrafine()->state(new Sequence($this->getState()))->create(); - Asset::factory()->count(10)->ultrasharp()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(20)->ultrafine()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(20)->ultrasharp()->state(new Sequence($this->getState()))->create(); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index 4c8bdcb62..c76bb02b5 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -32,7 +32,7 @@ return [ 'backups_restoring' => 'Restoring from Backup', 'backups_upload' => 'Upload Backup', 'backups_path' => 'Backups on the server are stored in :path', - 'backups_restore_warning' => 'Use the restore button to restore from a previous backup. (This does not currently work with S3 file storage or Docker.

Your entire :app_name database and any uploaded files will be completely replaced by what\'s in the backup file. ', + 'backups_restore_warning' => 'Use the restore button to restore from a previous backup. (This does not currently work with S3 file storage or Docker.)

Your entire :app_name database and any uploaded files will be completely replaced by what\'s in the backup file. ', 'backups_logged_out' => 'All existing users, including you, will be logged out once your restore is complete.', 'backups_large' => 'Very large backups may time out on the restore attempt and may still need to be run via command line. ', 'barcode_settings' => 'Barcode Settings',