From 282b3b5b0a4903172bb6d7f6902ad2f5e28e3c4f Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 6 Oct 2017 18:41:10 -0700 Subject: [PATCH 1/3] =?UTF-8?q?Remove=20catch-all=20=E2=80=9Cdeployed?= =?UTF-8?q?=E2=80=9D=20from=20pie=20chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/StatuslabelsController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index a5f9e23073..045d587bdf 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -168,9 +168,7 @@ class StatuslabelsController extends Controller } } } - $labels[]='Deployed'; - $points[]=Asset::whereNotNull('assigned_to')->count(); - + $colors_array = array_merge($colors, Helper::chartColors()); $result= [ From a84da88114a0777ecef98fd8e6f695464b8682b1 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 6 Oct 2017 22:58:00 -0700 Subject: [PATCH 2/3] Demo seeder --- app/Console/Commands/DemoData.php | 1107 +++++++++++++++++++++++++++++ app/Console/Kernel.php | 3 +- 2 files changed, 1109 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/DemoData.php diff --git a/app/Console/Commands/DemoData.php b/app/Console/Commands/DemoData.php new file mode 100644 index 0000000000..b0597a6631 --- /dev/null +++ b/app/Console/Commands/DemoData.php @@ -0,0 +1,1107 @@ +error('This action cannot be performed on a production system.'); + $this->info('If you wish to reset a production system, please put your'); + $this->info('app into develop mode. This is for your protection.'); + return false; + } + + if ($this->confirm("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n This will overwrite your existing database. Do you wish to continue?")) { + + + $this->dropRealCustomFieldsColumns(); + $this->dropAndCreateCategories(); + $this->dropAndCreateManufacturers(); + $this->dropAndCreateLocations(); + $this->dropAndCreateActionlogs(); + $this->dropAndCreateAssetModels(); + $this->dropAndCreateStatusLabels(); + $this->dropAndCreateAssets(); + $this->dropAndCreateDepreciations(); + $this->dropAndCreateSuppliers(); + $this->dropAndCreateAccessories(); + $this->dropAndCreateLicenses(); + $this->dropAndCreateComponents(); + $this->dropAndCreateConsumables(); + + + Import::truncate(); + AssetMaintenance::truncate(); + Group::truncate(); + Company::truncate(); + CustomField::truncate(); + Group::truncate(); + CustomFieldset::truncate(); + Department::truncate(); + User::where('username', '!=', 'snipe') + ->where('username', '!=', 'admin') + ->forceDelete(); + DB::table('custom_field_custom_fieldset')->truncate(); + DB::table('checkout_requests')->truncate(); + + + } + + + } + + + public function dropAndCreateAssets() { + + Asset::truncate(); + + $assets = [ + + // Assets + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Brady Laptop', + 'model_id' => 1, + 'assigned_to' => null, + 'assigned_type' => null, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000341' + ], + + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Alison Laptop', + 'model_id' => 1, + 'assigned_to' => null, + 'assigned_type' => null, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000342' + ], + + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Frontdesk Laptop', + 'model_id' => 1, + 'assigned_to' => null, + 'assigned_type' => null, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 2, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000343' + ], + + [ + 'id' => 4, + 'user_id' => 1, + 'name' => null, + 'model_id' => 2, + 'assigned_to' => 1, + 'assigned_type' => User::class, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000344' + ], + [ + 'id' => 5, + 'user_id' => 1, + 'name' => null, + 'model_id' => 3, + 'assigned_to' => 1, + 'assigned_type' => User::class, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000345' + ], + [ + 'id' => 6, + 'user_id' => 1, + 'name' => 'Backroom Desktop', + 'model_id' => 3, + 'assigned_to' => 2, + 'assigned_type' => Location::class, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000346' + ], + [ + 'id' => 7, + 'user_id' => 1, + 'name' => 'Lobby Laptop', + 'model_id' => 4, + 'assigned_to' => 2, + 'assigned_type' => Location::class, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000347' + ], + + [ + 'id' => 8, + 'user_id' => 1, + 'name' => 'Conference Room A Polycom', + 'model_id' => 11, + 'assigned_to' => 2, + 'assigned_type' => Location::class, + 'purchase_cost' => '3025.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000348' + ], + + [ + 'id' => 9, + 'user_id' => 1, + 'name' => null, + 'model_id' => 12, + 'assigned_to' => null, + 'assigned_type' => null, + 'purchase_cost' => '799.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000349' + ], + [ + 'id' => 10, + 'user_id' => 1, + 'name' => null, + 'model_id' => 13, + 'assigned_to' => 1, + 'assigned_type' => User::class, + 'purchase_cost' => '799.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000310' + ], + [ + 'id' => 11, + 'user_id' => 1, + 'name' => null, + 'model_id' => 14, + 'assigned_to' => null, + 'assigned_type' => null, + 'purchase_cost' => '899.56', + 'purchase_date' => date('Y-m-d'), + 'supplier_id' => rand(1,4), + 'status_id' => 1, + 'rtd_location_id' => rand(1,4), + 'serial' => self::generateRandomString(), + 'asset_tag' => '1000311' + ], + + + ]; + + // Create assets + DB::table('assets')->insert($assets); + return $assets; + + } + + public function dropAndCreateManufacturers() { + + Manufacturer::truncate(); + + $manufacturers = [ + + // Asset Manufacturers + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Apple', + ], + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Microsoft', + ], + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Dell', + ], + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Asus', + ], + [ + 'id' => 5, + 'user_id' => 1, + 'name' => 'HP', + ], + [ + 'id' => 6, + 'user_id' => 1, + 'name' => 'Lenovo', + ], + [ + 'id' => 7, + 'user_id' => 1, + 'name' => 'LG', + ], + [ + 'id' => 8, + 'user_id' => 1, + 'name' => 'Polycom', + ], + [ + 'id' => 9, + 'user_id' => 1, + 'name' => 'Adobe', + ], + + ]; + + // Create Manufacturers + DB::table('manufacturers')->insert($manufacturers); + return $manufacturers; + + } + + + public function dropAndCreateSuppliers() { + + Supplier::truncate(); + + $supppliers = [ + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Best Buy', + ], + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Frys', + ], + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'New Egg', + ], + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Mikes Tech Shop', + ], + ]; + + // Create Depreciations + DB::table('suppliers')->insert($supppliers); + return $supppliers; + } + + + public function dropAndCreateDepreciations() { + + Depreciation::truncate(); + + $depreciations = [ + [ + 'id' => 1, + 'months' => 36, + 'user_id' => 1, + 'name' => 'Computers Depreciation', + ], + [ + 'id' => 2, + 'months' => 24, + 'user_id' => 1, + 'name' => 'Mobile Phone Depreciation', + ], + ]; + + // Create Depreciations + DB::table('depreciations')->insert($depreciations); + return $depreciations; + } + + + public function dropAndCreateAssetModels() { + + AssetModel::truncate(); + + $models = [ + + // Asset models + [ + 'id' => 1, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'Macbook Pro Retina 13"', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + + [ + 'id' => 2, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'Macbook Air', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 3, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 1, + 'category_id' => 2, + 'name' => 'iMac Pro', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 4, + 'user_id' => 1, + 'manufacturer_id' => 2, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'Surface Pro', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 5, + 'user_id' => 1, + 'manufacturer_id' => 3, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'XPS 13', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 6, + 'user_id' => 1, + 'manufacturer_id' => 4, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'ZenBook UX310', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 7, + 'user_id' => 1, + 'manufacturer_id' => 5, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'Spectre', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 8, + 'user_id' => 1, + 'manufacturer_id' => 6, + 'depreciation_id' => 1, + 'category_id' => 1, + 'name' => 'Yoga 910', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 9, + 'user_id' => 1, + 'manufacturer_id' => 7, + 'depreciation_id' => 1, + 'category_id' => 4, + 'name' => '4G Ultrafine', + 'eol' => 24, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 10, + 'user_id' => 1, + 'manufacturer_id' => 5, + 'depreciation_id' => 1, + 'category_id' => 4, + 'name' => '20.7" LED FHD Monitor - Black', + 'eol' => 24, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 11, + 'user_id' => 1, + 'manufacturer_id' => 8, + 'depreciation_id' => 1, + 'category_id' => 7, + 'name' => 'Soundstation 2', + 'eol' => 24, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 12, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 2, + 'category_id' => 3, + 'name' => 'iPhone 6S', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 13, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 2, + 'category_id' => 5, + 'name' => 'iPad Pro', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + [ + 'id' => 14, + 'user_id' => 1, + 'manufacturer_id' => 1, + 'depreciation_id' => 2, + 'category_id' => 3, + 'name' => 'iPhone 7', + 'eol' => 36, + 'notes' => 'Created by demo seeder', + 'model_number' => rand(111111,99999) + ], + + ]; + + // Create Models + DB::table('models')->insert($models); + return $models; + } + public function dropAndCreateCategories() { + + Category::truncate(); + $categories = [ + + [ + 'id' => 1, + 'name' => 'Laptops', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 2, + 'name' => 'Desktops', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 3, + 'name' => 'Mobile Phones', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 4, + 'name' => 'Displays', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 5, + 'name' => 'Tablets', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 6, + 'name' => 'VOIP Phones', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 7, + 'name' => 'Conference Phones', + 'category_type' => 'asset', + 'require_acceptance' => rand(0,1) + ], + + // Accessory categories: 8-9 + [ + 'id' => 8, + 'name' => 'Keyboard', + 'category_type' => 'accessory', + 'require_acceptance' => rand(0,1) + ], + + [ + 'id' => 9, + 'name' => 'Mouse', + 'category_type' => 'accessory', + 'require_acceptance' => rand(0,1) + ], + [ + 'id' => 10, + 'name' => 'Printer Paper', + 'category_type' => 'consumable', + 'require_acceptance' => 0, + ], + [ + 'id' => 11, + 'name' => 'Printer Toner', + 'category_type' => 'consumable', + 'require_acceptance' => 0, + ], + [ + 'id' => 12, + 'name' => 'RAM', + 'category_type' => 'component', + 'require_acceptance' => 0, + ], + [ + 'id' => 13, + 'name' => 'Hard Drives', + 'category_type' => 'component', + 'require_acceptance' => 0, + ], + + + ]; + + + // Create Categories + DB::table('categories')->insert($categories); + return $categories; + } + + public function dropAndCreateLocations() { + + Location::truncate(); + + $locations = [ + + // Locations + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'San Diego HQ', + ], + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Ocean Beach HQ', + ], + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Point Loma HQ', + ], + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Pacific Beach HQ', + ], + ]; + + // Create Locations + DB::table('locations')->insert($locations); + return $locations; + + } + + public function dropAndCreateLicenses() { + + License::truncate(); + LicenseSeat::truncate(); + + $licenses = [ + + // Licenses + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Adobe Acrobat Pro', + 'serial' => self::generateRandomString(), + 'purchase_cost' => '99.99', + 'license_name' => 'Alison Gianotto', + 'license_email' => 'foo@example.com', + 'depreciate' => 0, + 'supplier_id' => 1, + 'manufacturer_id' => 9, + 'seats' => rand(2,20), + ], + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Adobe Photoshop', + 'serial' => self::generateRandomString(), + 'purchase_cost' => '299.99', + 'license_name' => 'Alison Gianotto', + 'license_email' => 'foo@example.com', + 'depreciate' => 0, + 'supplier_id' => 1, + 'manufacturer_id' => 9, + 'seats' => rand(2,20), + ], + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Garageband', + 'serial' => self::generateRandomString(), + 'purchase_cost' => '39.99', + 'license_name' => 'Alison Gianotto', + 'license_email' => 'foo@example.com', + 'depreciate' => 0, + 'supplier_id' => 1, + 'manufacturer_id' => 1, + 'seats' => rand(2,20), + ], + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Office', + 'serial' => self::generateRandomString(), + 'purchase_cost' => '39.99', + 'license_name' => 'Alison Gianotto', + 'license_email' => 'foo@example.com', + 'depreciate' => 0, + 'supplier_id' => 1, + 'manufacturer_id' => 2, + 'seats' => rand(2,20), + ], + + ]; + + // Create Licenses + DB::table('licenses')->insert($licenses); + + foreach ($licenses as $license) { + $license_seats = + [ + 'license_id' => $license['id'], + 'notes' => 'Created by demo seeder', + 'user_id' => 1 + ]; + + for ($x=0; $x < $license['seats']; $x++) { + DB::table('license_seats')->insert($license_seats); + } + + + } + return $licenses; + + } + + public function dropAndCreateAccessories() { + + Accessory::truncate(); + DB::table('accessories_users')->truncate(); + + + $accessories = [ + + // Accessories + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Bluetooth Keyboard', + 'category_id' => 8, + 'manufacturer_id' => 1, + 'location_id' => 1, + 'model_number' => rand(123,12345677), + 'purchase_cost' => '99.99', + 'qty' => 10, + 'min_amt' => 2, + ], + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'USB Keyboard', + 'category_id' => 8, + 'manufacturer_id' => 1, + 'location_id' => 1, + 'model_number' => rand(123,12345677), + 'purchase_cost' => '69.99', + 'qty' => 5, + 'min_amt' => 1, + ], + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Magic Mouse 2', + 'category_id' => 9, + 'manufacturer_id' => 1, + 'location_id' => 2, + 'model_number' => rand(123,12345677), + 'purchase_cost' => '59.99', + 'qty' => 15, + 'min_amt' => 2, + ], + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Sculpt Comfort Mouse', + 'category_id' => 9, + 'manufacturer_id' => 2, + 'location_id' => 3, + 'model_number' => rand(123,12345677), + 'purchase_cost' => '24.99', + 'qty' => 10, + 'min_amt' => 2, + ], + ]; + + // Create Locations + DB::table('accessories')->insert($accessories); + return $accessories; + + } + + + + public function dropAndCreateComponents() { + + Component::truncate(); + DB::table('components_assets')->truncate(); + + $components = [ + + // Components + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Seagate 1TB', + 'category_id' => 12, + 'location_id' => 1, + 'purchase_cost' => '99.99', + 'qty' => 10, + 'min_amt' => 2, + ], + + ]; + + // Create Locations + DB::table('components')->insert($components); + return $components; + + } + + + public function dropAndCreateConsumables() { + + Consumable::truncate(); + DB::table('consumables_users')->truncate(); + + $consumables = [ + + // Consumables + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'Bone White Cardstock', + 'category_id' => 10, + 'location_id' => 1, + 'purchase_cost' => '29.99', + 'qty' => 10, + 'min_amt' => 2, + ], + + + ]; + + // Create Locations + DB::table('consumables')->insert($consumables); + return $consumables; + + } + + + public function dropAndCreateActionlogs() { + + Actionlog::truncate(); + + $action_logs = [ + + // Action logs + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 1, + 'target_type' => User::class, + 'item_type' => Asset::class, + 'item_id' => 4, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 1, + 'target_type' => User::class, + 'item_type' => Asset::class, + 'item_id' => 5, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 2, + 'target_type' => Location::class, + 'item_type' => Asset::class, + 'item_id' => 5, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 2, + 'target_type' => Location::class, + 'item_type' => Asset::class, + 'item_id' => 7, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 2, + 'target_type' => Location::class, + 'item_type' => Asset::class, + 'item_id' => 8, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkin from', + 'target_id' => 2, + 'target_type' => Location::class, + 'item_type' => Asset::class, + 'item_id' => 8, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + [ + 'user_id' => 1, + 'action_type' => 'checkout', + 'target_id' => 2, + 'target_type' => Location::class, + 'item_type' => Asset::class, + 'item_id' => 8, + 'created_at' => date('Y-m-d'), + 'note' => 'Created by demo seeder', + ], + + ]; + + // Create Logs + DB::table('action_logs')->insert($action_logs); + return $action_logs; + } + + public function dropAndCreateStatusLabels() { + + Statuslabel::truncate(); + + $statuslabels = [ + + // Status Labels + [ + 'id' => 1, + 'user_id' => 1, + 'name' => 'New - Ready for Deployment', + 'deployable' => 1, + 'pending' => 0, + 'archived' => 0, + 'notes' => 'Created by demo seeder', + + ], + + // Status Labels + [ + 'id' => 2, + 'user_id' => 1, + 'name' => 'Awaiting Repair', + 'deployable' => 0, + 'pending' => 1, + 'archived' => 0, + 'notes' => 'Created by demo seeder', + + ], + + // Status Labels + [ + 'id' => 3, + 'user_id' => 1, + 'name' => 'Archived - Keep for Records', + 'deployable' => 0, + 'pending' => 0, + 'archived' => 1, + 'notes' => 'Created by demo seeder', + + ], + + // Status Labels + [ + 'id' => 4, + 'user_id' => 1, + 'name' => 'Broken - Not Fixable', + 'deployable' => 0, + 'pending' => 0, + 'archived' => 1, + 'notes' => 'Created by demo seeder', + + ], + + + ]; + + // Create status labels + DB::table('status_labels')->insert($statuslabels); + return $statuslabels; + } + + public function dropRealCustomFieldsColumns() { + // delete custom field columns on the asset table + $fields = Customfield::all(); + foreach ($fields as $field) { + if ($field->db_column!='') { + $this->info('Dropping DB column: '.$field->db_column); + Schema::table('assets', function (Blueprint $table) { + $table->dropColumn($field->db_column); + }); + } + } + } + + public function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d6de607fb8..5195a3cf35 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -25,7 +25,8 @@ class Kernel extends ConsoleKernel Commands\Purge::class, Commands\LdapSync::class, Commands\FixDoubleEscape::class, - Commands\RecryptFromMcrypt::class + Commands\RecryptFromMcrypt::class, + Commands\DemoData::class ]; /** From fbea1c0823070eb899e8d5ed7628b71abf28a364 Mon Sep 17 00:00:00 2001 From: tiagom62 Date: Sat, 7 Oct 2017 01:58:41 -0400 Subject: [PATCH 3/3] Code dedupe, general cleanup and added a verbose option for debugging. (#4173) --- snipeit.sh | 329 +++++++++++++++++++---------------------------------- 1 file changed, 117 insertions(+), 212 deletions(-) diff --git a/snipeit.sh b/snipeit.sh index 4aa49078c5..78ab2cc925 100755 --- a/snipeit.sh +++ b/snipeit.sh @@ -8,7 +8,6 @@ # install process for Debian and CentOS # # based distributions. I assume you will be # # installing as a subdomain on a fresh OS install. # -# Right now I'm not going to worry about SMTP setup # # # # Feel free to modify, but please give # # credit where it's due. Thanks! # @@ -28,9 +27,9 @@ fi clear name="snipeit" +verbose="false" hostname="$(hostname)" fqdn="$(hostname --fqdn)" -ans=default hosts=/etc/hosts spin[0]="-" @@ -50,8 +49,7 @@ progress () { done } -#Used for Debian and Ubuntu -vhenvfile () { +setvhdebian () { find /etc/apache2/mods-enabled -maxdepth 1 -name 'rewrite.load' >/dev/null 2>&1 apachefile=/etc/apache2/sites-available/$name.conf { @@ -71,22 +69,37 @@ vhenvfile () { log "a2ensite $name.conf" } -perms () { - chmod_dirs=( "$webdir/$name/storage" ) - chmod_dirs+=( "$webdir/$name/storage/private_uploads" ) - chmod_dirs+=( "$webdir/$name/public/uploads" ) - #Change permissions on directories - for chmod_dir in "${chmod_dirs[@]}" - do - chmod -R 755 "$chmod_dir" - done +setvhcentos () { + apachefile=/etc/httpd/conf.d/$name.conf + { + echo "" + echo "ServerAdmin webmaster@localhost" + echo " " + echo " Allow From All" + echo " AllowOverride All" + echo " Options +Indexes" + echo " " + echo " DocumentRoot $webdir/$name/public" + echo " ServerName $fqdn" + echo " ErrorLog /var/log/httpd/snipeIT.error.log" + echo " CustomLog /var/log/access.log combined" + echo "" + } >> "$apachefile" } log () { - eval "$@" |& tee -a /var/log/snipeit-install.log >/dev/null 2>&1 + if [ "$verbose" = true ]; then + eval "$@" + else + eval "$@" |& tee -a /var/log/snipeit-install.log >/dev/null 2>&1 + fi } -setenv () { +installsnipeit () { + echo "* Cloning Snipe-IT from github to the web directory." + log "git clone https://github.com/snipe/snipe-it $webdir/$name" + + echo "* Configuring .env file." cp $webdir/$name/.env.example $webdir/$name/.env sed -i '1 i\#Created By Snipe-it Installer' $webdir/$name/.env @@ -96,12 +109,30 @@ setenv () { sed -i 's,^\(DB_USERNAME=\).*,\1'snipeit',' $webdir/$name/.env sed -i 's,^\(DB_PASSWORD=\).*,\1'$mysqluserpw',' $webdir/$name/.env sed -i 's,^\(APP_URL=\).*,\1'http://$fqdn',' $webdir/$name/.env -} -installcomposer () { - cd $webdir/$name/ - curl -sS https://getcomposer.org/installer | php - php composer.phar install --no-dev --prefer-source + echo "* Installing and running composer." + cd $webdir/$name/ + curl -sS https://getcomposer.org/installer | php + php composer.phar install --no-dev --prefer-source + + echo "* Setting permissions." + chmod_dirs=( "$webdir/$name/storage" ) + chmod_dirs+=( "$webdir/$name/storage/private_uploads" ) + chmod_dirs+=( "$webdir/$name/public/uploads" ) + for chmod_dir in "${chmod_dirs[@]}" + do + chmod -R 755 "$chmod_dir" + done + chown -R $ownergroup $webdir/$name + + echo "* Generating the application key." + log "php artisan key:generate --force" + + echo "* Artisan Migrate." + log "php artisan migrate --force" + + echo "* Creating scheduler cron." + (crontab -l ; echo "* * * * * /usr/bin/php $webdir/$name/artisan schedule:run >> /dev/null 2>&1") | crontab - } #CentOS Friendly f(x)s @@ -140,7 +171,7 @@ echo " " echo "" -echo " Welcome to Snipe-IT Inventory Installer for Centos, Debian and Ubuntu!" +echo " Welcome to Snipe-IT Inventory Installer for CentOS, Debian and Ubuntu!" echo "" shopt -s nocasematch case $distro in @@ -171,6 +202,7 @@ fi echo " Setting to $fqdn" echo "" +ans=default until [[ $ans == "yes" ]] || [[ $ans == "no" ]]; do echo -n " Q. Do you want to automatically create the database user password? (y/n) " read setpw @@ -201,6 +233,8 @@ case $distro in if [[ "$version" =~ ^9 ]]; then ##################################### Install for Debian 9 ############################################## webdir=/var/www + ownergroup=www-data:www-data + tzone=$(cat /etc/timezone) echo "* Updating with apt-get update." log "apt-get update" & pid=$! @@ -210,50 +244,31 @@ case $distro in log "apt-get -y upgrade" & pid=$! progress - echo "* Installing httpd, PHP, MariaDB and other requirements." + echo "* Installing Apache httpd, PHP, MariaDB and other requirements." log "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server mariadb-client apache2 libapache2-mod-php php php-mcrypt php-curl php-mysql php-gd php-ldap php-zip php-mbstring php-xml php-bcmath curl git unzip" & pid=$! progress log "a2enmod rewrite" - echo "* Cloning Snipe-IT from github to the web directory." - log "git clone https://github.com/snipe/snipe-it $webdir/$name" & pid=$! - progress - - echo "* Configuring .env file." - tzone=$(cat /etc/timezone) - setenv - echo "* Creating the new virtual host in Apache." - vhenvfile + setvhdebian echo >> $hosts "127.0.0.1 $hostname $fqdn" - a2ensite $name.conf - echo "* Securing MariaDB server."; + echo "* Securing MariaDB." /usr/bin/mysql_secure_installation echo "* Creating MariaDB Database/User." echo "* Please Input your MariaDB root password:" mysql -u root -p --execute="CREATE DATABASE snipeit;GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost IDENTIFIED BY '$mysqluserpw';" - echo "* Installing and running composer." - installcomposer + installsnipeit - echo "* Setting permissions." - perms - chown -R www-data:www-data "/var/www/$name" - - service apache2 restart - - echo "* Generating the application key." - php artisan key:generate --force - - echo "* Artisan Migrate." - php artisan migrate --force + echo "* Restarting Apache httpd." + log "service apache2 restart" else - echo "Unable to Handle Debian Version #. Version Found: " $version + echo "Unsupported Debian version. Version found: " $version return 1 fi ;; @@ -261,6 +276,8 @@ case $distro in if [[ "$version" =~ 1[6-7] ]]; then ##################################### Install for Ubuntu 16-17 ############################################## webdir=/var/www + ownergroup=www-data:www-data + tzone=$(cat /etc/timezone) echo "* Adding MariaDB repository." log "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8" @@ -268,14 +285,15 @@ case $distro in echo "* Updating with apt-get update." log "apt-get update" & pid=$! - [ -f /var/lib/dpkg/lock ] && rm -f /var/lib/dpkg/lock + #https://wiki.debian.org/Teams/Dpkg/FAQ#Q:_What_can_be_done_when_the_dpkg_lock_is_held.3F + #[ -f /var/lib/dpkg/lock ] && rm -f /var/lib/dpkg/lock progress echo "* Upgrading packages with apt-get upgrade." log "apt-get -y upgrade" & pid=$! progress - echo "* Installing httpd, PHP, MariaDB and other requirements." + echo "* Installing Apache httpd, PHP, MariaDB and other requirements." log "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server mariadb-client apache2 libapache2-mod-php php php-mcrypt php-curl php-mysql php-gd php-ldap php-zip php-mbstring php-xml php-bcmath curl git unzip" & pid=$! progress @@ -283,45 +301,29 @@ case $distro in log "phpenmod mbstring" log "a2enmod rewrite" - echo "* Cloning Snipe-IT from github to the web directory." - log "git clone https://github.com/snipe/snipe-it $webdir/$name" & pid=$! - progress - - echo "* Configuring .env file." - tzone=$(cat /etc/timezone) - setenv - echo "* Creating the new virtual host in Apache." - vhenvfile + setvhdebian - echo "* Starting the MariaDB server."; - service mysql status >/dev/null || service mysql start + echo "* Starting MariaDB." + log "service mysql start" - echo "* Securing MariaDB server."; + echo "* Securing MariaDB." /usr/bin/mysql_secure_installation echo "* Creating MariaDB Database/User." echo "* Please Input your MariaDB root password:" mysql -u root -p --execute="CREATE DATABASE snipeit;GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost IDENTIFIED BY '$mysqluserpw';" - echo "* Installing and running composer." - installcomposer + installsnipeit - echo "* Setting permissions." - perms - chown -R www-data:www-data "/var/www/$name" - - service apache2 restart - - echo "* Generating the application key." - php artisan key:generate --force - - echo "* Artisan Migrate." - php artisan migrate --force + echo "* Restarting Apache httpd." + log "service apache2 restart" elif [[ "$version" =~ 14 ]]; then ##################################### Install for Ubuntu 14 ############################################## webdir=/var/www + ownergroup=www-data:www-data + tzone=$(cat /etc/timezone) echo "* Adding MariaDB and ppa:ondrej/php repositories." log "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db" @@ -331,14 +333,15 @@ case $distro in echo "* Updating with apt-get update." log "apt-get update" & pid=$! - [ -f /var/lib/dpkg/lock ] && rm -f /var/lib/dpkg/lock + #https://wiki.debian.org/Teams/Dpkg/FAQ#Q:_What_can_be_done_when_the_dpkg_lock_is_held.3F + #[ -f /var/lib/dpkg/lock ] && rm -f /var/lib/dpkg/lock progress echo "* Upgrading packages with apt-get upgrade." log "apt-get -y upgrade" & pid=$! progress - echo "* Installing httpd, PHP, MariaDB and other requirements." + echo "* Installing Apache httpd, PHP, MariaDB and other requirements." log "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server mariadb-client php7.1 php7.1-mcrypt php7.1-curl php7.1-mysql php7.1-gd php7.1-ldap php7.1-zip php7.1-mbstring php7.1-xml php7.1-bcmath curl git unzip" & pid=$! progress @@ -346,53 +349,37 @@ case $distro in log "phpenmod mbstring" log "a2enmod rewrite" - echo "* Cloning Snipe-IT from github to the web directory." - log "git clone https://github.com/snipe/snipe-it $webdir/$name" & pid=$! - progress - - echo "* Configuring .env file." - tzone=$(cat /etc/timezone) - setenv - echo "* Creating the new virtual host in Apache." - vhenvfile + setvhdebian - echo "* Starting the MariaDB server."; - service mysql status >/dev/null || service mysql start + echo "* Starting MariaDB." + log "service mysql start" - echo "* Securing MariaDB server."; + echo "* Securing MariaDB." /usr/bin/mysql_secure_installation echo "* Creating MariaDB Database/User." echo "* Please Input your MariaDB root password:" mysql -u root -p --execute="CREATE DATABASE snipeit;GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost IDENTIFIED BY '$mysqluserpw';" - echo "* Installing and running composer." - installcomposer + installsnipeit - echo "* Setting permissions." - perms - chown -R www-data:www-data "/var/www/$name" - - service apache2 restart - - echo "* Generating the application key." - php artisan key:generate --force - - echo "* Artisan Migrate." - php artisan migrate --force + echo "* Restarting Apache httpd." + log "service apache2 restart" else - echo "Unable to Handle Ubuntu Version #. Version Found: " $version + echo "Unsupported Ubuntu version. Version found: " $version return 1 fi ;; centos) if [[ "$version" =~ ^6 ]]; then - ##################################### Install for Centos/Redhat 6 ############################################## + ##################################### Install for CentOS/Redhat 6 ############################################## webdir=/var/www/html + ownergroup=apache:apache + tzone=$(grep ZONE /etc/sysconfig/clock | tr -d '"' | sed 's/ZONE=//g'); - echo "* Adding IUS, epel-release and MariaDB repositories."; + echo "* Adding IUS, epel-release and MariaDB repositories." mariadbRepo=/etc/yum.repos.d/MariaDB.repo touch "$mariadbRepo" { @@ -408,7 +395,7 @@ case $distro in log "yum -y install https://centos6.iuscommunity.org/ius-release.rpm" log "rpm --import /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY" - echo "* Installing httpd, PHP, MariaDB and other requirements."; + echo "* Installing Apache httpd, PHP, MariaDB and other requirements." PACKAGES="httpd mariadb-server git unzip php71u php71u-mysqlnd php71u-bcmath php71u-cli php71u-common php71u-embedded php71u-gd php71u-mbstring php71u-mcrypt php71u-ldap php71u-json php71u-simplexml" for p in $PACKAGES;do @@ -420,15 +407,11 @@ case $distro in fi done; - echo "* Cloning Snipe-IT from github to the web directory."; - log "git clone https://github.com/snipe/snipe-it $webdir/$name" + echo "* Setting MariaDB to start on boot and starting MariaDB." + log "chkconfig mysql on" + log "/sbin/service mysql start" - # Make mariaDB start on boot and restart the daemon - echo "* Starting the MariaDB server."; - chkconfig mysql on - /sbin/service mysql start - - echo "* Securing MariaDB server."; + echo "* Securing MariaDB." /usr/bin/mysql_secure_installation echo "* Creating MariaDB Database/User." @@ -437,45 +420,11 @@ case $distro in #Create the new virtual host in Apache and enable rewrite echo "* Creating the new virtual host in Apache." - apachefile=/etc/httpd/conf.d/$name.conf + setvhcentos - { - echo "" - echo "" - echo "" - echo "" - echo "ServerAdmin webmaster@localhost" - echo " " - echo " Allow From All" - echo " AllowOverride All" - echo " Options +Indexes" - echo " " - echo " DocumentRoot $webdir/$name/public" - echo " ServerName $fqdn" - echo " ErrorLog /var/log/httpd/snipeIT.error.log" - echo " CustomLog /var/log/access.log combined" - echo "" - } >> "$apachefile" - - echo "* Setting up hosts file."; + echo "* Setting up hosts file." echo >> $hosts "127.0.0.1 $hostname $fqdn" - # Make apache start on boot and restart the daemon - echo "* Starting the apache server."; - chkconfig httpd on - /sbin/service httpd start - - echo "* Configuring .env file." - tzone=$(grep ZONE /etc/sysconfig/clock | tr -d '"' | sed 's/ZONE=//g'); - setenv - - echo "* Installing and running composer." - installcomposer - - echo "* Setting permissions." - perms - chown -R apache:apache $webdir/$name - /sbin/service iptables status >/dev/null 2>&1 if [ $? = 0 ]; then echo "* Configuring iptables." @@ -484,24 +433,24 @@ case $distro in service iptables save fi - service httpd restart + installsnipeit - echo "* Generating the application key." - php artisan key:generate --force - - echo "* Artisan Migrate." - php artisan migrate --force + echo "* Setting Apache httpd to start on boot and starting service." + log "chkconfig httpd on" + log "/sbin/service httpd start" elif [[ "$version" =~ ^7 ]]; then - ##################################### Install for Centos/Redhat 7 ############################################## + ##################################### Install for CentOS/Redhat 7 ############################################## webdir=/var/www/html + ownergroup=apache:apache + tzone=$(timedatectl | gawk -F'[: ]' ' $9 ~ /zone/ {print $11}'); - echo "* Adding IUS, epel-release and MariaDB repositories."; + echo "* Adding IUS, epel-release and MariaDB repositories." log "yum -y install wget epel-release" log "yum -y install https://centos7.iuscommunity.org/ius-release.rpm" log "rpm --import /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY" - echo "* Installing httpd, PHP, MariaDB and other requirements."; + echo "* Installing Apache httpd, PHP, MariaDB and other requirements." PACKAGES="httpd mariadb-server git unzip php71u php71u-mysqlnd php71u-bcmath php71u-cli php71u-common php71u-embedded php71u-gd php71u-mbstring php71u-mcrypt php71u-ldap php71u-json php71u-simplexml" for p in $PACKAGES;do @@ -513,15 +462,11 @@ case $distro in fi done; - echo "* Cloning Snipe-IT from github to the web directory."; - log "git clone https://github.com/snipe/snipe-it $webdir/$name" + echo "* Setting MariaDB to start on boot and starting MariaDB." + log "systemctl enable mariadb.service" + log "systemctl start mariadb.service" - #Make mariaDB start on boot and restart the daemon - echo "* Starting the MariaDB server."; - systemctl enable mariadb.service - systemctl start mariadb.service - - echo "* Securing MariaDB server."; + echo "* Securing MariaDB." /usr/bin/mysql_secure_installation echo "* Creating MariaDB Database/User." @@ -531,46 +476,13 @@ case $distro in #TODO make sure the apachefile doesnt exist isnt already in there #Create the new virtual host in Apache and enable rewrite echo "* Creating the new virtual host in Apache." - apachefile="/etc/httpd/conf.d/$name.conf" - - { - - echo "" - echo "" - echo "LoadModule rewrite_module modules/mod_rewrite.so" - echo "" - echo "" - echo "ServerAdmin webmaster@localhost" - echo " " - echo " Allow From All" - echo " AllowOverride All" - echo " Options +Indexes" - echo " " - echo " DocumentRoot $webdir/$name/public" - echo " ServerName $fqdn" - echo " ErrorLog /var/log/httpd/snipeIT.error.log" - echo " CustomLog /var/log/access.log combined" - echo "" - } >> "$apachefile" + setvhcentos #TODO make sure this isnt already in there - echo "* Setting up hosts file."; + echo "* Setting up hosts file." echo >> $hosts "127.0.0.1 $hostname $fqdn" - echo "* Starting the apache server."; - systemctl enable httpd.service - systemctl restart httpd.service - - echo "* Configuring .env file." - tzone=$(timedatectl | gawk -F'[: ]' ' $9 ~ /zone/ {print $11}'); - setenv - - echo "* Installing and running composer." - installcomposer - - echo "* Setting permissions." - perms - chown -R apache:apache $webdir/$name + installsnipeit #Check if SELinux is enforcing if [ "$(getenforce)" == "Enforcing" ]; then @@ -581,19 +493,12 @@ case $distro in chcon -R -h -t httpd_sys_script_rw_t $webdir/$name/ fi + echo "* Setting Apache httpd to start on boot and starting service." + log "systemctl enable httpd.service" log "systemctl restart httpd.service" - echo "* Generating the application key." - php artisan key:generate --force - - echo "* Artisan Migrate." - php artisan migrate --force - - echo "* Creating scheduler cron." - (crontab -l ; echo "* * * * * /usr/bin/php $webdir/$name/artisan schedule:run >> /dev/null 2>&1") | crontab - - else - echo "Unable to Handle Centos Version #. Version Found: " $version + echo "Unsupported CentOS version. Version found: " $version return 1 fi esac