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();
53 $protocol = stripos($_SERVER[
'SERVER_PROTOCOL'],
'https') ===
true ?
'https://' :
'http://';
56 if ($_SERVER[
"SERVER_PORT"] !=
"80") {
57 $main_page = $_SERVER[
"SERVER_NAME"].
":".$_SERVER[
"SERVER_PORT"];
58 $pageURL .= $main_page.$_SERVER[
"REQUEST_URI"];
60 $main_page = $_SERVER[
"SERVER_NAME"].$_SERVER[
"REQUEST_URI"];
61 $pageURL .= $main_page;
64 $start_settings[
'env_location'] = $pageURL.
'../.env';
67 if (config(
'app.url').
'/setup'!=$pageURL) {
68 $start_settings[
'url_valid']=
false;
70 $start_settings[
'url_valid']=
true;
73 $start_settings[
'url_config']= config(
'app.url');
74 $start_settings[
'real_url']= $pageURL;
76 $exposed_env = @file_get_contents($main_page.
'/.env');
79 $start_settings[
'env_exposed'] =
true;
81 $start_settings[
'env_exposed'] =
false;
84 if (\App::Environment(
'production') && (config(
'app.debug')==
true)) {
85 $start_settings[
'debug_exposed'] =
true;
87 $start_settings[
'debug_exposed'] =
false;
90 $environment = app()->environment();
91 if ($environment!=
'production') {
92 $start_settings[
'env'] = $environment;
93 $start_settings[
'prod'] =
false;
95 $start_settings[
'env'] = $environment;
96 $start_settings[
'prod'] =
true;
100 $owner = posix_getpwuid(fileowner($_SERVER[
"SCRIPT_FILENAME"]));
101 $start_settings[
'owner'] = $owner[
'name'];
103 if (($start_settings[
'owner']==
'root') || ($start_settings[
'owner']==
'0') || ($start_settings[
'owner']==
'root')) {
104 $start_settings[
'owner_is_admin'] =
true;
106 $start_settings[
'owner_is_admin'] =
false;
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'))
116 $start_settings[
'writable'] =
true;
118 $start_settings[
'writable'] =
false;
122 $start_settings[
'gd'] = extension_loaded(
'gd');
123 return View::make(
'setup/index')
125 ->with(
'start_settings', $start_settings)
126 ->with(
'section',
'Pre-Flight Check');
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');
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');
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;
179 if ((!$user->isValid(
'initial')) && (!$settings->isValid(
'initial'))) {
180 return Redirect::back()->withInput()->withErrors($user->getErrors())->withErrors($settings->getErrors());
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');
192 return redirect()->route(
'setup.done');
207 return View::make(
'setup/user')
209 ->with(
'section',
'Create a User');
221 return View::make(
'setup/done')
223 ->with(
'section',
'Done!');
237 Artisan::call(
'migrate', [
'--force' =>
true]);
239 $output = Artisan::output();
240 return View::make(
'setup/migrate')
241 ->with(
'output', $output)
243 ->with(
'section',
'Create Database Tables');
258 $settings = Setting::all();
261 return View::make(
'settings/index', compact(
'settings'));
274 $setting = Setting::first();
275 $is_gd_installed = extension_loaded(
'gd');
277 return View::make(
'settings/edit', compact(
'setting'))->with(
'is_gd_installed', $is_gd_installed);
292 if (is_null($setting = Setting::find(1))) {
294 return Redirect::to(
'admin')->with(
'error', trans(
'admin/settings/message.update.error'));
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();
308 $setting->logo = $file_name;
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'));
320 if (Input::get(
'per_page')!=
'') {
321 $setting->per_page = e(Input::get(
'per_page'));
323 $setting->per_page = 200;
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'));
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'));
348 if (Input::has(
'labels_display_name')) {
349 $setting->labels_display_name = 1;
351 $setting->labels_display_name = 0;
354 if (Input::has(
'labels_display_serial')) {
355 $setting->labels_display_serial = 1;
357 $setting->labels_display_serial = 0;
360 if (Input::has(
'labels_display_tag')) {
361 $setting->labels_display_tag = 1;
363 $setting->labels_display_tag = 0;
366 $alert_email = rtrim(Input::get(
'alert_email'),
',');
367 $alert_email = trim(Input::get(
'alert_email'));
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'));
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'));
395 if ($setting->save()) {
396 return Redirect::to(
"admin/settings/app")->with(
'success', trans(
'admin/settings/message.update.success'));
399 return Redirect::back()->withInput()->withErrors($setting->getErrors());
404 return Redirect::to(
"admin/settings/app/edit")->with(
'error', trans(
'admin/settings/message.update.error'));
419 $path = config(
'app.private_uploads').
'/backups';
423 if ($handle = opendir($path)) {
426 while (
false !== ($entry = readdir($handle))) {
428 if (substr(strrchr($entry,
'.'), 1)==
'zip') {
430 'filename' => $entry,
432 'modified' => filemtime($path.
'/'.$entry)
438 $files = array_reverse($files);
442 return View::make(
'settings/backups', compact(
'path',
'files'));
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'));
461 return Redirect::to(
"admin/settings/backups")->with(
'error', trans(
'general.feature_disabled'));
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);
485 return Redirect::route(
'settings/backups')->with(
'error', trans(
'admin/settings/message.backup.file_not_found'));
489 return Redirect::route(
'settings/backups')->with(
'error', trans(
'general.feature_disabled'));
505 if (!config(
'app.lock_passwords')) {
507 $file = config(
'backup::path').
'/'.$filename;
508 if (file_exists($file)) {
510 return Redirect::route(
'settings/backups')->with(
'success', trans(
'admin/settings/message.backup.file_deleted'));
512 return Redirect::route(
'settings/backups')->with(
'error', trans(
'admin/settings/message.backup.file_not_found'));
515 return Redirect::route(
'settings/backups')->with(
'error', trans(
'general.feature_disabled'));
getIndex()
Return a view that shows some of the key settings.
getSetupUser()
Return the admin user creation form in Setup.
getEdit()
Return a form to allow a super admin to update settings.
getSetupIndex()
Checks to see whether or not the database has a migrations table and a user, otherwise display the se...
ajaxTestEmail()
Test the email configuration.
postSaveFirstAdmin(SetupUserRequest $request)
Save the first admin user from Setup.
downloadFile($filename=null)
Download the backup file.
getBackups()
Show the listing of backups.
static fileSizeConvert($bytes)
Converts bytes into human readable file size.
postBackups()
Process the backup.
deleteFile($filename=null)
Delete the backup file.
postEdit(SettingRequest $request)
Validate and process settings edit form.
This controller handles all actions related to Settings for the Snipe-IT Asset Management application...
getSetupMigrate()
Migrate the database tables, and return the output to a view for Setup.
getSetupDone()
Return the view that tells the user that the Setup is done.