1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Added system settings page

This commit is contained in:
Hillel Coren 2015-11-04 15:57:59 +02:00
parent 4b935f5844
commit 65e959e84d
10 changed files with 245 additions and 149 deletions

View File

@ -174,6 +174,8 @@ class AccountController extends BaseController
return self::showProducts();
} elseif ($section === ACCOUNT_TAX_RATES) {
return self::showTaxRates();
} elseif ($section === ACCOUNT_SYSTEM_SETTINGS) {
return self::showSystemSettings();
} else {
$data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
@ -184,6 +186,21 @@ class AccountController extends BaseController
}
}
private function showSystemSettings()
{
if (Utils::isNinjaProd()) {
return Redirect::to('/');
}
$data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'title' => trans("texts.system_settings"),
'section' => ACCOUNT_SYSTEM_SETTINGS,
];
return View::make("accounts.system_settings", $data);
}
private function showInvoiceSettings()
{
$account = Auth::user()->account;

View File

@ -48,7 +48,7 @@ class AppController extends BaseController
public function doSetup()
{
if (Utils::isNinjaProd() || (Utils::isDatabaseSetup() && Account::count() > 0)) {
if (Utils::isNinjaProd()) {
return Redirect::to('/');
}
@ -57,9 +57,10 @@ class AppController extends BaseController
$app = Input::get('app');
$app['key'] = env('APP_KEY') ?: str_random(RANDOM_KEY_LENGTH);
$app['debug'] = Input::get('debug') ? 'true' : 'false';
$database = Input::get('database');
$dbType = $database['default'];
$dbType = 'mysql'; // $database['default'];
$database['connections'] = [$dbType => $database['type']];
$mail = Input::get('mail');
@ -78,8 +79,12 @@ class AppController extends BaseController
return Redirect::to('/setup')->withInput();
}
if (Utils::isDatabaseSetup() && Account::count() > 0) {
return Redirect::to('/');
}
$config = "APP_ENV=production\n".
"APP_DEBUG=false\n".
"APP_DEBUG={$app['debug']}\n".
"APP_URL={$app['url']}\n".
"APP_KEY={$app['key']}\n\n".
"DB_TYPE={$dbType}\n".
@ -120,17 +125,68 @@ class AppController extends BaseController
return Redirect::to('/login');
}
public function updateSetup()
{
if (Utils::isNinjaProd()) {
return Redirect::to('/');
}
if (!Auth::check() && Utils::isDatabaseSetup() && Account::count() > 0) {
return Redirect::to('/');
}
if ( ! $canUpdateEnv = @fopen(base_path()."/.env", 'w')) {
Session::flash('error', 'Warning: Permission denied to write to .env config file, try running <code>sudo chown www-data:www-data /path/to/ninja/.env</code>');
return Redirect::to('/settings/system_settings');
}
$app = Input::get('app');
$db = Input::get('database');
$mail = Input::get('mail');
$_ENV['APP_URL'] = $app['url'];
$_ENV['APP_DEBUG'] = Input::get('debug') ? 'true' : 'false';
$_ENV['DB_TYPE'] = 'mysql'; // $db['default'];
$_ENV['DB_HOST'] = $db['type']['host'];
$_ENV['DB_DATABASE'] = $db['type']['database'];
$_ENV['DB_USERNAME'] = $db['type']['username'];
$_ENV['DB_PASSWORD'] = $db['type']['password'];
if ($mail) {
$_ENV['MAIL_DRIVER'] = $mail['driver'];
$_ENV['MAIL_PORT'] = $mail['port'];
$_ENV['MAIL_ENCRYPTION'] = $mail['encryption'];
$_ENV['MAIL_HOST'] = $mail['host'];
$_ENV['MAIL_USERNAME'] = $mail['username'];
$_ENV['MAIL_FROM_NAME'] = $mail['from']['name'];
$_ENV['MAIL_PASSWORD'] = $mail['password'];
$_ENV['MAIL_FROM_ADDRESS'] = $mail['username'];
}
$config = '';
foreach ($_ENV as $key => $val) {
$config .= "{$key}={$val}\n";
}
$fp = fopen(base_path()."/.env", 'w');
fwrite($fp, $config);
fclose($fp);
Session::flash('message', trans('texts.updated_settings'));
return Redirect::to('/settings/system_settings');
}
private function testDatabase($database)
{
$dbType = $database['default'];
$dbType = 'mysql'; // $database['default'];
Config::set('database.default', $dbType);
foreach ($database['connections'][$dbType] as $key => $val) {
Config::set("database.connections.{$dbType}.{$key}", $val);
}
try {
DB::reconnect();
$valid = DB::connection()->getDatabaseName() ? true : false;
} catch (Exception $e) {
return $e->getMessage();

View File

@ -184,6 +184,7 @@ Route::group(['middleware' => 'auth'], function() {
Route::post('credits/bulk', 'CreditController@bulk');
get('/resend_confirmation', 'AccountController@resendConfirmation');
post('/update_setup', 'AppController@updateSetup');
});
// Route groups for API
@ -278,6 +279,7 @@ if (!defined('CONTACT_EMAIL')) {
define('ACCOUNT_TEMPLATES_AND_REMINDERS', 'templates_and_reminders');
define('ACCOUNT_API_TOKENS', 'api_tokens');
define('ACCOUNT_CUSTOMIZE_DESIGN', 'customize_design');
define('ACCOUNT_SYSTEM_SETTINGS', 'system_settings');
define('ACTION_RESTORE', 'restore');
define('ACTION_ARCHIVE', 'archive');

View File

@ -32231,7 +32231,7 @@ NINJA.parseRegExpLine = function(line, regExp, formatter, groupText)
var parts = [];
var lastIndex = 0;
while (match = regExp.exec(line)) {
while (match = regExp.exec(line + '\n')) {
if (match.index > lastIndex) {
parts.push(line.substring(lastIndex, match.index));
}

View File

@ -893,5 +893,7 @@ return array(
'quote_is_approved' => 'This quote is approved',
'apply_credit' => 'Apply Credit',
'system_settings' => 'System Settings',
);

View File

@ -16,7 +16,7 @@
<div class="panel panel-default">
<div class="panel-heading" style="color:white">
{{ trans("texts.{$type}") }}
@if ($type == ADVANCED_SETTINGS && !Utils::isPro())
@if ($type === ADVANCED_SETTINGS && !Utils::isPro())
<sup>{{ strtoupper(trans('texts.pro')) }}</sup>
@endif
</div>
@ -25,6 +25,10 @@
<a href="{{ URL::to("settings/{$section}") }}" class="list-group-item {{ $selected === $section ? 'selected' : '' }}"
style="width:100%;text-align:left">{{ trans("texts.{$section}") }}</a>
@endforeach
@if ($type === ADVANCED_SETTINGS && !Utils::isNinjaProd())
<a href="{{ URL::to("settings/system_settings") }}" class="list-group-item {{ $selected === 'system_settings' ? 'selected' : '' }}"
style="width:100%;text-align:left">{{ trans("texts.system_settings") }}</a>
@endif
</div>
</div>
@endforeach

View File

@ -0,0 +1,36 @@
@extends('header')
@section('content')
@parent
{!! Former::open('/update_setup')->addClass('warn-on-exit') !!}
@include('accounts.nav', ['selected' => ACCOUNT_SYSTEM_SETTINGS])
<div class="row">
{!! Former::open()->rules([
'app[url]' => 'required',
//'database[default]' => 'required',
'database[type][host]' => 'required',
'database[type][database]' => 'required',
'database[type][username]' => 'required',
'database[type][password]' => 'required',
]) !!}
@include('partials.system_settings')
</div>
<center>
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
</center>
{!! Former::close() !!}
@stop
@section('onReady')
$('#app\\[url\\]').focus();
@stop

View File

@ -198,8 +198,8 @@
<thead>
<th>{{ trans('texts.quote_number_short') }}</th>
<th>{{ trans('texts.client') }}</th>
<th>{{ trans('texts.due_date') }}</th>
<th>{{ trans('texts.balance_due') }}</th>
<th>{{ trans('texts.valid_until') }}</th>
<th>{{ trans('texts.amount') }}</th>
</thead>
<tbody>
@foreach ($upcoming as $invoice)
@ -229,8 +229,8 @@
<thead>
<th>{{ trans('texts.quote_number_short') }}</th>
<th>{{ trans('texts.client') }}</th>
<th>{{ trans('texts.due_date') }}</th>
<th>{{ trans('texts.balance_due') }}</th>
<th>{{ trans('texts.valid_until') }}</th>
<th>{{ trans('texts.amount') }}</th>
</thead>
<tbody>
@foreach ($pastDue as $invoice)

View File

@ -0,0 +1,112 @@
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Application Settings</h3>
</div>
<div class="panel-body form-padding-right">
{!! Former::text('app[url]')->label('URL')->value(isset($_ENV['APP_URL']) ? $_ENV['APP_URL'] : Request::root()) !!}
{!! Former::checkbox('debug')
->label('Debug')
->text(trans('texts.enable'))
->check(config('app.debug')) !!}
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Database Connection</h3>
</div>
<div class="panel-body form-padding-right">
{{--- Former::select('database[default]')->label('Driver')->options(['mysql' => 'MySQL', 'pgsql' => 'PostgreSQL', 'sqlite' => 'SQLite'])
->value(isset($_ENV['DB_TYPE']) ? $_ENV['DB_TYPE'] : 'mysql') ---}}
{!! Former::plaintext('Driver')->value('MySQL') !!}
{!! Former::text('database[type][host]')->label('Host')->value('localhost')
->value(isset($_ENV['DB_HOST']) ? $_ENV['DB_HOST'] : '') !!}
{!! Former::text('database[type][database]')->label('Database')->value('ninja')
->value(isset($_ENV['DB_DATABASE']) ? $_ENV['DB_DATABASE'] : '') !!}
{!! Former::text('database[type][username]')->label('Username')->value('ninja')
->value(isset($_ENV['DB_USERNAME']) ? $_ENV['DB_USERNAME'] : '') !!}
{!! Former::password('database[type][password]')->label('Password')->value('ninja')
->value(isset($_ENV['DB_PASSWORD']) ? $_ENV['DB_PASSWORD'] : '') !!}
{!! Former::actions( Button::primary('Test connection')->small()->withAttributes(['onclick' => 'testDatabase()']), '&nbsp;&nbsp;<span id="dbTestResult"/>' ) !!}
</div>
</div>
@if (!isset($_ENV['POSTMARK_API_TOKEN']))
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Email Settings</h3>
</div>
<div class="panel-body form-padding-right">
{!! Former::select('mail[driver]')->label('Driver')->options(['smtp' => 'SMTP', 'mail' => 'Mail', 'sendmail' => 'Sendmail'])
->value(isset($_ENV['MAIL_DRIVER']) ? $_ENV['MAIL_DRIVER'] : 'smtp') !!}
{!! Former::text('mail[host]')->label('Host')
->value(isset($_ENV['MAIL_HOST']) ? $_ENV['MAIL_HOST'] : '') !!}
{!! Former::text('mail[port]')->label('Port')
->value(isset($_ENV['MAIL_PORT']) ? $_ENV['MAIL_PORT'] : '587') !!}
{!! Former::select('mail[encryption]')->label('Encryption')->options(['tls' => 'TLS', 'ssl' => 'SSL'])
->value(isset($_ENV['MAIL_ENCRYPTION']) ? $_ENV['MAIL_ENCRYPTION'] : 'tls') !!}
{!! Former::text('mail[from][name]')->label('From Name')
->value(isset($_ENV['MAIL_FROM_NAME']) ? $_ENV['MAIL_FROM_NAME'] : '') !!}
{!! Former::text('mail[username]')->label('Email')
->value(isset($_ENV['MAIL_USERNAME']) ? $_ENV['MAIL_USERNAME'] : '') !!}
{!! Former::password('mail[password]')->label('Password')
->value(isset($_ENV['MAIL_PASSWORD']) ? $_ENV['MAIL_PASSWORD'] : '') !!}
{!! Former::actions( Button::primary('Send test email')->small()->withAttributes(['onclick' => 'testMail()']), '&nbsp;&nbsp;<span id="mailTestResult"/>' ) !!}
</div>
</div>
@endif
<script type="text/javascript">
var db_valid = false
var mail_valid = false
function testDatabase()
{
var data = $("form").serialize() + "&test=db";
// Show Progress Text
$('#dbTestResult').html('Working...').css('color', 'black');
// Send / Test Information
$.post( "/setup", data, function( data ) {
var color = 'red';
if(data == 'Success'){
color = 'green';
db_valid = true;
}
$('#dbTestResult').html(data).css('color', color);
});
return db_valid;
}
function testMail()
{
var data = $("form").serialize() + "&test=mail";
// Show Progress Text
$('#mailTestResult').html('Working...').css('color', 'black');
// Send / Test Information
$.post( "/setup", data, function( data ) {
var color = 'red';
if(data == 'Sent'){
color = 'green';
mail_valid = true;
}
$('#mailTestResult').html(data).css('color', color);
});
return mail_valid;
}
// Prevent the Enter Button from working
$("form").bind("keypress", function (e) {
if (e.keyCode == 13) {
return false;
}
});
</script>

View File

@ -33,8 +33,8 @@
<div class="alert alert-warning">Warning: <a href="http://php.net/manual/en/function.proc-open.php" target="_blank">proc_open</a> must be enabled.</div>
@endif
@if (!@fopen(base_path()."/.env", 'a'))
<div class="alert alert-warning">Warning: Permission denied to write config file
<pre>sudo chown yourname:www-data /path/to/ninja</pre>
<div class="alert alert-warning">Warning: Permission denied to write .env config file
<pre>sudo chown www-data:www-data /path/to/ninja/.env</pre>
</div>
@endif
If you need help you can either post to our <a href="https://www.invoiceninja.com/forums/forum/support/" target="_blank">support forum</a>
@ -61,58 +61,7 @@ FLUSH PRIVILEGES;</pre>
'terms_checkbox' => 'required'
]) !!}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Application Settings</h3>
</div>
<div class="panel-body">
{!! Former::text('app[url]')->label('URL')->value(isset($_ENV['APP_URL']) ? $_ENV['APP_URL'] : Request::root()) !!}
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Database Connection</h3>
</div>
<div class="panel-body">
{!! Former::select('database[default]')->label('Driver')->options(['mysql' => 'MySQL', 'pgsql' => 'PostgreSQL', 'sqlite' => 'SQLite'])
->value(isset($_ENV['DB_TYPE']) ? $_ENV['DB_TYPE'] : 'mysql') !!}
{!! Former::text('database[type][host]')->label('Host')->value('localhost')
->value(isset($_ENV['DB_HOST']) ? $_ENV['DB_HOST'] : '') !!}
{!! Former::text('database[type][database]')->label('Database')->value('ninja')
->value(isset($_ENV['DB_DATABASE']) ? $_ENV['DB_DATABASE'] : '') !!}
{!! Former::text('database[type][username]')->label('Username')->value('ninja')
->value(isset($_ENV['DB_USERNAME']) ? $_ENV['DB_USERNAME'] : '') !!}
{!! Former::password('database[type][password]')->label('Password')->value('ninja')
->value(isset($_ENV['DB_PASSWORD']) ? $_ENV['DB_PASSWORD'] : '') !!}
{!! Former::actions( Button::primary('Test connection')->small()->withAttributes(['onclick' => 'testDatabase()']), '&nbsp;&nbsp;<span id="dbTestResult"/>' ) !!}
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Email Settings</h3>
</div>
<div class="panel-body">
{!! Former::select('mail[driver]')->label('Driver')->options(['smtp' => 'SMTP', 'mail' => 'Mail', 'sendmail' => 'Sendmail'])
->value(isset($_ENV['MAIL_DRIVER']) ? $_ENV['MAIL_DRIVER'] : 'smtp') !!}
{!! Former::text('mail[host]')->label('Host')
->value(isset($_ENV['MAIL_HOST']) ? $_ENV['MAIL_HOST'] : '') !!}
{!! Former::text('mail[port]')->label('Port')
->value(isset($_ENV['MAIL_PORT']) ? $_ENV['MAIL_PORT'] : '587') !!}
{!! Former::select('mail[encryption]')->label('Encryption')->options(['tls' => 'TLS', 'ssl' => 'SSL'])
->value(isset($_ENV['MAIL_ENCRYPTION']) ? $_ENV['MAIL_ENCRYPTION'] : 'tls') !!}
{!! Former::text('mail[from][name]')->label('From Name')
->value(isset($_ENV['MAIL_FROM_NAME']) ? $_ENV['MAIL_FROM_NAME'] : '') !!}
{!! Former::text('mail[username]')->label('Email')
->value(isset($_ENV['MAIL_USERNAME']) ? $_ENV['MAIL_USERNAME'] : '') !!}
{!! Former::password('mail[password]')->label('Password')
->value(isset($_ENV['MAIL_PASSWORD']) ? $_ENV['MAIL_PASSWORD'] : '') !!}
{!! Former::actions( Button::primary('Send test email')->small()->withAttributes(['onclick' => 'testMail()']), '&nbsp;&nbsp;<span id="mailTestResult"/>' ) !!}
</div>
</div>
@include('partials.system_settings')
<div class="panel panel-default">
<div class="panel-heading">
@ -133,87 +82,5 @@ FLUSH PRIVILEGES;</pre>
</div>
<script type="text/javascript">
/*
* TODO:
* - Add JS Validation to DB and Mail
* - Add Function to clear valid vars fields if they change a setting
* - Add Nicer Error Message
*
*/
var db_valid = false
var mail_valid = false
function testDatabase()
{
var data = $("form").serialize() + "&test=db";
// Show Progress Text
$('#dbTestResult').html('Working...').css('color', 'black');
// Send / Test Information
$.post( "/setup", data, function( data ) {
var color = 'red';
if(data == 'Success'){
color = 'green';
db_valid = true;
}
$('#dbTestResult').html(data).css('color', color);
});
return db_valid;
}
function testMail()
{
var data = $("form").serialize() + "&test=mail";
// Show Progress Text
$('#mailTestResult').html('Working...').css('color', 'black');
// Send / Test Information
$.post( "/setup", data, function( data ) {
var color = 'red';
if(data == 'Sent'){
color = 'green';
mail_valid = true;
}
$('#mailTestResult').html(data).css('color', color);
});
return mail_valid;
}
// Validate Settings
/*$('form button[type="submit"]').click( function(e)
{
// Check DB Settings
if( !db_valid && !testDatabase() ) {
alert('Please check your Database Settings.');
return false;
}
// If Mail Settings are incorrect, prompt for continue
if( !mail_valid && !testMail() ) {
var check = confirm("The mail settings are incomplete.\nAre you sure you want to continue?");
if (!check) {
return false;
}
}
return true;
});*/
// Prevent the Enter Button from working
$("form").bind("keypress", function (e) {
if (e.keyCode == 13) {
return false;
}
});
</script>
</body>
</html>