App\Http\Controllers\SettingsController Class Reference

This controller handles all actions related to Settings for the Snipe-IT Asset Management application. More...

Inheritance diagram for App\Http\Controllers\SettingsController:
App\Http\Controllers\Controller

Public Member Functions

 getSetupIndex ()
 Checks to see whether or not the database has a migrations table and a user, otherwise display the setup view. More...
 
 ajaxTestEmail ()
 Test the email configuration. More...
 
 postSaveFirstAdmin (SetupUserRequest $request)
 Save the first admin user from Setup. More...
 
 getSetupUser ()
 Return the admin user creation form in Setup. More...
 
 getSetupDone ()
 Return the view that tells the user that the Setup is done. More...
 
 getSetupMigrate ()
 Migrate the database tables, and return the output to a view for Setup. More...
 
 getIndex ()
 Return a view that shows some of the key settings. More...
 
 getEdit ()
 Return a form to allow a super admin to update settings. More...
 
 postEdit (SettingRequest $request)
 Validate and process settings edit form. More...
 
 getBackups ()
 Show the listing of backups. More...
 
 postBackups ()
 Process the backup. More...
 
 downloadFile ($filename=null)
 Download the backup file. More...
 
 deleteFile ($filename=null)
 Delete the backup file. More...
 

Detailed Description

This controller handles all actions related to Settings for the Snipe-IT Asset Management application.

Version
v1.0

Definition at line 27 of file SettingsController.php.

Member Function Documentation

App\Http\Controllers\SettingsController::ajaxTestEmail ( )

Test the email configuration.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
Redirect

Definition at line 136 of file SettingsController.php.

137  {
138 
139  try {
140  Mail::send('emails.test', [], function ($m) {
141  $m->to(config('mail.from.address'), config('mail.from.name'));
142  $m->subject('Test Email from Snipe-IT');
143  });
144  return 'success';
145  } catch (Exception $e) {
146  return 'error';
147  }
148 
149  }
App\Http\Controllers\SettingsController::deleteFile (   $filename = null)

Delete the backup file.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.8]
Returns
View

Definition at line 502 of file SettingsController.php.

503  {
504 
505  if (!config('app.lock_passwords')) {
506 
507  $file = config('backup::path').'/'.$filename;
508  if (file_exists($file)) {
509  unlink($file);
510  return Redirect::route('settings/backups')->with('success', trans('admin/settings/message.backup.file_deleted'));
511  } else {
512  return Redirect::route('settings/backups')->with('error', trans('admin/settings/message.backup.file_not_found'));
513  }
514  } else {
515  return Redirect::route('settings/backups')->with('error', trans('general.feature_disabled'));
516  }
517 
518  }
App\Http\Controllers\SettingsController::downloadFile (   $filename = null)

Download the backup file.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.8]
Returns
Redirect

Definition at line 475 of file SettingsController.php.

476  {
477  if (!config('app.lock_passwords')) {
478  $path = config('app.private_uploads').'/backups';
479  $file = $path.'/'.$filename;
480  if (file_exists($file)) {
481  return Response::download($file);
482  } else {
483 
484  // Redirect to the backup page
485  return Redirect::route('settings/backups')->with('error', trans('admin/settings/message.backup.file_not_found'));
486  }
487  } else {
488  // Redirect to the backup page
489  return Redirect::route('settings/backups')->with('error', trans('general.feature_disabled'));
490  }
491 
492 
493  }
App\Http\Controllers\SettingsController::getBackups ( )

Show the listing of backups.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.8]
Returns
View

Definition at line 416 of file SettingsController.php.

417  {
418 
419  $path = config('app.private_uploads').'/backups';
420 
421  $files = array();
422 
423  if ($handle = opendir($path)) {
424 
425  /* This is the correct way to loop over the directory. */
426  while (false !== ($entry = readdir($handle))) {
427  clearstatcache();
428  if (substr(strrchr($entry, '.'), 1)=='zip') {
429  $files[] = array(
430  'filename' => $entry,
431  'filesize' => Setting::fileSizeConvert(filesize($path.'/'.$entry)),
432  'modified' => filemtime($path.'/'.$entry)
433  );
434  }
435 
436  }
437  closedir($handle);
438  $files = array_reverse($files);
439  }
440 
441 
442  return View::make('settings/backups', compact('path', 'files'));
443  }
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
Definition: Setting.php:78
App\Http\Controllers\SettingsController::getEdit ( )

Return a form to allow a super admin to update settings.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.0]
Returns
View

Definition at line 272 of file SettingsController.php.

273  {
274  $setting = Setting::first();
275  $is_gd_installed = extension_loaded('gd');
276 
277  return View::make('settings/edit', compact('setting'))->with('is_gd_installed', $is_gd_installed);
278  }
App\Http\Controllers\SettingsController::getIndex ( )

Return a view that shows some of the key settings.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.0]
Returns
View

Definition at line 255 of file SettingsController.php.

256  {
257  // Grab all the settings
258  $settings = Setting::all();
259 
260  // Show the page
261  return View::make('settings/index', compact('settings'));
262  }
App\Http\Controllers\SettingsController::getSetupDone ( )

Return the view that tells the user that the Setup is done.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
View

Definition at line 219 of file SettingsController.php.

220  {
221  return View::make('setup/done')
222  ->with('step', 4)
223  ->with('section', 'Done!');
224  }
App\Http\Controllers\SettingsController::getSetupIndex ( )

Checks to see whether or not the database has a migrations table and a user, otherwise display the setup view.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
View

Definition at line 38 of file SettingsController.php.

39  {
40 
41 
42  try {
43  $conn = DB::select('select 2 + 2');
44  $start_settings['db_conn'] = true;
45  $start_settings['db_name'] = DB::connection()->getDatabaseName();
46  $start_settings['db_error'] = null;
47  } catch (\PDOException $e) {
48  $start_settings['db_conn'] = false;
49  $start_settings['db_name'] = config('database.connections.mysql.database');
50  $start_settings['db_error'] = $e->getMessage();
51  }
52 
53  $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
54 
55  $pageURL = $protocol;
56  if ($_SERVER["SERVER_PORT"] != "80") {
57  $main_page = $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"];
58  $pageURL .= $main_page.$_SERVER["REQUEST_URI"];
59  } else {
60  $main_page = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
61  $pageURL .= $main_page;
62  }
63 
64  $start_settings['env_location'] = $pageURL.'../.env';
65 
66 
67  if (config('app.url').'/setup'!=$pageURL) {
68  $start_settings['url_valid']= false;
69  } else {
70  $start_settings['url_valid']= true;
71  }
72 
73  $start_settings['url_config']= config('app.url');
74  $start_settings['real_url']= $pageURL;
75 
76  $exposed_env = @file_get_contents($main_page.'/.env');
77 
78  if ($exposed_env) {
79  $start_settings['env_exposed'] = true;
80  } else {
81  $start_settings['env_exposed'] = false;
82  }
83 
84  if (\App::Environment('production') && (config('app.debug')==true)) {
85  $start_settings['debug_exposed'] = true;
86  } else {
87  $start_settings['debug_exposed'] = false;
88  }
89 
90  $environment = app()->environment();
91  if ($environment!='production') {
92  $start_settings['env'] = $environment;
93  $start_settings['prod'] = false;
94  } else {
95  $start_settings['env'] = $environment;
96  $start_settings['prod'] = true;
97 
98  }
99 
100  $owner = posix_getpwuid(fileowner($_SERVER["SCRIPT_FILENAME"]));
101  $start_settings['owner'] = $owner['name'];
102 
103  if (($start_settings['owner']=='root') || ($start_settings['owner']=='0') || ($start_settings['owner']=='root')) {
104  $start_settings['owner_is_admin'] = true;
105  } else {
106  $start_settings['owner_is_admin'] = false;
107  }
108 
109  if ((is_writable(storage_path()))
110  && (is_writable(storage_path().'/framework'))
111  && (is_writable(storage_path().'/framework/cache'))
112  && (is_writable(storage_path().'/framework/sessions'))
113  && (is_writable(storage_path().'/framework/views'))
114  && (is_writable(storage_path().'/logs'))
115  ) {
116  $start_settings['writable'] = true;
117  } else {
118  $start_settings['writable'] = false;
119  }
120 
121 
122  $start_settings['gd'] = extension_loaded('gd');
123  return View::make('setup/index')
124  ->with('step', 1)
125  ->with('start_settings', $start_settings)
126  ->with('section', 'Pre-Flight Check');
127  }
App\Http\Controllers\SettingsController::getSetupMigrate ( )

Migrate the database tables, and return the output to a view for Setup.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
View

Definition at line 234 of file SettingsController.php.

235  {
236 
237  Artisan::call('migrate', ['--force' => true]);
238 
239  $output = Artisan::output();
240  return View::make('setup/migrate')
241  ->with('output', $output)
242  ->with('step', 2)
243  ->with('section', 'Create Database Tables');
244 
245  }
App\Http\Controllers\SettingsController::getSetupUser ( )

Return the admin user creation form in Setup.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
View

Definition at line 205 of file SettingsController.php.

206  {
207  return View::make('setup/user')
208  ->with('step', 3)
209  ->with('section', 'Create a User');
210  }
App\Http\Controllers\SettingsController::postBackups ( )

Process the backup.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.8]
Returns
Redirect

Definition at line 454 of file SettingsController.php.

455  {
456  if (!config('app.lock_passwords')) {
457  Artisan::call('backup:run');
458  return Redirect::to("admin/settings/backups")->with('success', trans('admin/settings/message.backup.generated'));
459  } else {
460 
461  return Redirect::to("admin/settings/backups")->with('error', trans('general.feature_disabled'));
462  }
463 
464 
465  }
App\Http\Controllers\SettingsController::postEdit ( SettingRequest  $request)

Validate and process settings edit form.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v1.0]
Returns
Redirect

Definition at line 288 of file SettingsController.php.

289  {
290 
291  // Check if the asset exists
292  if (is_null($setting = Setting::find(1))) {
293  // Redirect to the asset management page with error
294  return Redirect::to('admin')->with('error', trans('admin/settings/message.update.error'));
295  }
296 
297  if (Input::get('clear_logo')=='1') {
298  $setting->logo = null;
299  } elseif (Input::file('logo_img')) {
300  if (!config('app.lock_passwords')) {
301  $image = Input::file('logo_img');
302  $file_name = "logo.".$image->getClientOriginalExtension();
303  $path = public_path('uploads/'.$file_name);
304  Image::make($image->getRealPath())->resize(null, 40, function ($constraint) {
305  $constraint->aspectRatio();
306  $constraint->upsize();
307  })->save($path);
308  $setting->logo = $file_name;
309  }
310  }
311 
312  $setting->id = '1';
313 
314  if (config('app.lock_passwords')==false) {
315  $setting->site_name = e(Input::get('site_name'));
316  $setting->brand = e(Input::get('brand'));
317  $setting->custom_css = e(Input::get('custom_css'));
318  }
319 
320  if (Input::get('per_page')!='') {
321  $setting->per_page = e(Input::get('per_page'));
322  } else {
323  $setting->per_page = 200;
324  }
325 
326  $setting->locale = e(Input::get('locale', 'en'));
327  $setting->qr_code = e(Input::get('qr_code', '0'));
328  $setting->barcode_type = e(Input::get('barcode_type'));
329  $setting->load_remote = e(Input::get('load_remote', '0'));
330  $setting->default_currency = e(Input::get('default_currency', '$'));
331  $setting->qr_text = e(Input::get('qr_text'));
332  $setting->auto_increment_prefix = e(Input::get('auto_increment_prefix'));
333  $setting->auto_increment_assets = e(Input::get('auto_increment_assets', '0'));
334 
335  $setting->labels_per_page = e(Input::get('labels_per_page'));
336  $setting->labels_width = e(Input::get('labels_width'));
337  $setting->labels_height = e(Input::get('labels_height'));
338  $setting->labels_pmargin_left = e(Input::get('labels_pmargin_left'));
339  $setting->labels_pmargin_right = e(Input::get('labels_pmargin_right'));
340  $setting->labels_pmargin_top = e(Input::get('labels_pmargin_top'));
341  $setting->labels_pmargin_bottom = e(Input::get('labels_pmargin_bottom'));
342  $setting->labels_display_bgutter = e(Input::get('labels_display_bgutter'));
343  $setting->labels_display_sgutter = e(Input::get('labels_display_sgutter'));
344  $setting->labels_fontsize = e(Input::get('labels_fontsize'));
345  $setting->labels_pagewidth = e(Input::get('labels_pagewidth'));
346  $setting->labels_pageheight = e(Input::get('labels_pageheight'));
347 
348  if (Input::has('labels_display_name')) {
349  $setting->labels_display_name = 1;
350  } else {
351  $setting->labels_display_name = 0;
352  }
353 
354  if (Input::has('labels_display_serial')) {
355  $setting->labels_display_serial = 1;
356  } else {
357  $setting->labels_display_serial = 0;
358  }
359 
360  if (Input::has('labels_display_tag')) {
361  $setting->labels_display_tag = 1;
362  } else {
363  $setting->labels_display_tag = 0;
364  }
365 
366  $alert_email = rtrim(Input::get('alert_email'), ',');
367  $alert_email = trim(Input::get('alert_email'));
368 
369  $setting->alert_email = e($alert_email);
370  $setting->alerts_enabled = e(Input::get('alerts_enabled', '0'));
371  $setting->header_color = e(Input::get('header_color'));
372  $setting->default_eula_text = e(Input::get('default_eula_text'));
373  $setting->slack_endpoint = e(Input::get('slack_endpoint'));
374  $setting->slack_channel = e(Input::get('slack_channel'));
375  $setting->slack_botname = e(Input::get('slack_botname'));
376  $setting->ldap_enabled = e(Input::get('ldap_enabled', '0'));
377  $setting->ldap_server = e(Input::get('ldap_server'));
378  $setting->ldap_server_cert_ignore = e(Input::get('ldap_server_cert_ignore', false));
379  $setting->ldap_uname = e(Input::get('ldap_uname'));
380  if (Input::has('ldap_pword')) {
381  $setting->ldap_pword = Crypt::encrypt(Input::get('ldap_pword'));
382  }
383  $setting->ldap_basedn = e(Input::get('ldap_basedn'));
384  $setting->ldap_filter = Input::get('ldap_filter');
385  $setting->ldap_username_field = Input::get('ldap_username_field');
386  $setting->ldap_lname_field = e(Input::get('ldap_lname_field'));
387  $setting->ldap_fname_field = e(Input::get('ldap_fname_field'));
388  $setting->ldap_auth_filter_query = Input::get('ldap_auth_filter_query');
389  $setting->ldap_version = e(Input::get('ldap_version'));
390  $setting->ldap_active_flag = e(Input::get('ldap_active_flag'));
391  $setting->ldap_emp_num = e(Input::get('ldap_emp_num'));
392  $setting->ldap_email = e(Input::get('ldap_email'));
393 
394  // If validation fails, we'll exit the operation now.
395  if ($setting->save()) {
396  return Redirect::to("admin/settings/app")->with('success', trans('admin/settings/message.update.success'));
397 
398  } else {
399  return Redirect::back()->withInput()->withErrors($setting->getErrors());
400  }
401 
402 
403  // Redirect to the setting management page
404  return Redirect::to("admin/settings/app/edit")->with('error', trans('admin/settings/message.update.error'));
405 
406  }
App\Http\Controllers\SettingsController::postSaveFirstAdmin ( SetupUserRequest  $request)

Save the first admin user from Setup.

Author
[A. Gianotto] [snipe.nosp@m.@sni.nosp@m.pe.ne.nosp@m.t]
Since
[v3.0]
Returns
Redirect

Definition at line 158 of file SettingsController.php.

159  {
160 
161 
162  $user = new User;
163  $user->first_name = $data['first_name']= e(Input::get('first_name'));
164  $user->last_name = e(Input::get('last_name'));
165  $user->email = $data['email'] = e(Input::get('email'));
166  $user->activated = 1;
167  $user->username = $data['username'] = e(Input::get('username'));
168  $user->password = bcrypt(Input::get('password'));
169  $data['password'] = Input::get('password');
170 
171  $settings = new Setting;
172  $settings->site_name = e(Input::get('site_name'));
173  $settings->alert_email = e(Input::get('email'));
174  $settings->alerts_enabled = 1;
175  $settings->brand = 1;
176  $settings->default_currency = 'USD';
177  $settings->user_id = 1;
178 
179  if ((!$user->isValid('initial')) && (!$settings->isValid('initial'))) {
180  return Redirect::back()->withInput()->withErrors($user->getErrors())->withErrors($settings->getErrors());
181  } else {
182  $user->save();
183  $settings->save();
184 
185  if (Input::get('email_creds')=='1') {
186  Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use ($data) {
187  $m->to($data['email'], $data['first_name']);
188  $m->subject('Your Snipe-IT credentials');
189  });
190  }
191 
192  return redirect()->route('setup.done');
193  }
194 
195 
196  }

The documentation for this class was generated from the following file: