A free open source IT asset/license management system
Merging master down into develop
snipe9db8bd782d6f
diff --git a/app/Console/Commands/KillAllSessions.php b/app/Console/Commands/KillAllSessions.phpnew file mode 100644index 0000000000..043be0fa18--- /dev/null+++ b/app/Console/Commands/KillAllSessions.php@@ -0,0 +1,59 @@+<?php++namespace App\Console\Commands;++use Illuminate\Console\Command;++class KillAllSessions extends Command+{+ /**+ * The name and signature of the console command.+ *+ * @var string+ */+ protected $signature = 'snipeit:global-logout {--force : Skip the danger prompt; assuming you enter "y"} ';++ /**+ * The console command description.+ *+ * @var string+ */+ protected $description = 'This command will destroy all web sessions on disk and will force a re-login for all users.';++ /**+ * Create a new command instance.+ *+ * @return void+ */+ public function __construct()+ {+ parent::__construct();+ }++ /**+ * Execute the console command.+ *+ * @return mixed+ */+ public function handle()+ {++ if (!$this->option('force') && !$this->confirm("****************************************************\nTHIS WILL FORCE A LOGIN FOR ALL LOGGED IN USERS.\n\nAre you SURE you wish to continue? ")) {+ return $this->error("Session loss not confirmed");+ }++ $session_files = glob(storage_path("framework/sessions/*"));++ $count = 0;+ foreach ($session_files as $file) {++ if (is_file($file))+ unlink($file);+ $count++;+ }+ \DB::table('users')->update(['remember_token' => null]);++ $this->info($count. ' sessions cleared!');++ }+}diff --git a/app/Console/Commands/RestoreFromBackup.php b/app/Console/Commands/RestoreFromBackup.phpindex 0ebda27d89..e780b35d69 100644--- a/app/Console/Commands/RestoreFromBackup.php+++ b/app/Console/Commands/RestoreFromBackup.php@@ -82,6 +82,7 @@ class RestoreFromBackup extends Commandreturn $this->error('Could not access file: '.$filename.' - '.array_key_exists($errcode, $errors) ? $errors[$errcode] : " Unknown reason: $errcode");}+$private_dirs = ['storage/private_uploads/assets', // these are asset _files_, not the pictures.'storage/private_uploads/audits',@@ -256,7 +257,6 @@ class RestoreFromBackup extends Command$this->info($stderr);return false;- }}if (!feof($sql_contents) || $bytes_read == 0) {return $this->error("Not at end of file for sql file, or zero bytes read. aborting!");diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.phpindex 2125d1f6ba..c5063eb598 100755--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@ -235,6 +235,7 @@ class AssetsController extends Controller->with('statuslabel_types', Helper::statusTypeList());}+/*** Returns a view that presents information about an asset for detail view.*@@ -309,6 +310,7 @@ class AssetsController extends Controller$asset->location_id = $request->input('rtd_location_id', null);}+if ($request->filled('image_delete')) {try {unlink(public_path().'/uploads/assets/'.$asset->image);@@ -401,6 +403,24 @@ class AssetsController extends Controllerreturn redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.delete.success'));}+ /**+ * Searches the assets table by serial, and redirects if it finds one+ *+ * @author [A. Gianotto] [<[email protected]>]+ * @since [v3.0]+ * @return Redirect+ */+ public function getAssetBySerial(Request $request)+ {+ $topsearch = ($request->get('topsearch')=="true");++ if (!$asset = Asset::where('serial', '=', $request->get('serial'))->first()) {+ return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));+ }+ $this->authorize('view', $asset);+ return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch);+ }+/*** Searches the assets table by asset tag, and redirects if it finds one*@@ -420,6 +440,7 @@ class AssetsController extends Controllerreturn redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch);}+/*** Return a QR code for the asset*@@ -792,6 +813,7 @@ class AssetsController extends Controllerreturn view('hardware/audit-overdue');}+public function auditStore(Request $request, $id){$this->authorize('audit', Asset::class);@@ -822,6 +844,7 @@ class AssetsController extends Controller$asset->location_id = $request->input('location_id');}+if ($asset->save()) {$file_name = '';// Upload an image, if attacheddiff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.phpindex 5bcf6fd8e6..742c8013d9 100644--- a/app/Http/Transformers/AssetsTransformer.php+++ b/app/Http/Transformers/AssetsTransformer.php@@ -4,6 +4,7 @@ namespace App\Http\Transformers;use App\Helpers\Helper;use App\Models\Asset;+use App\Models\Setting;use Gate;use Illuminate\Database\Eloquent\Collection;@@ -21,6 +22,9 @@ class AssetsTransformerpublic function transformAsset(Asset $asset){+ // This uses the getSettings() method so we're pulling from the cache versus querying the settings on single asset+ $setting = Setting::getSettings();+$array = ['id' => (int) $asset->id,'name' => e($asset->name),@@ -65,6 +69,8 @@ class AssetsTransformer'name'=> e($asset->defaultLoc->name),] : null,'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,+ 'qr' => ($setting->qr_code=='1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,+ 'alt_barcode' => ($setting->alt_barcode_enabled=='1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,'assigned_to' => $this->transformAssignedTo($asset),'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.phpindex c68a90a2bb..358164313f 100644--- a/app/Importer/LicenseImporter.php+++ b/app/Importer/LicenseImporter.php@@ -48,9 +48,9 @@ class LicenseImporter extends ItemImporter}$asset_tag = $this->item['asset_tag'] = $this->findCsvMatch($row, 'asset_tag'); // used for checkout out to an asset.- $this->item['expiration_date'] = null;- if ($this->findCsvMatch($row, 'expiration_date') != '') {- $this->item['expiration_date'] = date('Y-m-d 00:00:01', strtotime($this->findCsvMatch($row, 'expiration_date')));+ $this->item["expiration_date"] = null;+ if ($this->findCsvMatch($row, "expiration_date")!='') {+ $this->item["expiration_date"] = date("Y-m-d 00:00:01", strtotime($this->findCsvMatch($row, "expiration_date")));}$this->item['license_email'] = $this->findCsvMatch($row, 'license_email');$this->item['license_name'] = $this->findCsvMatch($row, 'license_name');@@ -59,9 +59,9 @@ class LicenseImporter extends ItemImporter$this->item['reassignable'] = $this->findCsvMatch($row, 'reassignable');$this->item['seats'] = $this->findCsvMatch($row, 'seats');- $this->item['termination_date'] = null;- if ($this->findCsvMatch($row, 'termination_date') != '') {- $this->item['termination_date'] = date('Y-m-d 00:00:01', strtotime($this->findCsvMatch($row, 'termination_date')));+ $this->item["termination_date"] = null;+ if ($this->findCsvMatch($row, "termination_date")!='') {+ $this->item["termination_date"] = date("Y-m-d 00:00:01", strtotime($this->findCsvMatch($row, "termination_date")));}if ($editingLicense) {diff --git a/database/migrations/2018_07_28_023826_create_checkout_acceptances_table.php b/database/migrations/2018_07_28_023826_create_checkout_acceptances_table.phpindex adc9477b37..7f0d2d3c01 100644--- a/database/migrations/2018_07_28_023826_create_checkout_acceptances_table.php+++ b/database/migrations/2018_07_28_023826_create_checkout_acceptances_table.php@@ -13,20 +13,22 @@ class CreateCheckoutAcceptancesTable extends Migration*/public function up(){- Schema::create('checkout_acceptances', function (Blueprint $table) {- $table->increments('id');+ if (!Schema::hasTable('checkout_acceptances')) {+ Schema::create('checkout_acceptances', function (Blueprint $table) {+ $table->increments('id');- $table->morphs('checkoutable');- $table->integer('assigned_to_id')->nullable();+ $table->morphs('checkoutable');+ $table->integer('assigned_to_id')->nullable();- $table->string('signature_filename')->nullable();+ $table->string('signature_filename')->nullable();- $table->timestamp('accepted_at')->nullable();- $table->timestamp('declined_at')->nullable();+ $table->timestamp('accepted_at')->nullable();+ $table->timestamp('declined_at')->nullable();- $table->timestamps();- $table->softDeletes();- });+ $table->timestamps();+ $table->softDeletes();+ });+ }}/**@@ -36,6 +38,8 @@ class CreateCheckoutAcceptancesTable extends Migration*/public function down(){- Schema::dropIfExists('checkout_acceptances');+ if (Schema::hasTable('checkout_acceptances')) {+ Schema::dropIfExists('checkout_acceptances');+ }}}diff --git a/database/migrations/2018_10_18_191228_add_kits_licenses_table.php b/database/migrations/2018_10_18_191228_add_kits_licenses_table.phpindex 4942942121..470f67803c 100644--- a/database/migrations/2018_10_18_191228_add_kits_licenses_table.php+++ b/database/migrations/2018_10_18_191228_add_kits_licenses_table.php@@ -1,7 +1,9 @@<?php-use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;+use Illuminate\Support\Facades\Schema;+class AddKitsLicensesTable extends Migration{@@ -12,15 +14,16 @@ class AddKitsLicensesTable extends Migration*/public function up(){- //- Schema::create('kits_licenses', function ($table) {- $table->increments('id');- $table->integer('kit_id')->nullable()->default(null);- $table->integer('license_id')->nullable()->default(null);- $table->integer('quantity')->default(1);- $table->timestamps();- });- }+ if (!Schema::hasTable('kits_licenses')) {+ Schema::create('kits_licenses', function ($table) {+ $table->increments('id');+ $table->integer('kit_id')->nullable()->default(null);+ $table->integer('license_id')->nullable()->default(null);+ $table->integer('quantity')->default(1);+ $table->timestamps();+ });+ }+ }/*** Reverse the migrations.@@ -29,7 +32,9 @@ class AddKitsLicensesTable extends Migration*/public function down(){- //- Schema::drop('kits_licenses');- }+ if (Schema::hasTable('kits_licenses')) {+ Schema::drop('kits_licenses');+ }+ }+}diff --git a/database/migrations/2018_10_19_153910_add_kits_table.php b/database/migrations/2018_10_19_153910_add_kits_table.phpindex 04e9290aba..fbc683f180 100644--- a/database/migrations/2018_10_19_153910_add_kits_table.php+++ b/database/migrations/2018_10_19_153910_add_kits_table.php@@ -1,7 +1,8 @@<?php-use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;+use Illuminate\Support\Facades\Schema;class AddKitsTable extends Migration{@@ -12,14 +13,16 @@ class AddKitsTable extends Migration*/public function up(){- //- Schema::create('kits', function ($table) {- $table->increments('id');- $table->string('name')->nullable()->default(null);- $table->timestamps();- $table->engine = 'InnoDB';- });- }+ if (!Schema::hasTable('kits')) {+ Schema::create('kits', function ($table) {+ $table->increments('id');+ $table->string('name')->nullable()->default(null);+ $table->timestamps();+ $table->engine = 'InnoDB';+ });+ }++ }/*** Reverse the migrations.@@ -28,7 +31,9 @@ class AddKitsTable extends Migration*/public function down(){- //- Schema::drop('kits');- }+ if (Schema::hasTable('kits')) {+ Schema::drop('kits');+ }+ }+}diff --git a/database/migrations/2018_10_19_154013_add_kits_models_table.php b/database/migrations/2018_10_19_154013_add_kits_models_table.phpindex 0f62dd45ef..3b5224c6bc 100644--- a/database/migrations/2018_10_19_154013_add_kits_models_table.php+++ b/database/migrations/2018_10_19_154013_add_kits_models_table.php@@ -1,7 +1,9 @@<?php-use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;+use Illuminate\Support\Facades\Schema;+class AddKitsModelsTable extends Migration{@@ -12,15 +14,16 @@ class AddKitsModelsTable extends Migration*/public function up(){- //- Schema::create('kits_models', function ($table) {- $table->increments('id');- $table->integer('kit_id')->nullable()->default(null);- $table->integer('model_id')->nullable()->default(null);- $table->integer('quantity')->default(1);- $table->timestamps();- });- }+ if (!Schema::hasTable('kits_models')) {+ Schema::create('kits_models', function ($table) {+ $table->increments('id');+ $table->integer('kit_id')->nullable()->default(null);+ $table->integer('model_id')->nullable()->default(null);+ $table->integer('quantity')->default(1);+ $table->timestamps();+ });+ }+ }/*** Reverse the migrations.@@ -29,7 +32,8 @@ class AddKitsModelsTable extends Migration*/public function down(){- //- Schema::drop('kits_models');+ if (Schema::hasTable('kits_models')) {+ Schema::drop('kits_models');+ }}}diff --git a/database/migrations/2019_02_07_185953_add_kits_consumables_table.php b/database/migrations/2019_02_07_185953_add_kits_consumables_table.phpindex c1fb46c23e..34fbb3539b 100644--- a/database/migrations/2019_02_07_185953_add_kits_consumables_table.php+++ b/database/migrations/2019_02_07_185953_add_kits_consumables_table.php@@ -1,8 +1,8 @@<?php-use Illuminate\Database\Migrations\Migration;-use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;class AddKitsConsumablesTable extends Migration{@@ -13,14 +13,15 @@ class AddKitsConsumablesTable extends Migration*/public function up(){- //- Schema::create('kits_consumables', function ($table) {- $table->increments('id');- $table->integer('kit_id')->nullable()->default(null);- $table->integer('consumable_id')->nullable()->default(null);- $table->integer('quantity')->default(1);- $table->timestamps();- });+ if (!Schema::hasTable('kits_consumables')) {+ Schema::create('kits_consumables', function ($table) {+ $table->increments('id');+ $table->integer('kit_id')->nullable()->default(null);+ $table->integer('consumable_id')->nullable()->default(null);+ $table->integer('quantity')->default(1);+ $table->timestamps();+ });+ }}/**@@ -30,7 +31,8 @@ class AddKitsConsumablesTable extends Migration*/public function down(){- //- Schema::drop('kits_consumables');+ if (Schema::hasTable('kits_consumables')) {+ Schema::drop('kits_consumables');+ }}}diff --git a/database/migrations/2019_02_07_190030_add_kits_accessories_table.php b/database/migrations/2019_02_07_190030_add_kits_accessories_table.phpindex 12e20beba2..1a4e14af94 100644--- a/database/migrations/2019_02_07_190030_add_kits_accessories_table.php+++ b/database/migrations/2019_02_07_190030_add_kits_accessories_table.php@@ -1,8 +1,8 @@<?php-use Illuminate\Database\Migrations\Migration;-use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;class AddKitsAccessoriesTable extends Migration{@@ -13,14 +13,15 @@ class AddKitsAccessoriesTable extends Migration*/public function up(){- //- Schema::create('kits_accessories', function ($table) {- $table->increments('id');- $table->integer('kit_id')->nullable()->default(null);- $table->integer('accessory_id')->nullable()->default(null);- $table->integer('quantity')->default(1);- $table->timestamps();- });+ if (!Schema::hasTable('kits_accessories')) {+ Schema::create('kits_accessories', function ($table) {+ $table->increments('id');+ $table->integer('kit_id')->nullable()->default(null);+ $table->integer('accessory_id')->nullable()->default(null);+ $table->integer('quantity')->default(1);+ $table->timestamps();+ });+ }}/**@@ -30,7 +31,8 @@ class AddKitsAccessoriesTable extends Migration*/public function down(){- //- Schema::drop('kits_accessories');+ if (Schema::hasTable('kits_accessories')) {+ Schema::drop('kits_accessories');+ }}}diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.phpindex d7b948604e..7bc948960b 100755--- a/resources/views/hardware/view.blade.php+++ b/resources/views/hardware/view.blade.php@@ -459,6 +459,7 @@@else{!! nl2br(e($asset->{$field->db_column_name()})) !!} @endif+@endif</div></div>diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex 5c638735f6..72927026ae 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -53,7 +53,7 @@paginationLastText: "{{ trans('general.last') }}",paginationPreText: "{{ trans('general.previous') }}",paginationNextText: "{{ trans('general.next') }}",- pageList: ['10','20', '30','50','100','150','200', '500', '1000'],+ pageList: ['10','20', '30','50','100','150','200'{!! ((config('app.max_results') > 200) ? ",'500'" : '') !!}{!! ((config('app.max_results') > 500) ? ",'".config('app.max_results')."'" : '') !!}],pageSize: {{ (($snipeSettings->per_page!='') && ($snipeSettings->per_page > 0)) ? $snipeSettings->per_page : 20 }},paginationVAlign: 'both',queryParams: function (params) {