2016-03-25 01:18:05 -07:00
< ? php
namespace App\Http\Controllers ;
2018-08-02 21:36:18 -07:00
use App\Notifications\MailTest ;
2016-03-25 01:18:05 -07:00
use Input ;
use Lang ;
2016-12-27 17:31:53 -08:00
use Illuminate\Http\Request ;
2016-03-25 01:18:05 -07:00
use App\Models\Setting ;
2016-07-13 05:50:40 -07:00
use App\Models\Ldap ;
2016-03-25 01:18:05 -07:00
use Redirect ;
use DB ;
use Str ;
use View ;
use Image ;
use Config ;
use Response ;
use Artisan ;
use Crypt ;
use Mail ;
2016-11-29 01:19:25 -08:00
use Auth ;
2016-03-25 19:26:22 -07:00
use App\Models\User ;
2016-03-25 01:18:05 -07:00
use App\Http\Requests\SetupUserRequest ;
2016-12-27 17:31:53 -08:00
use App\Http\Requests\ImageUploadRequest ;
2017-08-31 13:45:48 -07:00
use App\Http\Requests\SettingsLdapRequest ;
2017-10-19 08:18:56 -07:00
use App\Helpers\Helper ;
2018-03-03 14:37:42 -08:00
use App\Notifications\FirstAdminNotification ;
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
{
/**
* 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 ]
* @ return View
*/
public function getSetupIndex ()
{
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' ), '<' )) {
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 );
}
2016-03-25 01:18:05 -07:00
try {
$conn = DB :: select ( 'select 2 + 2' );
$start_settings [ 'db_conn' ] = true ;
$start_settings [ 'db_name' ] = DB :: connection () -> getDatabaseName ();
$start_settings [ 'db_error' ] = null ;
} catch ( \PDOException $e ) {
$start_settings [ 'db_conn' ] = false ;
$start_settings [ 'db_name' ] = config ( 'database.connections.mysql.database' );
$start_settings [ 'db_error' ] = $e -> getMessage ();
}
2016-06-22 12:27:41 -07:00
$protocol = array_key_exists ( 'HTTPS' , $_SERVER ) && ( $_SERVER [ 'HTTPS' ] == " on " ) ? 'https://' : 'http://' ;
2016-05-14 15:04:59 -07:00
2018-02-22 21:46:58 -08:00
$host = array_key_exists ( 'SERVER_NAME' , $_SERVER ) ? $_SERVER [ 'SERVER_NAME' ] : null ;
$port = array_key_exists ( 'SERVER_PORT' , $_SERVER ) ? $_SERVER [ 'SERVER_PORT' ] : null ;
if (( $protocol === 'http://' && $port != '80' ) || ( $protocol === 'https://' && $port != '443' )) {
$host .= ':' . $port ;
2016-03-25 01:18:05 -07:00
}
2016-09-26 18:23:56 -07:00
$pageURL = $protocol . $host . $_SERVER [ 'REQUEST_URI' ];
2016-03-25 01:18:05 -07:00
2016-12-15 16:42:14 -08:00
$start_settings [ 'url_valid' ] = ( url ( '/' ) . '/setup' === $pageURL );
2016-03-25 01:18:05 -07:00
2016-12-15 16:42:14 -08:00
$start_settings [ 'url_config' ] = url ( '/' );
2016-09-26 18:23:56 -07:00
$start_settings [ 'real_url' ] = $pageURL ;
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
$ch = curl_init ( $protocol . $host . '/.env' );
curl_setopt ( $ch , CURLOPT_HEADER , true ); // we want headers
curl_setopt ( $ch , CURLOPT_NOBODY , true ); // we don't need body
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 10 );
$output = curl_exec ( $ch );
$httpcode = curl_getinfo ( $ch , CURLINFO_HTTP_CODE );
curl_close ( $ch );
2016-03-25 01:18:05 -07:00
2018-08-02 21:36:18 -07:00
if ( $httpcode == 404 || $httpcode == 403 || $httpcode == 0 ) {
2016-03-25 01:18:05 -07:00
$start_settings [ 'env_exposed' ] = false ;
2017-06-01 20:41:23 -07:00
} else {
$start_settings [ 'env_exposed' ] = true ;
2016-03-25 01:18:05 -07:00
}
2017-06-01 20:41:23 -07:00
2016-03-25 01:18:05 -07:00
if ( \App :: Environment ( 'production' ) && ( config ( 'app.debug' ) == true )) {
$start_settings [ 'debug_exposed' ] = true ;
} else {
$start_settings [ 'debug_exposed' ] = false ;
}
$environment = app () -> environment ();
if ( $environment != 'production' ) {
$start_settings [ 'env' ] = $environment ;
$start_settings [ 'prod' ] = false ;
} else {
$start_settings [ 'env' ] = $environment ;
$start_settings [ 'prod' ] = true ;
}
2016-06-22 12:27:41 -07:00
if ( function_exists ( 'posix_getpwuid' )) { // Probably Linux
2016-06-06 05:37:45 -07:00
$owner = posix_getpwuid ( fileowner ( $_SERVER [ " SCRIPT_FILENAME " ]));
$start_settings [ 'owner' ] = $owner [ 'name' ];
} else { // Windows
// TODO: Is there a way of knowing if a windows user has elevated permissions
// This just gets the user name, which likely isn't 'root'
// $start_settings['owner'] = getenv('USERNAME');
$start_settings [ 'owner' ] = '' ;
}
2016-03-25 01:18:05 -07:00
2016-06-06 05:37:45 -07: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 ;
}
if (( is_writable ( storage_path ()))
&& ( is_writable ( storage_path () . '/framework' ))
&& ( is_writable ( storage_path () . '/framework/cache' ))
&& ( is_writable ( storage_path () . '/framework/sessions' ))
&& ( is_writable ( storage_path () . '/framework/views' ))
&& ( is_writable ( storage_path () . '/logs' ))
) {
$start_settings [ 'writable' ] = true ;
} else {
$start_settings [ 'writable' ] = false ;
}
$start_settings [ 'gd' ] = extension_loaded ( 'gd' );
2017-06-09 16:44:03 -07:00
return view ( 'setup/index' )
2016-03-25 01:18:05 -07:00
-> with ( 'step' , 1 )
-> with ( 'start_settings' , $start_settings )
-> with ( 'section' , 'Pre-Flight Check' );
}
/**
* Save the first admin user from Setup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return Redirect
*/
public function postSaveFirstAdmin ( SetupUserRequest $request )
{
2016-03-25 19:26:22 -07:00
$user = new User ;
2018-01-17 10:58:03 -08:00
$user -> first_name = $data [ 'first_name' ] = $request -> input ( 'first_name' );
$user -> last_name = $request -> input ( 'last_name' );
$user -> email = $data [ 'email' ] = $request -> input ( 'email' );
2016-03-25 01:18:05 -07:00
$user -> activated = 1 ;
2016-05-14 15:04:59 -07:00
$permissions = array ( 'superuser' => 1 );
$user -> permissions = json_encode ( $permissions );
2018-01-17 10:58:03 -08: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
2016-03-25 19:26:22 -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 );
$settings -> site_name = $request -> input ( 'site_name' );
$settings -> alert_email = $request -> input ( 'email' );
2016-03-25 01:18:05 -07:00
$settings -> alerts_enabled = 1 ;
2017-08-25 08:30:48 -07:00
$settings -> pwd_secure_min = 10 ;
2016-03-25 01:18:05 -07:00
$settings -> brand = 1 ;
2018-07-24 13:37:02 -07:00
$settings -> locale = $request -> input ( 'locale' , 'en' );
2018-01-17 10:58:03 -08:00
$settings -> default_currency = $request -> input ( 'default_currency' , " USD " );
2016-03-25 01:18:05 -07:00
$settings -> user_id = 1 ;
2018-01-17 10:58:03 -08:00
$settings -> email_domain = $request -> input ( 'email_domain' );
$settings -> email_format = $request -> input ( 'email_format' );
2017-06-20 12:19:05 -07:00
$settings -> next_auto_tag_base = 1 ;
2018-01-17 10:58:03 -08:00
$settings -> auto_increment_assets = $request -> input ( 'auto_increment_assets' , 0 );
$settings -> auto_increment_prefix = $request -> input ( 'auto_increment_prefix' );
2016-03-25 01:18:05 -07:00
2016-06-01 15:45:26 -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
2016-03-25 01:18:05 -07:00
if ( Input :: get ( 'email_creds' ) == '1' ) {
2018-03-03 14:37:42 -08:00
$data = array ();
$data [ 'email' ] = $user -> email ;
$data [ 'username' ] = $user -> username ;
$data [ 'first_name' ] = $user -> first_name ;
$data [ 'last_name' ] = $user -> last_name ;
2018-05-02 14:40:41 -07:00
$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
}
2016-06-01 15:45:26 -07:00
2016-11-29 01:19:25 -08:00
2016-03-25 01:18:05 -07:00
return redirect () -> route ( 'setup.done' );
}
}
/**
* Return the admin user creation form in Setup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return View
*/
public function getSetupUser ()
{
2017-06-09 16:44:03 -07:00
return view ( 'setup/user' )
2016-03-25 01:18:05 -07:00
-> with ( 'step' , 3 )
-> with ( 'section' , 'Create a User' );
}
/**
* Return the view that tells the user that the Setup is done .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return View
*/
public function getSetupDone ()
{
2016-11-29 01:19:25 -08:00
2017-06-09 16:44:03 -07:00
return view ( 'setup/done' )
2016-03-25 01:18:05 -07:00
-> with ( 'step' , 4 )
-> with ( 'section' , 'Done!' );
}
/**
* Migrate the database tables , and return the output
* to a view for Setup
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return View
*/
public function getSetupMigrate ()
{
Artisan :: call ( 'migrate' , [ '--force' => true ]);
$output = Artisan :: output ();
2017-08-22 22:46:02 -07:00
if (( ! file_exists ( storage_path () . '/oauth-private.key' )) || ( ! file_exists ( storage_path () . '/oauth-public.key' ))) {
Artisan :: call ( 'migrate' , [ '--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' )
2016-03-25 01:18:05 -07:00
-> with ( 'output' , $output )
-> with ( 'step' , 2 )
-> with ( 'section' , 'Create Database Tables' );
}
/**
* Return a view that shows some of the key settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
2017-07-07 23:44:48 -07:00
public function index ()
2016-03-25 01:18:05 -07:00
{
$settings = Setting :: all ();
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 the admin settings page
2016-03-25 01:18:05 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getEdit ()
{
$setting = Setting :: first ();
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 > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getSettings ()
{
$setting = Setting :: first ();
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 > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postSettings ( Request $request )
2016-03-25 01:18:05 -07:00
{
2016-06-01 15:50:50 -07:00
if ( is_null ( $setting = Setting :: first ())) {
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 = '' ;
2018-07-24 22:51:31 -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' );
$setting -> load_remote = $request -> input ( 'load_remote' , '0' );
2018-07-05 19:30:36 -07:00
$setting -> unique_serial = $request -> input ( 'unique_serial' , '0' );
2018-03-25 13:46:57 -07:00
$setting -> show_images_in_email = $request -> input ( 'show_images_in_email' , '0' );
2018-01-17 19:18:48 -08:00
$setting -> show_archived_in_list = $request -> input ( 'show_archived_in_list' , '0' );
2018-01-19 20:43:55 -08:00
$setting -> dashboard_message = $request -> input ( 'dashboard_message' );
2017-07-07 23:44:48 -07:00
$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' );
2017-09-27 16:35:54 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2017-09-22 17:23:22 -07:00
$setting -> login_note = $request -> input ( 'login_note' );
}
2017-07-07 23:44:48 -07:00
$setting -> default_eula_text = $request -> input ( 'default_eula_text' );
2017-07-25 19:36:38 -07:00
$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' );
2017-07-07 23:44:48 -07:00
2018-08-23 10:49:20 -07:00
$setting -> depreciation_method = $request -> input ( 'depreciation_method' );
2017-07-07 23:44:48 -07:00
if ( Input :: get ( 'per_page' ) != '' ) {
$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' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
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 > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getBranding ()
{
$setting = Setting :: first ();
return view ( 'settings.branding' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postBranding ( ImageUploadRequest $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
$setting -> brand = $request -> input ( 'brand' , '1' );
$setting -> header_color = $request -> input ( 'header_color' );
2018-01-24 07:02:30 -08:00
$setting -> support_footer = $request -> input ( 'support_footer' );
2018-06-21 07:12:16 -07:00
$setting -> version_footer = $request -> input ( 'version_footer' );
2018-01-24 07:02:30 -08:00
$setting -> footer_text = $request -> input ( 'footer_text' );
2018-03-02 17:50:40 -08:00
$setting -> skin = $request -> input ( 'skin' );
2017-10-17 13:54:03 -07:00
$setting -> show_url_in_emails = $request -> input ( 'show_url_in_emails' , '0' );
2018-07-24 13:37:02 -07:00
$setting -> logo_print_assets = $request -> input ( 'logo_print_assets' , '0' );
2017-07-07 23:44:48 -07:00
// Only allow the site name and CSS to be changed if lock_passwords is false
// Because public demos make people act like dicks
2016-10-29 05:50:55 -07:00
if ( ! config ( 'app.lock_passwords' )) {
2017-07-07 18:06:31 -07:00
$setting -> site_name = $request -> input ( 'site_name' );
$setting -> custom_css = $request -> input ( 'custom_css' );
2017-07-07 23:44:48 -07:00
}
// If the user wants to clear the logo, reset the brand type
if ( $request -> input ( 'clear_logo' ) == '1' ) {
$setting -> logo = null ;
$setting -> brand = 1 ;
// If they are uploading an image, validate it and upload it
2018-07-24 22:52:49 -07:00
} elseif ( $request -> hasFile ( 'image' )) {
2017-07-07 23:44:48 -07:00
if ( ! config ( 'app.lock_passwords' )) {
$image = $request -> file ( 'image' );
$file_name = " logo. " . $image -> getClientOriginalExtension ();
$path = public_path ( 'uploads' );
if ( $image -> getClientOriginalExtension () != 'svg' ) {
2017-10-03 14:15:03 -07:00
Image :: make ( $image -> getRealPath ()) -> resize ( null , 150 , function ( $constraint ) {
2017-07-07 23:44:48 -07:00
$constraint -> aspectRatio ();
$constraint -> upsize ();
}) -> save ( $path . '/' . $file_name );
} else {
$image -> move ( $path , $file_name );
}
$setting -> logo = $file_name ;
}
}
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getSecurity ()
{
$setting = Setting :: first ();
return view ( 'settings.security' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postSecurity ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
if ( ! config ( 'app.lock_passwords' )) {
2016-10-31 13:50:00 -07:00
2017-07-07 18:06:31 -07:00
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' );
2018-05-31 10:53:56 -07:00
# remote user login
$setting -> login_remote_user_enabled = ( int ) $request -> input ( 'login_remote_user_enabled' );
$setting -> login_common_disabled = ( int ) $request -> input ( 'login_common_disabled' );
$setting -> login_remote_user_custom_logout_url = $request -> input ( 'login_remote_user_custom_logout_url' );
2016-10-31 13:50:00 -07:00
}
2016-03-25 01:18:05 -07:00
}
2017-08-22 20:32:39 -07:00
$setting -> pwd_secure_uncommon = ( int ) $request -> input ( 'pwd_secure_uncommon' );
$setting -> pwd_secure_min = ( int ) $request -> input ( 'pwd_secure_min' );
$setting -> pwd_secure_complexity = '' ;
2018-03-14 12:48:07 -07:00
2018-07-24 22:51:31 -07:00
if ( $request -> filled ( 'pwd_secure_complexity' )) {
2017-08-22 20:32:39 -07:00
$setting -> pwd_secure_complexity = implode ( '|' , $request -> input ( 'pwd_secure_complexity' ));
}
2017-07-07 23:44:48 -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 ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getLocalization ()
{
$setting = Setting :: first ();
return view ( 'settings.localization' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postLocalization ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
2016-03-25 01:18:05 -07:00
}
2018-07-24 13:37:02 -07:00
if ( ! config ( 'app.lock_passwords' )) {
$setting -> locale = $request -> input ( 'locale' , 'en' );
}
2017-07-07 23:44:48 -07:00
$setting -> default_currency = $request -> input ( 'default_currency' , '$' );
$setting -> date_display_format = $request -> input ( 'date_display_format' );
$setting -> time_display_format = $request -> input ( 'time_display_format' );
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getAlerts ()
{
$setting = Setting :: first ();
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 ]
* @ return View
*/
public function postAlerts ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
$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
2017-08-25 18:40:20 -07:00
$setting -> alert_email = $alert_email ;
2018-03-25 13:46:57 -07:00
$setting -> admin_cc_email = $admin_cc_email ;
2017-07-07 23:44:48 -07:00
$setting -> alerts_enabled = $request -> input ( 'alerts_enabled' , '0' );
$setting -> alert_interval = $request -> input ( 'alert_interval' );
$setting -> alert_threshold = $request -> input ( 'alert_threshold' );
2017-08-25 18:40:20 -07:00
$setting -> audit_interval = $request -> input ( 'audit_interval' );
$setting -> audit_warning_days = $request -> input ( 'audit_warning_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' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getSlack ()
{
$setting = Setting :: first ();
return view ( 'settings.slack' , compact ( 'setting' ));
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postSlack ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
$setting -> slack_endpoint = $request -> input ( 'slack_endpoint' );
$setting -> slack_channel = $request -> input ( 'slack_channel' );
$setting -> slack_botname = $request -> input ( 'slack_botname' );
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getAssetTags ()
{
$setting = Setting :: first ();
return view ( 'settings.asset_tags' , compact ( 'setting' ));
}
/**
* Saves settings from form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postAssetTags ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
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' );
$setting -> zerofill_count = $request -> input ( 'zerofill_count' );
$setting -> next_auto_tag_base = $request -> input ( 'next_auto_tag_base' );
if ( $setting -> save ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function getBarcodes ()
{
$setting = Setting :: first ();
$is_gd_installed = extension_loaded ( 'gd' );
return view ( 'settings.barcodes' , compact ( 'setting' )) -> with ( 'is_gd_installed' , $is_gd_installed );
}
/**
* Saves settings from form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return View
*/
public function postBarcodes ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2017-07-07 18:06:31 -07:00
$setting -> qr_code = $request -> input ( 'qr_code' , '0' );
$setting -> alt_barcode = $request -> input ( 'alt_barcode' );
$setting -> alt_barcode_enabled = $request -> input ( 'alt_barcode_enabled' , '0' );
$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' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
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 > ]
* @ since [ v4 . 0 ]
* @ return View
*/
public function getPhpInfo ()
{
2017-07-08 00:22:30 -07:00
if ( config ( 'app.debug' ) === true ) {
return view ( 'settings.phpinfo' );
}
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 ]
* @ return View
*/
public function getLabels ()
{
$setting = Setting :: first ();
return view ( 'settings.labels' , compact ( 'setting' ));
}
/**
* Saves settings from form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return View
*/
public function postLabels ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2017-07-07 18:06:31 -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' );
2017-07-07 23:44:48 -07:00
2016-03-25 01:18:05 -07:00
2016-10-31 13:50:00 -07:00
2018-07-24 22:51:31 -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 ;
}
2018-07-24 22:51:31 -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 ;
}
2018-07-24 22:51:31 -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 ;
2018-07-24 12:09:57 -07:00
}
2018-07-12 18:23:12 -07:00
2018-07-24 22:51:31 -07:00
if ( $request -> filled ( 'labels_display_tag' )) {
2018-07-12 18:23:12 -07:00
$setting -> labels_display_tag = 1 ;
} else {
$setting -> labels_display_tag = 0 ;
}
2016-03-25 01:18:05 -07:00
2018-07-24 22:51:31 -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 ()) {
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
}
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
}
/**
* Return a form to allow a super admin to update settings .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return View
*/
public function getLdapSettings ()
{
$setting = Setting :: first ();
return view ( 'settings.ldap' , compact ( 'setting' ));
}
/**
* Saves settings from form
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return View
*/
public function postLdapSettings ( Request $request )
{
if ( is_null ( $setting = Setting :: first ())) {
return redirect () -> to ( 'admin' ) -> with ( 'error' , trans ( 'admin/settings/message.update.error' ));
}
2016-03-25 01:18:05 -07:00
2017-07-07 18:06:31 -07:00
$setting -> ldap_enabled = $request -> input ( 'ldap_enabled' , '0' );
$setting -> ldap_server = $request -> input ( 'ldap_server' );
$setting -> ldap_server_cert_ignore = $request -> input ( 'ldap_server_cert_ignore' , false );
$setting -> ldap_uname = $request -> input ( 'ldap_uname' );
2016-03-25 01:18:05 -07:00
if ( Input :: has ( 'ldap_pword' )) {
2017-07-07 18:06:31 -07:00
$setting -> ldap_pword = Crypt :: encrypt ( $request -> input ( 'ldap_pword' ));
2016-03-25 01:18:05 -07:00
}
2017-07-07 18:06:31 -07:00
$setting -> ldap_basedn = $request -> input ( 'ldap_basedn' );
$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' );
$setting -> ldap_auth_filter_query = $request -> input ( 'ldap_auth_filter_query' );
$setting -> ldap_version = $request -> input ( 'ldap_version' );
$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' );
$setting -> ad_domain = $request -> input ( 'ad_domain' );
$setting -> is_ad = $request -> input ( 'is_ad' , '0' );
$setting -> ldap_tls = $request -> input ( 'ldap_tls' , '0' );
$setting -> ldap_pw_sync = $request -> input ( 'ldap_pw_sync' , '0' );
2017-10-19 12:22:27 -07:00
$setting -> custom_forgot_pass_url = $request -> input ( 'custom_forgot_pass_url' );
2017-07-07 18:06:31 -07:00
2016-03-25 01:18:05 -07:00
if ( $setting -> save ()) {
2017-07-07 23:44:48 -07:00
return redirect () -> route ( 'settings.index' )
-> with ( 'success' , trans ( 'admin/settings/message.update.success' ));
2016-03-25 01:18:05 -07:00
}
2017-07-07 23:44:48 -07:00
return redirect () -> back () -> withInput () -> withErrors ( $setting -> getErrors ());
2016-03-25 01:18:05 -07:00
}
2016-07-13 05:50:40 -07:00
2016-03-25 01:18:05 -07:00
/**
* Show the listing of backups
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
* @ return View
*/
public function getBackups ()
{
2016-03-25 15:50:08 -07:00
2018-07-25 01:36:30 -07:00
$path = storage_path () . '/app/' . config ( 'backup.backup.name' );
2016-03-25 15:50:08 -07:00
2016-03-25 01:18:05 -07:00
$files = array ();
if ( $handle = opendir ( $path )) {
/* This is the correct way to loop over the directory. */
while ( false !== ( $entry = readdir ( $handle ))) {
clearstatcache ();
if ( substr ( strrchr ( $entry , '.' ), 1 ) == 'zip' ) {
$files [] = array (
'filename' => $entry ,
'filesize' => Setting :: fileSizeConvert ( filesize ( $path . '/' . $entry )),
'modified' => filemtime ( $path . '/' . $entry )
);
}
}
closedir ( $handle );
2016-09-17 11:39:24 -07:00
rsort ( $files );
2016-03-25 01:18:05 -07:00
}
2017-06-09 16:44:03 -07:00
return view ( 'settings/backups' , compact ( 'path' , 'files' ));
2016-03-25 01:18:05 -07:00
}
/**
* Process the backup .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
* @ return Redirect
*/
public function postBackups ()
{
2017-11-01 14:12:18 -07:00
2016-03-25 01:18:05 -07:00
if ( ! config ( 'app.lock_passwords' )) {
Artisan :: call ( 'backup:run' );
2017-11-01 14:12:18 -07:00
$output = Artisan :: output ();
// Backup completed
if ( ! preg_match ( '/failed/' , $output )) {
return redirect () -> route ( 'settings.backups.index' )
-> with ( 'success' , trans ( 'admin/settings/message.backup.generated' ));
}
$formatted_output = str_replace ( 'Backup completed!' , '' , $output );
$output_split = explode ( '...' , $formatted_output );
if ( array_key_exists ( 2 , $output_split )) {
return redirect () -> route ( " settings.backups.index " ) -> with ( 'error' , $output_split [ 2 ]);
}
return redirect () -> route ( " settings.backups.index " ) -> with ( 'error' , $formatted_output );
}
return redirect () -> route ( " settings.backups.index " ) -> with ( 'error' , trans ( 'general.feature_disabled' ));
2016-03-25 01:18:05 -07:00
}
/**
* Download the backup file
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
* @ return Redirect
*/
public function downloadFile ( $filename = null )
{
if ( ! config ( 'app.lock_passwords' )) {
2018-07-25 01:36:30 -07:00
$path = storage_path () . '/app/' . config ( 'backup.backup.name' );
2016-03-25 01:18:05 -07:00
$file = $path . '/' . $filename ;
if ( file_exists ( $file )) {
return Response :: download ( $file );
} 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
}
}
/**
* Delete the backup file
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 8 ]
* @ return View
*/
public function deleteFile ( $filename = null )
{
if ( ! config ( 'app.lock_passwords' )) {
2018-07-25 01:36:30 -07:00
$path = storage_path () . '/app/' . config ( 'backup.backup.name' );
2016-05-12 16:20:23 -07:00
$file = $path . '/' . $filename ;
2016-03-25 01:18:05 -07:00
if ( file_exists ( $file )) {
unlink ( $file );
2017-07-08 13:42:05 -07:00
return redirect () -> route ( 'settings.backups.index' ) -> with ( 'success' , trans ( 'admin/settings/message.backup.file_deleted' ));
2016-03-25 01:18:05 -07:00
} else {
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 {
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
}
}
2016-04-19 04:36:07 -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 ]
* @ return View
*/
public function getPurge ()
{
return view ( 'settings.purge-form' );
}
2016-04-19 04:36:07 -07:00
/**
* Purges soft - deletes
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return View
*/
public function postPurge ()
{
if ( ! config ( 'app.lock_passwords' )) {
if ( Input :: get ( 'confirm_purge' ) == 'DELETE' ) {
2017-09-25 15:00:23 -07:00
// Run a backup immediately before processing
Artisan :: call ( 'backup:run' );
2016-06-22 12:27:41 -07:00
Artisan :: call ( 'snipeit:purge' , [ '--force' => 'true' , '--no-interaction' => true ]);
2016-04-19 04:36:07 -07:00
$output = Artisan :: output ();
2017-06-09 16:44:03 -07:00
return view ( 'settings/purge' )
2016-04-19 04:36:07 -07:00
-> with ( 'output' , $output ) -> with ( 'success' , trans ( 'admin/settings/message.purge.success' ));
} else {
2016-04-28 21:06:41 -07:00
return redirect () -> back () -> with ( 'error' , trans ( 'admin/settings/message.purge.validation_failed' ));
2016-04-19 04:36:07 -07:00
}
} else {
2016-04-28 21:06:41 -07:00
return redirect () -> back () -> with ( 'error' , trans ( 'general.feature_disabled' ));
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 ]
* @ return View
*/
public function api () {
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
/**
* Test the email configuration
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return Redirect
*/
public function ajaxTestEmail ()
{
try {
2018-08-02 21:36:18 -07:00
( new User ) -> forceFill ([
'name' => config ( 'mail.from.name' ),
'email' => config ( 'mail.from.address' )
]) -> notify ( new MailTest ());
2017-10-19 08:18:56 -07:00
return response () -> json ( Helper :: formatStandardApiResponse ( 'success' , null , 'Maiol sent!' ));
2017-10-19 06:16:03 -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
}
}
2018-08-01 03:51:59 -07:00
public function getLoginAttempts () {
return view ( 'settings.logins' );
}
2016-03-25 01:18:05 -07:00
}