2016-03-25 01:18:05 -07:00
< ? php
2018-10-03 10:06:24 -07:00
2016-03-25 01:18:05 -07:00
namespace App\Http\Controllers ;
2020-04-21 04:08:25 -07:00
use App\Helpers\Helper ;
2021-06-10 13:15:52 -07:00
use App\Helpers\StorageHelper ;
2020-04-21 04:08:25 -07:00
use App\Http\Requests\ImageUploadRequest ;
2020-05-05 07:06:19 -07:00
use App\Http\Requests\SettingsSamlRequest ;
2018-10-03 10:06:24 -07:00
use App\Http\Requests\SetupUserRequest ;
2024-10-09 10:16:34 -07:00
use App\Http\Requests\StoreLdapSettings ;
use App\Http\Requests\StoreLocalizationSettings ;
use App\Http\Requests\StoreNotificationSettings ;
use App\Http\Requests\StoreLabelSettings ;
use App\Http\Requests\StoreSecuritySettings ;
2023-09-27 16:51:53 -07:00
use App\Models\CustomField ;
2022-08-29 12:09:56 -07:00
use App\Models\Group ;
2016-03-25 01:18:05 -07:00
use App\Models\Setting ;
2022-02-16 20:19:38 -08:00
use App\Models\Asset ;
2016-03-25 19:26:22 -07:00
use App\Models\User ;
2018-03-03 14:37:42 -08:00
use App\Notifications\FirstAdminNotification ;
2018-10-03 10:06:24 -07:00
use App\Notifications\MailTest ;
use Illuminate\Http\Request ;
2024-05-29 00:07:49 -07:00
use Illuminate\Support\Facades\App ;
2018-09-29 21:33:52 -07:00
use Illuminate\Support\Facades\Storage ;
2024-03-25 17:45:41 -07:00
use Illuminate\Validation\Rule ;
2024-07-04 14:37:58 -07:00
use Illuminate\Http\RedirectResponse ;
2024-07-04 14:52:49 -07:00
use Illuminate\Http\JsonResponse ;
2024-07-04 14:37:58 -07:00
use \Illuminate\Contracts\View\View ;
2021-11-10 00:07:17 -08:00
use Illuminate\Support\Str ;
use Illuminate\Support\Facades\Artisan ;
2024-05-29 00:07:49 -07:00
use Illuminate\Support\Facades\Auth ;
use Illuminate\Support\Facades\Crypt ;
use Illuminate\Support\Facades\DB ;
2024-06-19 09:21:49 -07:00
use Illuminate\Support\Facades\File ;
2024-05-31 09:33:57 -07:00
use Illuminate\Support\Facades\Http ;
2024-05-29 00:07:49 -07:00
use Illuminate\Support\Facades\Log ;
2024-05-31 09:33:57 -07:00
use Illuminate\Support\Facades\URL ;
2023-10-31 08:30:38 -07:00
use Illuminate\Support\Facades\Validator ;
2024-07-09 03:47:53 -07:00
use Symfony\Component\HttpFoundation\BinaryFileResponse ;
2016-12-27 17:31:53 -08:00
2016-03-25 01:18:05 -07:00
/**
2016-04-07 13:21:09 -07:00
* This controller handles all actions related to Settings for
* the Snipe - IT Asset Management application .
*
* @ version v1 . 0
2016-03-25 01:18:05 -07:00
*/
class SettingsController extends Controller
{
/**
2018-10-03 10:06:24 -07:00
* Checks to see whether or not the database has a migrations table
* and a user , otherwise display the setup view .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v3 . 0 ]
*
2024-07-04 12:49:22 -07:00
* @ return \Illuminate\Contracts\View\View | \Illuminate\Http\Response
2018-10-03 10:06:24 -07:00
*/
2024-07-04 14:37:58 -07:00
public function getSetupIndex () : View
2016-03-25 01:18:05 -07:00
{
2018-08-02 21:36:18 -07:00
$start_settings [ 'php_version_min' ] = false ;
2016-03-25 01:18:05 -07:00
2018-08-02 21:36:18 -07:00
if ( version_compare ( PHP_VERSION , config ( 'app.min_php' ), '<' )) {
2021-06-10 13:15:52 -07:00
return response ( '<center><h1>This software requires PHP version ' . config ( 'app.min_php' ) . ' or greater. This server is running ' . PHP_VERSION . '. </h1><h2>Please upgrade PHP on this server and try again. </h2></center>' , 500 );
2018-08-02 21:36:18 -07:00
}
2016-03-25 01:18:05 -07:00
try {
2021-06-10 13:15:52 -07:00
$conn = DB :: select ( 'select 2 + 2' );
$start_settings [ 'db_conn' ] = true ;
$start_settings [ 'db_name' ] = DB :: connection () -> getDatabaseName ();
2016-03-25 01:18:05 -07:00
$start_settings [ 'db_error' ] = null ;
} catch ( \PDOException $e ) {
2021-06-10 13:15:52 -07:00
$start_settings [ 'db_conn' ] = false ;
$start_settings [ 'db_name' ] = config ( 'database.connections.mysql.database' );
2016-03-25 01:18:05 -07:00
$start_settings [ 'db_error' ] = $e -> getMessage ();
}
2024-06-05 13:46:43 -07:00
$start_settings [ 'url_config' ] = trim ( config ( 'app.url' ), '/' ) . '/setup' ;
$start_settings [ 'real_url' ] = request () -> url ();
$start_settings [ 'url_valid' ] = $start_settings [ 'url_config' ] === $start_settings [ 'real_url' ];
2018-08-02 21:36:18 -07:00
$start_settings [ 'php_version_min' ] = true ;
2018-01-17 10:58:03 -08:00
2017-06-01 20:41:23 -07:00
// Curl the .env file to make sure it's not accessible via a browser
2024-05-31 09:33:57 -07:00
$start_settings [ 'env_exposed' ] = $this -> dotEnvFileIsExposed ();
2016-03-25 01:18:05 -07:00
2024-05-29 00:07:49 -07:00
if ( App :: Environment ( 'production' ) && ( true == config ( 'app.debug' ))) {
2016-03-25 01:18:05 -07:00
$start_settings [ 'debug_exposed' ] = true ;
} else {
$start_settings [ 'debug_exposed' ] = false ;
}
$environment = app () -> environment ();
2018-10-03 10:06:24 -07:00
if ( 'production' != $environment ) {
2021-06-10 13:15:52 -07:00
$start_settings [ 'env' ] = $environment ;
2016-03-25 01:18:05 -07:00
$start_settings [ 'prod' ] = false ;
} else {
2021-06-10 13:15:52 -07:00
$start_settings [ 'env' ] = $environment ;
2016-03-25 01:18:05 -07:00
$start_settings [ 'prod' ] = true ;
}
2023-02-28 23:31:26 -08:00
$start_settings [ 'owner' ] = '' ;
2016-06-22 12:27:41 -07:00
if ( function_exists ( 'posix_getpwuid' )) { // Probably Linux
2021-06-10 13:15:52 -07:00
$owner = posix_getpwuid ( fileowner ( $_SERVER [ 'SCRIPT_FILENAME' ]));
2023-02-28 23:37:30 -08:00
// This *should* be an array, but we've seen this return a bool in some chrooted environments
2023-02-28 23:32:10 -08:00
if ( is_array ( $owner )) {
2023-02-28 23:31:26 -08:00
$start_settings [ 'owner' ] = $owner [ 'name' ];
}
2016-06-06 05:37:45 -07:00
}
2016-03-25 01:18:05 -07:00
2023-02-28 23:31:26 -08:00
if (( $start_settings [ 'owner' ] === 'root' ) || ( $start_settings [ 'owner' ] === '0' )) {
2016-03-25 01:18:05 -07:00
$start_settings [ 'owner_is_admin' ] = true ;
} else {
$start_settings [ 'owner_is_admin' ] = false ;
}
2024-06-19 09:21:49 -07:00
$start_settings [ 'writable' ] = $this -> storagePathIsWritable ();
2016-03-25 01:18:05 -07:00
$start_settings [ 'gd' ] = extension_loaded ( 'gd' );
2018-10-03 10:06:24 -07:00
2017-06-09 16:44:03 -07:00
return view ( 'setup/index' )
2020-04-21 04:08:25 -07:00
-> with ( 'step' , 1 )
-> with ( 'start_settings' , $start_settings )
-> with ( 'section' , 'Pre-Flight Check' );
2016-03-25 01:18:05 -07:00
}
2024-05-31 09:33:57 -07:00
/**
* Determine if the . env file accessible via a browser .
*
* @ return bool This method will return true when exceptions ( such as curl exception ) is thrown .
* Check the log files to see more details about the exception .
*/
2024-07-04 14:37:58 -07:00
protected function dotEnvFileIsExposed () : bool
2024-05-31 09:33:57 -07:00
{
try {
2024-07-23 08:03:02 -07:00
return Http :: withoutVerifying () -> timeout ( 10 )
2024-05-31 09:33:57 -07:00
-> accept ( '*/*' )
-> get ( URL :: to ( '.env' ))
-> successful ();
2024-07-23 08:03:02 -07:00
} catch ( \Exception $e ) {
2024-07-23 12:24:05 -07:00
Log :: debug ( $e -> getMessage ());
2024-05-31 09:33:57 -07:00
return true ;
}
}
2024-06-19 09:21:49 -07:00
/**
* Determine if the app storage path is writable .
*/
protected function storagePathIsWritable () : bool
{
return File :: isWritable ( storage_path ()) &&
File :: isWritable ( storage_path ( 'framework' )) &&
File :: isWritable ( storage_path ( 'framework/cache' )) &&
File :: isWritable ( storage_path ( 'framework/sessions' )) &&
File :: isWritable ( storage_path ( 'framework/views' )) &&
File :: isWritable ( storage_path ( 'logs' ));
}
2016-03-25 01:18:05 -07:00
/**
2018-10-03 10:06:24 -07:00
* Save the first admin user from Setup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
*
*/
2024-07-04 14:37:58 -07:00
public function postSaveFirstAdmin ( SetupUserRequest $request ) : RedirectResponse
{
2024-07-04 14:52:49 -07:00
2021-06-10 13:15:52 -07:00
$user = new User ();
$user -> first_name = $data [ 'first_name' ] = $request -> input ( 'first_name' );
$user -> last_name = $request -> input ( 'last_name' );
$user -> email = $data [ 'email' ] = $request -> input ( 'email' );
$user -> activated = 1 ;
$permissions = [ 'superuser' => 1 ];
2016-05-14 15:04:59 -07:00
$user -> permissions = json_encode ( $permissions );
2021-06-10 13:15:52 -07:00
$user -> username = $data [ 'username' ] = $request -> input ( 'username' );
$user -> password = bcrypt ( $request -> input ( 'password' ));
$data [ 'password' ] = $request -> input ( 'password' );
2016-03-25 01:18:05 -07:00
2021-06-10 13:15:52 -07:00
$settings = new Setting ();
2018-01-17 10:58:03 -08:00
$settings -> full_multiple_companies_support = $request -> input ( 'full_multiple_companies_support' , 0 );
2021-06-10 13:15:52 -07:00
$settings -> site_name = $request -> input ( 'site_name' );
$settings -> alert_email = $request -> input ( 'email' );
$settings -> alerts_enabled = 1 ;
$settings -> pwd_secure_min = 10 ;
$settings -> brand = 1 ;
2023-12-24 11:44:20 -08:00
$settings -> locale = $request -> input ( 'locale' , 'en-US' );
2021-06-10 13:15:52 -07:00
$settings -> default_currency = $request -> input ( 'default_currency' , 'USD' );
2024-09-17 14:16:41 -07:00
$settings -> created_by = 1 ;
2021-06-10 13:15:52 -07:00
$settings -> email_domain = $request -> input ( 'email_domain' );
$settings -> email_format = $request -> input ( 'email_format' );
$settings -> next_auto_tag_base = 1 ;
$settings -> auto_increment_assets = $request -> input ( 'auto_increment_assets' , 0 );
$settings -> auto_increment_prefix = $request -> input ( 'auto_increment_prefix' );
2020-04-20 23:20:34 -07:00
2020-04-21 04:08:25 -07:00
if (( ! $user -> isValid ()) || ( ! $settings -> isValid ())) {
2016-04-28 21:06:41 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $user -> getErrors ()) -> withErrors ( $settings -> getErrors ());
2016-03-25 01:18:05 -07:00
} else {
2016-06-02 17:22:23 -07:00
$user -> save ();
2016-11-29 01:19:25 -08:00
Auth :: login ( $user , true );
2016-06-02 17:22:23 -07:00
$settings -> save ();
2016-09-17 00:00:39 -07:00
2020-09-15 01:51:10 -07:00
if ( $request -> input ( 'email_creds' ) == '1' ) {
2021-06-10 13:15:52 -07:00
$data = [];
$data [ 'email' ] = $user -> email ;
$data [ 'username' ] = $user -> username ;
2018-03-03 14:37:42 -08:00
$data [ 'first_name' ] = $user -> first_name ;
2021-06-10 13:15:52 -07:00
$data [ 'last_name' ] = $user -> last_name ;
$data [ 'password' ] = $request -> input ( 'password' );
2018-03-03 14:37:42 -08:00
$user -> notify ( new FirstAdminNotification ( $data ));
2016-03-25 01:18:05 -07:00
}
return redirect () -> route ( 'setup.done' );
}
}
/**
2018-10-03 10:06:24 -07:00
* Return the admin user creation form in Setup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v3 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getSetupUser () : View
2016-03-25 01:18:05 -07:00
{
2017-06-09 16:44:03 -07:00
return view ( 'setup/user' )
2020-04-21 04:08:25 -07:00
-> with ( 'step' , 3 )
-> with ( 'section' , 'Create a User' );
2016-03-25 01:18:05 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Return the view that tells the user that the Setup is done .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v3 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getSetupDone () : View
2016-03-25 01:18:05 -07:00
{
2017-06-09 16:44:03 -07:00
return view ( 'setup/done' )
2020-04-21 04:08:25 -07:00
-> with ( 'step' , 4 )
-> with ( 'section' , 'Done!' );
2016-03-25 01:18:05 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Migrate the database tables , and return the output
* to a view for Setup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v3 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getSetupMigrate () : View
2016-03-25 01:18:05 -07:00
{
Artisan :: call ( 'migrate' , [ '--force' => true ]);
2021-06-10 13:15:52 -07:00
if (( ! file_exists ( storage_path () . '/oauth-private.key' )) || ( ! file_exists ( storage_path () . '/oauth-public.key' ))) {
2019-01-30 14:45:36 -08:00
Artisan :: call ( 'migrate' , [ '--path' => 'vendor/laravel/passport/database/migrations' , '--force' => true ]);
2017-10-11 12:42:31 -07:00
Artisan :: call ( 'passport:install' );
2017-08-22 22:46:02 -07:00
}
2017-06-09 16:44:03 -07:00
return view ( 'setup/migrate' )
2020-04-21 04:08:25 -07:00
-> with ( 'output' , 'Databases installed!' )
-> with ( 'step' , 2 )
-> with ( 'section' , 'Create Database Tables' );
2016-03-25 01:18:05 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Return a view that shows some of the key settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function index () : View
2016-03-25 01:18:05 -07:00
{
2018-11-01 19:59:50 -07:00
$settings = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-06-09 16:44:03 -07:00
return view ( 'settings/index' , compact ( 'settings' ));
2016-03-25 01:18:05 -07:00
}
2017-07-07 23:44:48 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getSettings () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings/general' , compact ( 'setting' ));
2016-03-25 01:18:05 -07:00
}
/**
2017-07-07 23:44:48 -07:00
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function postSettings ( Request $request ) : RedirectResponse
2016-03-25 01:18:05 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2016-04-28 21:06:41 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
2016-03-25 01:18:05 -07:00
}
2018-01-24 10:43:46 -08:00
$setting -> modellist_displays = '' ;
2021-06-10 13:15:52 -07:00
if (( $request -> filled ( 'show_in_model_list' )) && ( count ( $request -> input ( 'show_in_model_list' )) > 0 )) {
2018-01-24 10:43:46 -08:00
$setting -> modellist_displays = implode ( ',' , $request -> input ( 'show_in_model_list' ));
}
2017-07-07 23:44:48 -07:00
$setting -> full_multiple_companies_support = $request -> input ( 'full_multiple_companies_support' , '0' );
2021-06-10 13:15:52 -07:00
$setting -> unique_serial = $request -> input ( 'unique_serial' , '0' );
2024-08-07 10:47:16 -07:00
$setting -> shortcuts_enabled = $request -> input ( 'shortcuts_enabled' , '0' );
2021-06-10 13:15:52 -07:00
$setting -> show_images_in_email = $request -> input ( 'show_images_in_email' , '0' );
$setting -> show_archived_in_list = $request -> input ( 'show_archived_in_list' , '0' );
$setting -> dashboard_message = $request -> input ( 'dashboard_message' );
$setting -> email_domain = $request -> input ( 'email_domain' );
$setting -> email_format = $request -> input ( 'email_format' );
$setting -> username_format = $request -> input ( 'username_format' );
$setting -> require_accept_signature = $request -> input ( 'require_accept_signature' );
$setting -> show_assigned_assets = $request -> input ( 'show_assigned_assets' , '0' );
2018-10-03 10:06:24 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2017-09-22 17:23:22 -07:00
$setting -> login_note = $request -> input ( 'login_note' );
}
2021-06-10 13:15:52 -07:00
$setting -> default_eula_text = $request -> input ( 'default_eula_text' );
$setting -> thumbnail_max_h = $request -> input ( 'thumbnail_max_h' );
2018-05-08 00:50:13 -07:00
$setting -> privacy_policy_link = $request -> input ( 'privacy_policy_link' );
2018-08-28 12:32:46 -07:00
$setting -> depreciation_method = $request -> input ( 'depreciation_method' );
2022-09-29 04:16:46 -07:00
$setting -> dash_chart_type = $request -> input ( 'dash_chart_type' );
2024-06-24 06:03:01 -07:00
$setting -> profile_edit = $request -> input ( 'profile_edit' , 0 );
2018-08-28 12:32:46 -07:00
2020-09-15 01:51:10 -07:00
if ( $request -> input ( 'per_page' ) != '' ) {
2017-07-07 23:44:48 -07:00
$setting -> per_page = $request -> input ( 'per_page' );
} else {
$setting -> per_page = 200 ;
}
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
2016-03-25 01:18:05 -07:00
2017-07-07 23:44:48 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getBranding () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.branding' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function postBranding ( ImageUploadRequest $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2024-07-04 05:22:36 -07:00
// Something has gone horribly wrong - no settings record exists!
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2021-06-10 13:15:52 -07:00
$setting -> brand = $request -> input ( 'brand' , '1' );
$setting -> header_color = $request -> input ( 'header_color' );
$setting -> support_footer = $request -> input ( 'support_footer' );
$setting -> version_footer = $request -> input ( 'version_footer' );
$setting -> footer_text = $request -> input ( 'footer_text' );
$setting -> skin = $request -> input ( 'skin' );
2024-07-04 05:22:36 -07:00
$setting -> allow_user_skin = $request -> input ( 'allow_user_skin' , '0' );
2017-10-17 13:54:03 -07:00
$setting -> show_url_in_emails = $request -> input ( 'show_url_in_emails' , '0' );
2021-06-10 13:15:52 -07:00
$setting -> logo_print_assets = $request -> input ( 'logo_print_assets' , '0' );
2024-07-04 08:55:47 -07:00
$setting -> load_remote = $request -> input ( 'load_remote' , 0 );
2018-07-24 13:37:02 -07:00
2024-07-04 05:22:36 -07:00
// Only allow the site name, images, and CSS to be changed if lock_passwords is false
2017-07-07 23:44:48 -07:00
// Because public demos make people act like dicks
2024-03-01 02:17:57 -08:00
2024-07-04 05:22:36 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2024-07-04 08:33:22 -07:00
if ( $request -> has ( 'site_name' )) {
$request -> validate ([ 'site_name' => 'required' ]);
}
$setting -> site_name = $request -> input ( 'site_name' , 'Snipe-IT' );
2017-07-07 18:06:31 -07:00
$setting -> custom_css = $request -> input ( 'custom_css' );
2017-07-07 23:44:48 -07:00
2024-07-04 05:22:36 -07:00
// Logo upload
$setting = $request -> handleImages ( $setting , 600 , 'logo' , '' , 'logo' );
2024-07-04 08:33:22 -07:00
if ( $request -> input ( 'clear_logo' ) == '1' ) {
2024-07-19 22:06:27 -07:00
$setting = $request -> deleteExistingImage ( $setting , '' , 'logo' );
2024-02-19 08:11:17 -08:00
$setting -> logo = null ;
2020-04-27 23:22:52 -07:00
$setting -> brand = 1 ;
2024-02-19 08:11:17 -08:00
}
2018-12-05 19:56:12 -08:00
2024-07-04 05:22:36 -07:00
// Email logo upload
2024-02-19 08:11:17 -08:00
$setting = $request -> handleImages ( $setting , 600 , 'email_logo' , '' , 'email_logo' );
2024-07-04 08:33:22 -07:00
if ( $request -> input ( 'clear_email_logo' ) == '1' ) {
2024-07-19 22:05:01 -07:00
$setting = $request -> deleteExistingImage ( $setting , '' , 'email_logo' );
2024-02-19 08:11:17 -08:00
$setting -> email_logo = null ;
}
2019-03-01 15:25:42 -08:00
2024-07-04 05:22:36 -07:00
// Label logo upload
2024-02-19 08:11:17 -08:00
$setting = $request -> handleImages ( $setting , 600 , 'label_logo' , '' , 'label_logo' );
2024-07-04 08:33:22 -07:00
2024-07-19 21:55:34 -07:00
if ( $request -> input ( 'clear_label_logo' ) == '1' ) {
$setting = $request -> deleteExistingImage ( $setting , '' , 'label_logo' );
2024-02-19 08:11:17 -08:00
$setting -> label_logo = null ;
2018-12-05 19:56:12 -08:00
}
2024-07-04 05:22:36 -07:00
// Favicon upload
$setting = $request -> handleImages ( $setting , 100 , 'favicon' , '' , 'favicon' );
2024-03-01 02:17:57 -08:00
if ( '1' == $request -> input ( 'clear_favicon' )) {
2024-07-19 21:55:34 -07:00
$setting = $request -> deleteExistingImage ( $setting , '' , 'favicon' );
2024-02-19 08:11:17 -08:00
$setting -> favicon = null ;
2017-07-07 23:44:48 -07:00
}
2024-07-04 05:22:36 -07:00
// Default avatar upload
$setting = $request -> handleImages ( $setting , 500 , 'default_avatar' , 'avatars' , 'default_avatar' );
2024-07-19 21:55:34 -07:00
if ( $request -> input ( 'clear_default_avatar' ) == '1' ) {
// Don't delete the file, just update the field if this is the default
if ( $setting -> default_avatar != 'default.png' ) {
$setting = $request -> deleteExistingImage ( $setting , 'avatars' , 'default_avatar' );
2024-07-04 08:33:22 -07:00
}
2024-07-04 05:22:36 -07:00
$setting -> default_avatar = null ;
}
2024-07-19 21:55:34 -07:00
if ( $request -> input ( 'restore_default_avatar' ) == '1' ) {
$setting -> default_avatar = 'default.png' ;
}
2024-02-19 08:11:17 -08:00
}
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:37:58 -07:00
public function getSecurity () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.security' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-10-09 10:16:34 -07:00
public function postSecurity ( StoreSecuritySettings $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2024-03-25 17:45:41 -07:00
$this -> validate ( $request , [
'pwd_secure_complexity' => 'array' ,
'pwd_secure_complexity.*' => [
Rule :: in ([
'disallow_same_pwd_as_user_fields' ,
'letters' ,
'numbers' ,
'symbols' ,
'case_diff' ,
])
]
]);
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2018-10-03 10:06:24 -07:00
if ( ! config ( 'app.lock_passwords' )) {
if ( '' == $request -> input ( 'two_factor_enabled' )) {
2016-10-31 13:50:00 -07:00
$setting -> two_factor_enabled = null ;
} else {
2017-07-07 18:06:31 -07:00
$setting -> two_factor_enabled = $request -> input ( 'two_factor_enabled' );
2016-10-31 13:50:00 -07:00
}
2019-01-15 14:02:10 -08:00
// remote user login
2021-06-10 13:15:52 -07:00
$setting -> login_remote_user_enabled = ( int ) $request -> input ( 'login_remote_user_enabled' );
$setting -> login_common_disabled = ( int ) $request -> input ( 'login_common_disabled' );
2019-01-15 13:59:36 -08:00
$setting -> login_remote_user_custom_logout_url = $request -> input ( 'login_remote_user_custom_logout_url' );
2019-09-03 11:07:26 -07:00
$setting -> login_remote_user_header_name = $request -> input ( 'login_remote_user_header_name' );
2016-03-25 01:18:05 -07:00
}
2021-06-10 13:15:52 -07:00
$setting -> pwd_secure_uncommon = ( int ) $request -> input ( 'pwd_secure_uncommon' );
$setting -> pwd_secure_min = ( int ) $request -> input ( 'pwd_secure_min' );
2017-08-22 20:32:39 -07:00
$setting -> pwd_secure_complexity = '' ;
2018-03-14 12:48:07 -07:00
2019-05-23 17:39:50 -07:00
if ( $request -> filled ( 'pwd_secure_complexity' )) {
2021-06-10 13:15:52 -07:00
$setting -> pwd_secure_complexity = implode ( '|' , $request -> input ( 'pwd_secure_complexity' ));
2017-08-22 20:32:39 -07:00
}
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getLocalization () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.localization' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-10-09 10:16:34 -07:00
public function postLocalization ( StoreLocalizationSettings $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
2016-03-25 01:18:05 -07:00
}
2018-10-03 10:06:24 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2023-12-24 11:44:20 -08:00
$setting -> locale = $request -> input ( 'locale' , 'en-US' );
2018-07-24 13:37:02 -07:00
}
2021-06-10 13:15:52 -07:00
$setting -> default_currency = $request -> input ( 'default_currency' , '$' );
2017-07-07 23:44:48 -07:00
$setting -> date_display_format = $request -> input ( 'date_display_format' );
$setting -> time_display_format = $request -> input ( 'time_display_format' );
2020-12-15 11:49:13 -08:00
$setting -> digit_separator = $request -> input ( 'digit_separator' );
2023-08-21 12:10:03 -07:00
$setting -> name_display_format = $request -> input ( 'name_display_format' );
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getAlerts () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.alerts' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
*/
2024-10-09 10:16:34 -07:00
public function postAlerts ( StoreNotificationSettings $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2022-02-16 20:19:38 -08:00
// Check if the audit interval has changed - if it has, we want to update ALL of the assets audit dates
if ( $request -> input ( 'audit_interval' ) != $setting -> audit_interval ) {
2024-02-06 07:52:46 -08:00
// This could be a negative number if the user is trying to set the audit interval to a lower number than it was before
2022-02-17 14:34:33 -08:00
$audit_diff_months = (( int ) $request -> input ( 'audit_interval' ) - ( int )( $setting -> audit_interval ));
2022-02-16 20:19:38 -08:00
2024-02-06 07:52:46 -08:00
// Batch update the dates. We have to use this method to avoid time limit exceeded errors on very large datasets,
// but it DOES mean this change doesn't get logged in the action logs, since it skips the observer.
// @see https://stackoverflow.com/questions/54879160/laravel-observer-not-working-on-bulk-insert
$affected = Asset :: whereNotNull ( 'next_audit_date' )
-> whereNull ( 'deleted_at' )
-> update (
2024-02-06 07:58:36 -08:00
[ 'next_audit_date' => DB :: raw ( 'DATE_ADD(next_audit_date, INTERVAL ' . $audit_diff_months . ' MONTH)' )]
2024-02-06 07:52:46 -08:00
);
2022-02-16 20:19:38 -08:00
2024-05-29 00:07:49 -07:00
Log :: debug ( $affected . ' assets affected by audit interval update' );
2024-02-06 07:52:46 -08:00
2022-02-20 13:29:12 -08:00
}
2022-02-16 20:19:38 -08:00
2021-06-10 13:15:52 -07:00
$alert_email = rtrim ( $request -> input ( 'alert_email' ), ',' );
$alert_email = trim ( $alert_email );
2018-03-25 13:46:57 -07:00
$admin_cc_email = rtrim ( $request -> input ( 'admin_cc_email' ), ',' );
$admin_cc_email = trim ( $admin_cc_email );
2017-07-07 23:44:48 -07:00
2021-06-10 13:15:52 -07:00
$setting -> alert_email = $alert_email ;
$setting -> admin_cc_email = $admin_cc_email ;
$setting -> alerts_enabled = $request -> input ( 'alerts_enabled' , '0' );
$setting -> alert_interval = $request -> input ( 'alert_interval' );
$setting -> alert_threshold = $request -> input ( 'alert_threshold' );
$setting -> audit_interval = $request -> input ( 'audit_interval' );
$setting -> audit_warning_days = $request -> input ( 'audit_warning_days' );
2024-08-15 03:20:51 -07:00
$setting -> due_checkin_days = $request -> input ( 'due_checkin_days' );
2017-11-08 03:08:17 -08:00
$setting -> show_alerts_in_menu = $request -> input ( 'show_alerts_in_menu' , '0' );
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getSlack () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.slack' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getAssetTags () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2018-10-03 10:06:24 -07:00
2017-07-07 23:44:48 -07:00
return view ( 'settings.asset_tags' , compact ( 'setting' ));
}
/**
2018-10-03 10:06:24 -07:00
* Saves settings from form .
2017-07-07 23:44:48 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function postAssetTags ( Request $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
$setting -> auto_increment_prefix = $request -> input ( 'auto_increment_prefix' );
$setting -> auto_increment_assets = $request -> input ( 'auto_increment_assets' , '0' );
2021-06-10 13:15:52 -07:00
$setting -> zerofill_count = $request -> input ( 'zerofill_count' );
$setting -> next_auto_tag_base = $request -> input ( 'next_auto_tag_base' );
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getBarcodes () : View
2017-07-07 23:44:48 -07:00
{
2021-06-10 13:15:52 -07:00
$setting = Setting :: getSettings ();
2017-07-07 23:44:48 -07:00
$is_gd_installed = extension_loaded ( 'gd' );
2018-10-03 10:06:24 -07:00
return view ( 'settings.barcodes' , compact ( 'setting' )) -> with ( 'is_gd_installed' , $is_gd_installed );
2017-07-07 23:44:48 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Saves settings from form .
2017-07-07 23:44:48 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v1 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function postBarcodes ( Request $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2021-06-10 13:15:52 -07:00
$setting -> qr_code = $request -> input ( 'qr_code' , '0' );
$setting -> alt_barcode = $request -> input ( 'alt_barcode' );
2017-07-07 18:06:31 -07:00
$setting -> alt_barcode_enabled = $request -> input ( 'alt_barcode_enabled' , '0' );
2021-06-10 13:15:52 -07:00
$setting -> barcode_type = $request -> input ( 'barcode_type' );
$setting -> qr_text = $request -> input ( 'qr_text' );
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
2017-07-08 00:09:39 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-08 00:09:39 -07:00
* @ since [ v4 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getPhpInfo () : View | RedirectResponse
2017-07-08 00:09:39 -07:00
{
2023-02-06 12:43:35 -08:00
if ( config ( 'app.debug' ) === true ) {
2017-07-08 00:22:30 -07:00
return view ( 'settings.phpinfo' );
}
2018-10-03 10:06:24 -07:00
2017-07-08 00:22:30 -07:00
return redirect () -> route ( 'settings.index' )
-> with ( 'error' , 'PHP syetem debugging information is only available when debug is enabled in your .env file.' );
2017-07-08 00:09:39 -07:00
}
2017-07-07 23:44:48 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getLabels () : View
2017-07-07 23:44:48 -07:00
{
2024-04-22 18:27:34 -07:00
return view ( 'settings.labels' )
-> with ( 'setting' , Setting :: getSettings ())
-> with ( 'customFields' , CustomField :: where ( 'field_encrypted' , '=' , 0 ) -> get ());
2017-07-07 23:44:48 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Saves settings from form .
2017-07-07 23:44:48 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
*/
2024-10-09 10:16:34 -07:00
public function postLabels ( StoreLabelSettings $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2022-11-01 05:00:53 -07:00
$setting -> label2_enable = $request -> input ( 'label2_enable' );
$setting -> label2_template = $request -> input ( 'label2_template' );
$setting -> label2_title = $request -> input ( 'label2_title' );
$setting -> label2_asset_logo = $request -> input ( 'label2_asset_logo' );
$setting -> label2_1d_type = $request -> input ( 'label2_1d_type' );
$setting -> label2_2d_type = $request -> input ( 'label2_2d_type' );
$setting -> label2_2d_target = $request -> input ( 'label2_2d_target' );
$setting -> label2_fields = $request -> input ( 'label2_fields' );
2021-06-10 13:15:52 -07:00
$setting -> labels_per_page = $request -> input ( 'labels_per_page' );
$setting -> labels_width = $request -> input ( 'labels_width' );
$setting -> labels_height = $request -> input ( 'labels_height' );
$setting -> labels_pmargin_left = $request -> input ( 'labels_pmargin_left' );
$setting -> labels_pmargin_right = $request -> input ( 'labels_pmargin_right' );
$setting -> labels_pmargin_top = $request -> input ( 'labels_pmargin_top' );
$setting -> labels_pmargin_bottom = $request -> input ( 'labels_pmargin_bottom' );
$setting -> labels_display_bgutter = $request -> input ( 'labels_display_bgutter' );
$setting -> labels_display_sgutter = $request -> input ( 'labels_display_sgutter' );
$setting -> labels_fontsize = $request -> input ( 'labels_fontsize' );
$setting -> labels_pagewidth = $request -> input ( 'labels_pagewidth' );
$setting -> labels_pageheight = $request -> input ( 'labels_pageheight' );
2017-11-08 20:05:39 -08:00
$setting -> labels_display_company_name = $request -> input ( 'labels_display_company_name' , '0' );
2020-04-27 23:22:52 -07:00
$setting -> labels_display_company_name = $request -> input ( 'labels_display_company_name' , '0' );
2017-07-07 23:44:48 -07:00
2016-03-25 01:18:05 -07:00
2016-10-31 13:50:00 -07:00
2019-05-23 17:39:50 -07:00
if ( $request -> filled ( 'labels_display_name' )) {
2016-03-25 01:18:05 -07:00
$setting -> labels_display_name = 1 ;
} else {
$setting -> labels_display_name = 0 ;
}
2019-05-23 17:39:50 -07:00
if ( $request -> filled ( 'labels_display_serial' )) {
2016-03-25 01:18:05 -07:00
$setting -> labels_display_serial = 1 ;
} else {
$setting -> labels_display_serial = 0 ;
}
2019-05-23 17:39:50 -07:00
if ( $request -> filled ( 'labels_display_tag' )) {
2016-03-25 01:18:05 -07:00
$setting -> labels_display_tag = 1 ;
} else {
$setting -> labels_display_tag = 0 ;
2020-04-21 04:08:25 -07:00
}
2018-07-12 18:23:12 -07:00
2020-04-21 04:08:25 -07:00
if ( $request -> filled ( 'labels_display_tag' )) {
$setting -> labels_display_tag = 1 ;
} else {
$setting -> labels_display_tag = 0 ;
}
2016-03-25 01:18:05 -07:00
2019-05-23 17:39:50 -07:00
if ( $request -> filled ( 'labels_display_model' )) {
2018-07-24 12:09:30 -07:00
$setting -> labels_display_model = 1 ;
} else {
$setting -> labels_display_model = 0 ;
}
2017-07-07 23:44:48 -07:00
if ( $setting -> save ()) {
2023-08-15 10:48:12 -07:00
return redirect () -> route ( 'settings.labels.index' )
2017-07-07 23:44:48 -07:00
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2017-07-07 23:44:48 -07:00
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v4 . 0 ]
*/
2024-10-09 14:15:49 -07:00
public function getLdapSettings () : View
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
$setting = Setting :: getSettings ();
2022-08-29 12:09:56 -07:00
$groups = Group :: pluck ( 'name' , 'id' );
2024-10-09 14:15:49 -07:00
return view ( 'settings.ldap' , compact ( 'setting' , 'groups' ));
2017-07-07 23:44:48 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Saves settings from form .
2017-07-07 23:44:48 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
*/
2024-10-09 10:16:34 -07:00
public function postLdapSettings ( StoreLdapSettings $request ) : RedirectResponse
2017-07-07 23:44:48 -07:00
{
2018-11-01 19:59:50 -07:00
if ( is_null ( $setting = Setting :: getSettings ())) {
2017-07-07 23:44:48 -07:00
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2016-03-25 01:18:05 -07:00
2021-06-10 13:15:52 -07:00
if ( ! config ( 'app.lock_passwords' ) === true ) {
$setting -> ldap_enabled = $request -> input ( 'ldap_enabled' , '0' );
$setting -> ldap_server = $request -> input ( 'ldap_server' );
2020-09-25 18:38:26 -07:00
$setting -> ldap_server_cert_ignore = $request -> input ( 'ldap_server_cert_ignore' , false );
2021-06-10 13:15:52 -07:00
$setting -> ldap_uname = $request -> input ( 'ldap_uname' );
2020-10-09 13:08:51 -07:00
if ( $request -> filled ( 'ldap_pword' )) {
2020-09-25 18:38:26 -07:00
$setting -> ldap_pword = Crypt :: encrypt ( $request -> input ( 'ldap_pword' ));
}
2021-06-10 13:15:52 -07:00
$setting -> ldap_basedn = $request -> input ( 'ldap_basedn' );
2022-08-25 15:19:38 -07:00
$setting -> ldap_default_group = $request -> input ( 'ldap_default_group' );
2021-06-10 13:15:52 -07:00
$setting -> ldap_filter = $request -> input ( 'ldap_filter' );
$setting -> ldap_username_field = $request -> input ( 'ldap_username_field' );
$setting -> ldap_lname_field = $request -> input ( 'ldap_lname_field' );
$setting -> ldap_fname_field = $request -> input ( 'ldap_fname_field' );
2020-09-25 18:38:26 -07:00
$setting -> ldap_auth_filter_query = $request -> input ( 'ldap_auth_filter_query' );
2022-06-06 21:00:22 -07:00
$setting -> ldap_version = $request -> input ( 'ldap_version' , 3 );
2021-06-10 13:15:52 -07:00
$setting -> ldap_active_flag = $request -> input ( 'ldap_active_flag' );
$setting -> ldap_emp_num = $request -> input ( 'ldap_emp_num' );
$setting -> ldap_email = $request -> input ( 'ldap_email' );
2022-03-21 11:15:39 -07:00
$setting -> ldap_manager = $request -> input ( 'ldap_manager' );
2021-06-10 13:15:52 -07:00
$setting -> ad_domain = $request -> input ( 'ad_domain' );
$setting -> is_ad = $request -> input ( 'is_ad' , '0' );
$setting -> ad_append_domain = $request -> input ( 'ad_append_domain' , '0' );
$setting -> ldap_tls = $request -> input ( 'ldap_tls' , '0' );
$setting -> ldap_pw_sync = $request -> input ( 'ldap_pw_sync' , '0' );
2020-09-25 18:38:26 -07:00
$setting -> custom_forgot_pass_url = $request -> input ( 'custom_forgot_pass_url' );
2021-06-10 13:15:52 -07:00
$setting -> ldap_phone_field = $request -> input ( 'ldap_phone' );
$setting -> ldap_jobtitle = $request -> input ( 'ldap_jobtitle' );
$setting -> ldap_country = $request -> input ( 'ldap_country' );
2023-04-25 11:44:04 -07:00
$setting -> ldap_location = $request -> input ( 'ldap_location' );
2021-06-10 13:15:52 -07:00
$setting -> ldap_dept = $request -> input ( 'ldap_dept' );
2021-08-17 14:43:36 -07:00
$setting -> ldap_client_tls_cert = $request -> input ( 'ldap_client_tls_cert' );
$setting -> ldap_client_tls_key = $request -> input ( 'ldap_client_tls_key' );
2020-09-25 18:38:26 -07:00
}
2017-07-07 18:06:31 -07:00
2016-03-25 01:18:05 -07:00
if ( $setting -> save ()) {
2021-08-17 14:43:36 -07:00
$setting -> update_client_side_cert_files ();
2018-12-06 14:05:43 -08:00
return redirect () -> route ( 'settings.ldap.index' )
2017-07-07 23:44:48 -07:00
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
2016-03-25 01:18:05 -07:00
}
2018-10-03 10:06:24 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2016-03-25 01:18:05 -07:00
}
2020-05-05 07:06:19 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author Johnson Yi < jyi . dev @ outlook . com >
* @ since v5 . 0.0
*/
2024-07-04 14:52:49 -07:00
public function getSamlSettings () : View
2020-05-05 07:06:19 -07:00
{
$setting = Setting :: getSettings ();
return view ( 'settings.saml' , compact ( 'setting' ));
}
/**
* Saves settings from form .
*
* @ author Johnson Yi < jyi . dev @ outlook . com >
* @ since v5 . 0.0
*/
2024-07-04 14:52:49 -07:00
public function postSamlSettings ( SettingsSamlRequest $request ) : RedirectResponse
2020-05-05 07:06:19 -07:00
{
if ( is_null ( $setting = Setting :: getSettings ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2021-06-10 13:15:52 -07:00
$setting -> saml_enabled = $request -> input ( 'saml_enabled' , '0' );
$setting -> saml_idp_metadata = $request -> input ( 'saml_idp_metadata' );
$setting -> saml_attr_mapping_username = $request -> input ( 'saml_attr_mapping_username' );
$setting -> saml_forcelogin = $request -> input ( 'saml_forcelogin' , '0' );
$setting -> saml_slo = $request -> input ( 'saml_slo' , '0' );
if ( ! empty ( $request -> input ( 'saml_sp_privatekey' ))) {
$setting -> saml_sp_x509cert = $request -> input ( 'saml_sp_x509cert' );
$setting -> saml_sp_privatekey = $request -> input ( 'saml_sp_privatekey' );
2020-05-05 07:06:19 -07:00
}
2021-06-10 13:15:52 -07:00
if ( ! empty ( $request -> input ( 'saml_sp_x509certNew' ))) {
$setting -> saml_sp_x509certNew = $request -> input ( 'saml_sp_x509certNew' );
2020-08-14 02:10:19 -07:00
} else {
2021-06-10 13:15:52 -07:00
$setting -> saml_sp_x509certNew = '' ;
2020-08-14 02:10:19 -07:00
}
2021-06-10 13:15:52 -07:00
$setting -> saml_custom_settings = $request -> input ( 'saml_custom_settings' );
2020-05-05 07:06:19 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.saml.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
2022-03-16 15:53:32 -07:00
2024-07-04 14:52:49 -07:00
/**
* Do we need this ? Can we not just call getSettings () directly ?
*/
public static function getPDFBranding () : Setting
{
$pdf_branding = Setting :: getSettings ();
2022-03-16 15:53:32 -07:00
return $pdf_branding ;
}
2020-05-05 07:06:19 -07:00
2023-05-10 00:54:28 -07:00
/**
* Show Google login settings form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v6 . 1.1 ]
*/
2024-07-04 14:52:49 -07:00
public function getGoogleLoginSettings () : View
2023-05-10 00:54:28 -07:00
{
$setting = Setting :: getSettings ();
return view ( 'settings.google' , compact ( 'setting' ));
}
/**
* ShSaveow Google login settings form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v6 . 1.1 ]
*/
2024-07-04 14:52:49 -07:00
public function postGoogleLoginSettings ( Request $request ) : RedirectResponse
2023-05-10 00:54:28 -07:00
{
2023-05-10 01:14:54 -07:00
if ( ! config ( 'app.lock_passwords' )) {
$setting = Setting :: getSettings ();
2023-05-10 00:54:28 -07:00
2023-05-10 01:14:54 -07:00
$setting -> google_login = $request -> input ( 'google_login' , 0 );
$setting -> google_client_id = $request -> input ( 'google_client_id' );
$setting -> google_client_secret = $request -> input ( 'google_client_secret' );
2023-05-10 00:54:28 -07:00
2023-05-10 01:14:54 -07:00
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2023-05-10 00:54:28 -07:00
}
2023-05-10 01:14:54 -07:00
return redirect () -> back () -> with ( 'error' , trans ( 'general.feature_disabled' ));
2023-05-10 00:54:28 -07:00
}
2016-03-25 01:18:05 -07:00
/**
2018-10-03 10:06:24 -07:00
* Show the listing of backups .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*
* @ since [ v1 . 8 ]
*/
2024-07-04 14:52:49 -07:00
public function getBackups () : View
2016-03-25 01:18:05 -07:00
{
2022-05-17 14:36:05 -07:00
$settings = Setting :: getSettings ();
2021-06-10 13:15:52 -07:00
$path = 'app/backups' ;
2018-09-29 21:33:52 -07:00
$backup_files = Storage :: files ( $path );
2021-06-10 13:15:52 -07:00
$files_raw = [];
2016-03-25 15:50:08 -07:00
2018-09-29 21:33:52 -07:00
if ( count ( $backup_files ) > 0 ) {
2021-06-10 13:15:52 -07:00
for ( $f = 0 ; $f < count ( $backup_files ); $f ++ ) {
2020-08-28 14:10:43 -07:00
// Skip dotfiles like .gitignore and .DS_STORE
if (( substr ( basename ( $backup_files [ $f ]), 0 , 1 ) != '.' )) {
2021-11-09 22:37:49 -08:00
//$lastmodified = Carbon::parse(Storage::lastModified($backup_files[$f]))->toDatetimeString();
$file_timestamp = Storage :: lastModified ( $backup_files [ $f ]);
2020-11-30 14:46:10 -08:00
$files_raw [] = [
2020-08-28 14:10:43 -07:00
'filename' => basename ( $backup_files [ $f ]),
'filesize' => Setting :: fileSizeConvert ( Storage :: size ( $backup_files [ $f ])),
2021-11-09 22:37:49 -08:00
'modified_value' => $file_timestamp ,
2022-05-17 14:36:05 -07:00
'modified_display' => date ( $settings -> date_display_format . ' ' . $settings -> time_display_format , $file_timestamp ),
2024-05-29 00:07:49 -07:00
2020-08-28 14:10:43 -07:00
];
}
2016-03-25 01:18:05 -07:00
}
}
2020-11-30 14:46:10 -08:00
// Reverse the array so it lists oldest first
$files = array_reverse ( $files_raw );
2017-06-09 16:44:03 -07:00
return view ( 'settings/backups' , compact ( 'path' , 'files' ));
2016-03-25 01:18:05 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Process the backup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
*/
2024-07-04 14:52:49 -07:00
public function postBackups () : RedirectResponse
2016-03-25 01:18:05 -07:00
{
2018-10-03 10:06:24 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2023-06-29 12:32:20 -07:00
Artisan :: call ( 'snipeit:backup' , [ '--filename' => 'manual-backup-' . date ( 'Y-m-d-H-i-s' )]);
2017-11-01 14:12:18 -07:00
$output = Artisan :: output ();
// Backup completed
2018-10-03 10:06:24 -07:00
if ( ! preg_match ( '/failed/' , $output )) {
2017-11-01 14:12:18 -07:00
return redirect () -> route ( 'settings.backups.index' )
-> with ( 'success' , trans ( 'admin/settings/message.backup.generated' ));
}
$formatted_output = str_replace ( 'Backup completed!' , '' , $output );
2021-06-10 13:15:52 -07:00
$output_split = explode ( '...' , $formatted_output );
2017-11-01 14:12:18 -07:00
if ( array_key_exists ( 2 , $output_split )) {
2018-10-03 10:06:24 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , $output_split [ 2 ]);
2017-11-01 14:12:18 -07:00
}
2018-10-03 10:06:24 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , $formatted_output );
}
2017-11-01 14:12:18 -07:00
2018-10-03 10:06:24 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
2016-03-25 01:18:05 -07:00
}
/**
2018-10-03 10:06:24 -07:00
* Download the backup file .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
*/
2024-07-09 03:47:53 -07:00
public function downloadFile ( $filename = null ) : RedirectResponse | BinaryFileResponse
2016-03-25 01:18:05 -07:00
{
2020-08-28 18:22:37 -07:00
$path = 'app/backups' ;
2018-10-03 10:06:24 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2021-06-10 13:15:52 -07:00
if ( Storage :: exists ( $path . '/' . $filename )) {
return StorageHelper :: downloader ( $path . '/' . $filename );
2016-03-25 01:18:05 -07:00
} else {
// Redirect to the backup page
2017-07-08 13:42:05 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'admin/settings/message.backup.file_not_found' ));
2016-03-25 01:18:05 -07:00
}
} else {
// Redirect to the backup page
2017-07-08 13:42:05 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
2016-03-25 01:18:05 -07:00
}
}
/**
2018-10-03 10:06:24 -07:00
* Delete the backup file .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
*/
2024-07-04 14:52:49 -07:00
public function deleteFile ( $filename = null ) : RedirectResponse
2016-03-25 01:18:05 -07:00
{
2022-06-24 15:49:22 -07:00
if ( config ( 'app.allow_backup_delete' ) == 'true' ) {
2016-03-25 01:18:05 -07:00
2022-06-24 15:49:22 -07:00
if ( ! config ( 'app.lock_passwords' )) {
$path = 'app/backups' ;
2021-06-10 13:15:52 -07:00
2022-06-24 15:49:22 -07:00
if ( Storage :: exists ( $path . '/' . $filename )) {
try {
Storage :: delete ( $path . '/' . $filename );
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'success' , trans ( 'admin/settings/message.backup.file_deleted' ));
} catch ( \Exception $e ) {
2024-05-29 00:07:49 -07:00
Log :: debug ( $e );
2022-06-24 15:49:22 -07:00
}
} else {
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'admin/settings/message.backup.file_not_found' ));
2018-09-29 21:33:52 -07:00
}
2016-03-25 01:18:05 -07:00
}
2022-06-24 15:49:22 -07:00
2017-07-08 13:42:05 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
2016-03-25 01:18:05 -07:00
}
2022-06-24 15:49:22 -07:00
// Hell to the no
2024-07-04 12:49:22 -07:00
Log :: warning ( 'User ID ' . auth () -> id () . ' is attempting to delete backup file ' . $filename . ' and is not authorized to.' );
2022-06-24 15:49:22 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.backup_delete_not_allowed' ));
2016-03-25 01:18:05 -07:00
}
2016-04-19 04:36:07 -07:00
2021-11-10 00:07:17 -08:00
/**
* Uploads a backup file
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v6 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function postUploadBackup ( Request $request ) : RedirectResponse
{
2021-11-10 00:07:17 -08:00
2021-11-15 19:42:02 -08:00
if ( ! config ( 'app.lock_passwords' )) {
if ( ! $request -> hasFile ( 'file' )) {
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , 'No file uploaded' );
} else {
2021-11-10 00:07:17 -08:00
2023-10-31 08:30:38 -07:00
$max_file_size = Helper :: file_upload_max_size ();
$validator = Validator :: make ( $request -> all (), [
2021-11-15 19:42:02 -08:00
'file' => 'required|mimes:zip|max:' . $max_file_size ,
2023-10-31 08:30:38 -07:00
]);
2021-11-10 00:07:17 -08:00
2021-11-15 19:42:02 -08:00
if ( $validator -> passes ()) {
2021-11-10 00:07:17 -08:00
2021-11-15 19:42:02 -08:00
$upload_filename = 'uploaded-' . date ( 'U' ) . '-' . Str :: slug ( pathinfo ( $request -> file ( 'file' ) -> getClientOriginalName (), PATHINFO_FILENAME )) . '.zip' ;
2021-11-10 00:07:17 -08:00
2021-11-15 19:42:02 -08:00
Storage :: putFileAs ( 'app/backups' , $request -> file ( 'file' ), $upload_filename );
2024-05-29 00:07:49 -07:00
2021-11-15 19:42:02 -08:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'success' , 'File uploaded' );
}
2022-06-24 15:49:22 -07:00
2023-10-31 08:30:38 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> withErrors ( $validator );
2021-11-10 00:07:17 -08:00
}
2021-11-15 19:42:02 -08:00
} else {
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
2024-05-29 00:07:49 -07:00
}
2021-11-10 00:07:17 -08:00
}
/**
* Restore the backup file .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v6 . 0 ]
*/
2024-08-14 07:59:21 -07:00
public function postRestore ( Request $request , $filename = null ) : RedirectResponse
2021-11-10 00:07:17 -08:00
{
2024-05-29 00:07:49 -07:00
2021-11-10 00:07:17 -08:00
if ( ! config ( 'app.lock_passwords' )) {
$path = 'app/backups' ;
if ( Storage :: exists ( $path . '/' . $filename )) {
// grab the user's info so we can make sure they exist in the system
2024-07-04 12:49:22 -07:00
$user = User :: find ( auth () -> id ());
2021-11-10 00:07:17 -08:00
2022-02-17 14:59:44 -08:00
// TODO: run a backup
2021-11-10 01:43:45 -08:00
2022-05-17 04:27:48 -07:00
Artisan :: call ( 'db:wipe' , [
'--force' => true ,
]);
2021-11-10 01:43:45 -08:00
2024-05-29 00:07:49 -07:00
Log :: debug ( 'Attempting to restore from: ' . storage_path ( $path ) . '/' . $filename );
2022-05-17 09:41:35 -07:00
2024-08-14 07:59:21 -07:00
$restore_params = [
2024-05-29 00:07:49 -07:00
'--force' => true ,
'--no-progress' => true ,
2024-08-14 07:59:21 -07:00
'filename' => storage_path ( $path ) . '/' . $filename
];
if ( $request -> input ( 'clean' )) {
Log :: debug ( " Attempting 'clean' - first, guessing prefix... " );
Artisan :: call ( 'snipeit:restore' , [
'--sanitize-guess-prefix' => true ,
'filename' => storage_path ( $path ) . '/' . $filename
]);
$guess_prefix_output = Artisan :: output ();
Log :: debug ( " Sanitize output is: $guess_prefix_output " );
list ( $prefix , $_output ) = explode ( " \n " , $guess_prefix_output );
Log :: debug ( " prefix is: ' $prefix ' " );
$restore_params [ '--sanitize-with-prefix' ] = $prefix ;
}
// run the restore command
Artisan :: call ( 'snipeit:restore' ,
$restore_params
);
2021-11-10 00:07:17 -08:00
// If it's greater than 300, it probably worked
2022-02-17 14:59:44 -08:00
$output = Artisan :: output ();
2022-05-18 14:12:17 -07:00
2022-07-08 16:40:51 -07:00
/* Run migrations */
2024-05-29 00:07:49 -07:00
Log :: debug ( 'Migrating database...' );
2022-07-08 16:40:51 -07:00
Artisan :: call ( 'migrate' , [ '--force' => true ]);
$migrate_output = Artisan :: output ();
2024-05-29 00:07:49 -07:00
Log :: debug ( $migrate_output );
2022-07-08 16:40:51 -07:00
2022-07-08 17:09:56 -07:00
$find_user = DB :: table ( 'users' ) -> where ( 'username' , $user -> username ) -> exists ();
2024-05-29 00:07:49 -07:00
2022-07-08 17:09:56 -07:00
if ( ! $find_user ){
2024-05-29 00:07:49 -07:00
Log :: warning ( 'Attempting to restore user: ' . $user -> username );
2022-07-08 17:09:56 -07:00
$new_user = $user -> replicate ();
$new_user -> push ();
} else {
2024-05-29 00:07:49 -07:00
Log :: debug ( 'User: ' . $user -> username . ' already exists.' );
2022-07-08 17:09:56 -07:00
}
2022-02-17 16:00:24 -08:00
2024-05-29 00:07:49 -07:00
Log :: debug ( 'Logging all users out..' );
2022-07-08 17:09:56 -07:00
Artisan :: call ( 'snipeit:global-logout' , [ '--force' => true ]);
2022-05-18 14:12:17 -07:00
2022-07-08 17:09:56 -07:00
DB :: table ( 'users' ) -> update ([ 'remember_token' => null ]);
2024-05-29 00:07:49 -07:00
Auth :: logout ();
2022-02-17 16:00:24 -08:00
2024-07-26 08:47:40 -07:00
return redirect () -> route ( 'login' ) -> with ( 'success' , trans ( 'admin/settings/message.restore.success' ));
2021-11-10 00:07:17 -08:00
} else {
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'admin/settings/message.backup.file_not_found' ));
}
} else {
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
}
}
2017-07-07 23:44:48 -07:00
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2018-10-03 10:06:24 -07:00
*
2017-07-07 23:44:48 -07:00
* @ since [ v4 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function getPurge () : View | RedirectResponse
2017-07-07 23:44:48 -07:00
{
2022-06-23 20:11:43 -07:00
2024-07-04 14:52:49 -07:00
Log :: warning ( 'User ' . auth () -> user () -> username . ' (ID: ' . auth () -> id () . ') is attempting a PURGE' );
2022-06-24 15:49:22 -07:00
if ( config ( 'app.allow_purge' ) == 'true' ) {
2022-06-23 20:11:43 -07:00
return view ( 'settings.purge-form' );
}
2022-06-24 15:49:22 -07:00
return redirect () -> route ( 'settings.index' ) -> with ( 'error' , trans ( 'general.purge_not_allowed' ));
2017-07-07 23:44:48 -07:00
}
2016-04-19 04:36:07 -07:00
/**
2018-10-03 10:06:24 -07:00
* Purges soft - deletes .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function postPurge ( Request $request ) : RedirectResponse
2016-04-19 04:36:07 -07:00
{
2024-07-04 12:49:22 -07:00
Log :: warning ( 'User ' . auth () -> user () -> username . ' (ID' . auth () -> id () . ') is attempting a PURGE' );
2022-06-24 15:49:22 -07:00
2022-06-23 20:11:43 -07:00
if ( config ( 'app.allow_purge' ) == 'true' ) {
2024-05-29 00:07:49 -07:00
Log :: debug ( 'Purging is not allowed via the .env' );
2022-06-24 15:49:22 -07:00
2022-06-23 20:11:43 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2022-06-24 15:49:22 -07:00
if ( $request -> input ( 'confirm_purge' ) == 'DELETE' ) {
2024-07-04 12:49:22 -07:00
Log :: warning ( 'User ID ' . auth () -> id () . ' initiated a PURGE!' );
2022-06-23 20:11:43 -07:00
// Run a backup immediately before processing
Artisan :: call ( 'backup:run' );
Artisan :: call ( 'snipeit:purge' , [ '--force' => 'true' , '--no-interaction' => true ]);
$output = Artisan :: output ();
2022-06-24 15:49:22 -07:00
return redirect () -> route ( 'settings.index' )
2022-06-23 20:11:43 -07:00
-> with ( 'output' , $output ) -> with ( 'success' , trans ( 'admin/settings/message.purge.success' ));
} else {
2022-06-24 15:49:22 -07:00
return redirect () -> route ( 'settings.purge.index' )
-> with ( 'error' , trans ( 'admin/settings/message.purge.validation_failed' ));
2022-06-23 20:11:43 -07:00
}
2016-04-19 04:36:07 -07:00
} else {
2022-06-24 15:49:22 -07:00
return redirect () -> route ( 'settings.index' )
-> with ( 'error' , trans ( 'general.feature_disabled' ));
2016-04-19 04:36:07 -07:00
}
}
2022-06-24 15:49:22 -07:00
2024-07-04 12:49:22 -07:00
Log :: error ( 'User ' . auth () -> user () -> username . ' (ID' . auth () -> id () . ') is attempting to purge deleted data and is not authorized to.' );
2022-06-24 15:49:22 -07:00
// Nope.
return redirect () -> route ( 'settings.index' )
-> with ( 'error' , trans ( 'general.purge_not_allowed' ));
2016-04-19 04:36:07 -07:00
}
2017-01-24 17:37:07 -08:00
/**
* Returns a page with the API token generation interface .
*
* We created a controller method for this because closures aren ' t allowed
* in the routes file if you want to be able to cache the routes .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function api () : View
2018-10-03 10:06:24 -07:00
{
2017-07-07 23:44:48 -07:00
return view ( 'settings.api' );
2017-01-24 17:37:07 -08:00
}
2017-10-19 06:16:03 -07:00
/**
2018-10-03 10:06:24 -07:00
* Test the email configuration .
2017-10-19 06:16:03 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
*/
2024-07-04 14:52:49 -07:00
public function ajaxTestEmail () : JsonResponse
2017-10-19 06:16:03 -07:00
{
try {
2018-10-03 10:06:24 -07:00
( new User ()) -> forceFill ([
'name' => config ( 'mail.from.name' ),
'email' => config ( 'mail.from.address' ),
2018-08-02 21:36:18 -07:00
]) -> notify ( new MailTest ());
2024-07-04 12:49:22 -07:00
return response () -> json ( Helper :: formatStandardApiResponse ( 'success' , null , trans ( 'mail_sent.mail_sent' )));
2024-05-29 00:07:49 -07:00
} catch ( \Exception $e ) {
2017-10-19 08:18:56 -07:00
return response () -> json ( Helper :: formatStandardApiResponse ( 'success' , null , $e -> getMessage ()));
2017-10-19 06:16:03 -07:00
}
}
2024-07-04 12:49:22 -07:00
/**
* Get login attempts view
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
*/
2024-07-04 14:52:49 -07:00
public function getLoginAttempts () : View
2018-10-03 10:06:24 -07:00
{
2018-08-01 03:51:59 -07:00
return view ( 'settings.logins' );
2017-10-19 06:16:03 -07:00
}
2020-08-14 02:10:19 -07:00
}