2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-26 18:23:56 -07:00
|
|
|
$host = $_SERVER['SERVER_NAME'];
|
|
|
|
if (($protocol === 'http://' && $_SERVER['SERVER_PORT'] != '80') || ($protocol === 'https://' && $_SERVER['SERVER_PORT'] != '443')) {
|
2016-12-29 14:02:18 -08:00
|
|
|
$host .= ':' . $_SERVER['SERVER_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;
|
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
|
|
|
|
2017-06-01 20:41:23 -07:00
|
|
|
if ($httpcode == 404 || $httpcode == 403) {
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the email configuration
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.0]
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
|
|
|
public function ajaxTestEmail()
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
Mail::send('emails.test', [], function ($m) {
|
|
|
|
$m->to(config('mail.from.address'), config('mail.from.name'));
|
2016-09-20 07:20:10 -07:00
|
|
|
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
2016-09-26 14:13:07 -07:00
|
|
|
$m->subject(trans('mail.test_email'));
|
2016-03-25 01:18:05 -07:00
|
|
|
});
|
|
|
|
return 'success';
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2016-03-25 01:18:05 -07:00
|
|
|
$user->first_name = $data['first_name']= e(Input::get('first_name'));
|
|
|
|
$user->last_name = e(Input::get('last_name'));
|
|
|
|
$user->email = $data['email'] = e(Input::get('email'));
|
|
|
|
$user->activated = 1;
|
2016-05-14 15:04:59 -07:00
|
|
|
$permissions = array('superuser' => 1);
|
|
|
|
$user->permissions = json_encode($permissions);
|
2016-03-25 01:18:05 -07:00
|
|
|
$user->username = $data['username'] = e(Input::get('username'));
|
|
|
|
$user->password = bcrypt(Input::get('password'));
|
|
|
|
$data['password'] = Input::get('password');
|
|
|
|
|
2016-03-25 19:26:22 -07:00
|
|
|
$settings = new Setting;
|
2016-03-25 01:18:05 -07:00
|
|
|
$settings->site_name = e(Input::get('site_name'));
|
|
|
|
$settings->alert_email = e(Input::get('email'));
|
|
|
|
$settings->alerts_enabled = 1;
|
|
|
|
$settings->brand = 1;
|
2016-06-01 15:45:26 -07:00
|
|
|
$settings->locale = 'en';
|
2016-03-25 01:18:05 -07:00
|
|
|
$settings->default_currency = 'USD';
|
|
|
|
$settings->user_id = 1;
|
2016-06-01 15:45:26 -07:00
|
|
|
$settings->email_domain = e(Input::get('email_domain'));
|
|
|
|
$settings->email_format = e(Input::get('email_format'));
|
2017-06-20 12:19:05 -07:00
|
|
|
$settings->next_auto_tag_base = 1;
|
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') {
|
|
|
|
Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use ($data) {
|
|
|
|
$m->to($data['email'], $data['first_name']);
|
2016-09-20 07:20:10 -07:00
|
|
|
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
2016-09-26 14:13:07 -07:00
|
|
|
$m->subject(trans('mail.your_credentials'));
|
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-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
|
|
|
|
*/
|
|
|
|
public function getIndex()
|
|
|
|
{
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a form to allow a super admin to update settings.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function getEdit()
|
|
|
|
{
|
|
|
|
$setting = Setting::first();
|
|
|
|
$is_gd_installed = extension_loaded('gd');
|
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('settings/edit', compact('setting'))->with('is_gd_installed', $is_gd_installed);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate and process settings edit form.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-12-27 17:31:53 -08:00
|
|
|
public function postEdit(ImageUploadRequest $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
// Check if the asset exists
|
2016-06-01 15:50:50 -07:00
|
|
|
if (is_null($setting = Setting::first())) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-29 05:50:55 -07:00
|
|
|
if (!config('app.lock_passwords')) {
|
2016-03-25 01:18:05 -07:00
|
|
|
$setting->site_name = e(Input::get('site_name'));
|
|
|
|
$setting->custom_css = e(Input::get('custom_css'));
|
2016-10-31 13:50:00 -07:00
|
|
|
|
|
|
|
if (Input::get('two_factor_enabled')=='') {
|
|
|
|
$setting->two_factor_enabled = null;
|
|
|
|
} else {
|
|
|
|
$setting->two_factor_enabled = e(Input::get('two_factor_enabled'));
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::get('per_page')!='') {
|
|
|
|
$setting->per_page = e(Input::get('per_page'));
|
|
|
|
} else {
|
|
|
|
$setting->per_page = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
$setting->locale = e(Input::get('locale', 'en'));
|
2016-05-19 19:49:25 -07:00
|
|
|
$setting->qr_code = e(Input::get('qr_code', '0'));
|
2016-06-10 03:40:49 -07:00
|
|
|
$setting->full_multiple_companies_support = e(Input::get('full_multiple_companies_support', '0'));
|
2016-05-19 19:12:42 -07:00
|
|
|
$setting->alt_barcode = e(Input::get('alt_barcode'));
|
2016-05-19 19:49:25 -07:00
|
|
|
$setting->alt_barcode_enabled = e(Input::get('alt_barcode_enabled', '0'));
|
2016-03-25 01:18:05 -07:00
|
|
|
$setting->barcode_type = e(Input::get('barcode_type'));
|
|
|
|
$setting->load_remote = e(Input::get('load_remote', '0'));
|
|
|
|
$setting->default_currency = e(Input::get('default_currency', '$'));
|
|
|
|
$setting->qr_text = e(Input::get('qr_text'));
|
|
|
|
$setting->auto_increment_prefix = e(Input::get('auto_increment_prefix'));
|
|
|
|
$setting->auto_increment_assets = e(Input::get('auto_increment_assets', '0'));
|
2016-07-27 21:28:00 -07:00
|
|
|
$setting->zerofill_count = e(Input::get('zerofill_count'));
|
2016-05-19 19:33:53 -07:00
|
|
|
$setting->alert_interval = e(Input::get('alert_interval'));
|
|
|
|
$setting->alert_threshold = e(Input::get('alert_threshold'));
|
2016-06-01 15:45:26 -07:00
|
|
|
$setting->email_domain = e(Input::get('email_domain'));
|
|
|
|
$setting->email_format = e(Input::get('email_format'));
|
|
|
|
$setting->username_format = e(Input::get('username_format'));
|
2016-10-31 21:00:30 -07:00
|
|
|
$setting->require_accept_signature = e(Input::get('require_accept_signature'));
|
2016-03-25 01:18:05 -07:00
|
|
|
$setting->labels_per_page = e(Input::get('labels_per_page'));
|
|
|
|
$setting->labels_width = e(Input::get('labels_width'));
|
|
|
|
$setting->labels_height = e(Input::get('labels_height'));
|
|
|
|
$setting->labels_pmargin_left = e(Input::get('labels_pmargin_left'));
|
|
|
|
$setting->labels_pmargin_right = e(Input::get('labels_pmargin_right'));
|
|
|
|
$setting->labels_pmargin_top = e(Input::get('labels_pmargin_top'));
|
|
|
|
$setting->labels_pmargin_bottom = e(Input::get('labels_pmargin_bottom'));
|
|
|
|
$setting->labels_display_bgutter = e(Input::get('labels_display_bgutter'));
|
|
|
|
$setting->labels_display_sgutter = e(Input::get('labels_display_sgutter'));
|
|
|
|
$setting->labels_fontsize = e(Input::get('labels_fontsize'));
|
|
|
|
$setting->labels_pagewidth = e(Input::get('labels_pagewidth'));
|
|
|
|
$setting->labels_pageheight = e(Input::get('labels_pageheight'));
|
|
|
|
|
2016-10-31 13:50:00 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
if (Input::has('labels_display_name')) {
|
|
|
|
$setting->labels_display_name = 1;
|
|
|
|
} else {
|
|
|
|
$setting->labels_display_name = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('labels_display_serial')) {
|
|
|
|
$setting->labels_display_serial = 1;
|
|
|
|
} else {
|
|
|
|
$setting->labels_display_serial = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('labels_display_tag')) {
|
|
|
|
$setting->labels_display_tag = 1;
|
|
|
|
} else {
|
|
|
|
$setting->labels_display_tag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$alert_email = rtrim(Input::get('alert_email'), ',');
|
2016-10-29 05:50:55 -07:00
|
|
|
$alert_email = trim($alert_email);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$setting->alert_email = e($alert_email);
|
|
|
|
$setting->alerts_enabled = e(Input::get('alerts_enabled', '0'));
|
|
|
|
$setting->header_color = e(Input::get('header_color'));
|
|
|
|
$setting->default_eula_text = e(Input::get('default_eula_text'));
|
|
|
|
$setting->slack_endpoint = e(Input::get('slack_endpoint'));
|
|
|
|
$setting->slack_channel = e(Input::get('slack_channel'));
|
|
|
|
$setting->slack_botname = e(Input::get('slack_botname'));
|
2016-03-25 15:24:12 -07:00
|
|
|
$setting->ldap_enabled = e(Input::get('ldap_enabled', '0'));
|
|
|
|
$setting->ldap_server = e(Input::get('ldap_server'));
|
2016-03-25 01:18:05 -07:00
|
|
|
$setting->ldap_server_cert_ignore = e(Input::get('ldap_server_cert_ignore', false));
|
2016-03-25 15:24:12 -07:00
|
|
|
$setting->ldap_uname = e(Input::get('ldap_uname'));
|
2016-03-25 01:18:05 -07:00
|
|
|
if (Input::has('ldap_pword')) {
|
|
|
|
$setting->ldap_pword = Crypt::encrypt(Input::get('ldap_pword'));
|
|
|
|
}
|
|
|
|
$setting->ldap_basedn = e(Input::get('ldap_basedn'));
|
|
|
|
$setting->ldap_filter = Input::get('ldap_filter');
|
|
|
|
$setting->ldap_username_field = Input::get('ldap_username_field');
|
2016-03-25 15:24:12 -07:00
|
|
|
$setting->ldap_lname_field = e(Input::get('ldap_lname_field'));
|
|
|
|
$setting->ldap_fname_field = e(Input::get('ldap_fname_field'));
|
2016-03-25 01:18:05 -07:00
|
|
|
$setting->ldap_auth_filter_query = Input::get('ldap_auth_filter_query');
|
2016-03-25 15:24:12 -07:00
|
|
|
$setting->ldap_version = e(Input::get('ldap_version'));
|
|
|
|
$setting->ldap_active_flag = e(Input::get('ldap_active_flag'));
|
|
|
|
$setting->ldap_emp_num = e(Input::get('ldap_emp_num'));
|
|
|
|
$setting->ldap_email = e(Input::get('ldap_email'));
|
2016-07-14 15:52:52 -07:00
|
|
|
$setting->ad_domain = e(Input::get('ad_domain'));
|
|
|
|
$setting->is_ad = e(Input::get('is_ad', '0'));
|
2016-07-22 16:00:37 -07:00
|
|
|
$setting->ldap_tls = e(Input::get('ldap_tls', '0'));
|
2016-08-04 14:29:28 -07:00
|
|
|
$setting->ldap_pw_sync = e(Input::get('ldap_pw_sync', '0'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-03-03 17:29:41 -08:00
|
|
|
$setting->date_display_format = e(Input::get('date_display_format'));
|
|
|
|
$setting->time_display_format = e(Input::get('time_display_format'));
|
|
|
|
|
2016-12-27 17:31:53 -08:00
|
|
|
|
|
|
|
if ($request->input('clear_logo')=='1') {
|
|
|
|
$setting->logo = null;
|
|
|
|
$setting->brand = 1;
|
|
|
|
} elseif ($request->hasFile('image')) {
|
|
|
|
|
|
|
|
if (!config('app.lock_passwords')) {
|
|
|
|
$image = $request->file('image');
|
|
|
|
$file_name = "logo.".$image->getClientOriginalExtension();
|
|
|
|
$path = public_path('uploads');
|
|
|
|
if ($image->getClientOriginalExtension()!='svg') {
|
|
|
|
Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
|
|
|
|
$constraint->aspectRatio();
|
|
|
|
$constraint->upsize();
|
|
|
|
})->save($path.'/'.$file_name);
|
|
|
|
} else {
|
|
|
|
$image->move($path, $file_name);
|
|
|
|
}
|
|
|
|
$setting->logo = $file_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
if ($setting->save()) {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/app")->with('success', trans('admin/settings/message.update.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($setting->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Redirect to the setting management page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/app/edit")->with('error', trans('admin/settings/message.update.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
public function getLdapTest()
|
|
|
|
{
|
2016-07-13 05:50:40 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
$connection = Ldap::connectToLdap();
|
|
|
|
try {
|
|
|
|
Ldap::bindAdminToLdap($connection);
|
|
|
|
return response()->json(['message' => 'It worked!'], 200);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(['message' => $e->getMessage()], 500);
|
|
|
|
}
|
|
|
|
return response()->json(['message' => 'It worked!'], 200);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(['message' => $e->getMessage()], 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-12 17:16:10 -07:00
|
|
|
$path = storage_path().'/app/'.config('laravel-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()
|
|
|
|
{
|
|
|
|
if (!config('app.lock_passwords')) {
|
|
|
|
Artisan::call('backup:run');
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/backups")->with('success', trans('admin/settings/message.backup.generated'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/backups")->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')) {
|
2016-05-12 17:16:10 -07:00
|
|
|
$path = storage_path().'/app/'.config('laravel-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
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('settings/backups')->with('error', trans('admin/settings/message.backup.file_not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Redirect to the backup page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('settings/backups')->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')) {
|
|
|
|
|
2016-05-12 17:16:10 -07:00
|
|
|
$path = storage_path().'/app/'.config('laravel-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);
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('settings/backups')->with('success', trans('admin/settings/message.backup.file_deleted'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('settings/backups')->with('error', trans('admin/settings/message.backup.file_not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('settings/backups')->with('error', trans('general.feature_disabled'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
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') {
|
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() {
|
|
|
|
return view('settings/api');
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|