Skip to content

Commit

Permalink
More work on DB SSL install
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed May 9, 2024
1 parent 2af7128 commit 4f04ec6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
25 changes: 23 additions & 2 deletions upload/install/cli_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// --db_database opencart \
// --db_driver mysqli \
// --db_port 3306 \
// --db_ssl_key
// --db_ssl_cert
// --db_ssl_ca
// --username admin \
// --password admin \
// --email [email protected] \
Expand Down Expand Up @@ -96,7 +99,10 @@ function get_options($argv) {
'db_prefix' => 'oc_',
'db_driver' => 'mysqli',
'db_port' => '3306',
'username' => 'admin',
'db_ssl_key' => '',
'db_ssl_cert' => '',
'db_ssl_ca' => '',
'username' => 'admin'
];

$options = [];
Expand Down Expand Up @@ -125,6 +131,9 @@ function valid($options) {
'db_database',
'db_prefix',
'db_port',
'db_ssl_key',
'db_ssl_cert',
'db_ssl_ca',
'username',
'password',
'email',
Expand Down Expand Up @@ -206,7 +215,7 @@ function check_requirements() {

// Setup DB
function setup_db($data): void {
$db = new \DB($data['db_driver'], htmlspecialchars_decode($data['db_hostname']), htmlspecialchars_decode($data['db_username']), htmlspecialchars_decode($data['db_password']), htmlspecialchars_decode($data['db_database']), $data['db_port']);
$db = new \DB($data['db_driver'], htmlspecialchars_decode($data['db_hostname']), htmlspecialchars_decode($data['db_username']), htmlspecialchars_decode($data['db_password']), htmlspecialchars_decode($data['db_database']), $data['db_port'], $data['db_ssl_key'], $data['db_ssl_cert'], $data['db_ssl_ca']);

$file = DIR_APPLICATION . 'opencart.sql';

Expand Down Expand Up @@ -298,6 +307,18 @@ function write_config_files($options): void {
$output .= 'define(\'DB_PREFIX\', \'' . addslashes($options['db_prefix']) . '\');' . "\n";
$output .= 'define(\'DB_PORT\', \'' . addslashes($options['db_port']) . '\');' . "\n";

if ($options['db_ssl_key']) {
$output .= 'define(\'DB_SSL_KEY\', \'' . addslashes($options['db_ssl_key']) . '\');' . "\n";
}

if ($options['db_ssl_cert']) {
$output .= 'define(\'DB_SSL_CERT\', \'' . addslashes($options['db_ssl_cert']) . '\');' . "\n";
}

if ($options['db_ssl_ca']) {
$output .= 'define(\'DB_SSL_CA\', \'' . addslashes($options['db_ssl_ca']) . '\');' . "\n";
}

$file = fopen(DIR_OPENCART . 'config.php', 'w');

fwrite($file, $output);
Expand Down
40 changes: 40 additions & 0 deletions upload/install/controller/install/step_3.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ public function index(): void {
$output .= 'define(\'DB_PORT\', \'' . addslashes($this->request->post['db_port']) . '\');' . "\n";
$output .= 'define(\'DB_PREFIX\', \'' . addslashes($this->request->post['db_prefix']) . '\');' . "\n\n";

if (!empty($this->request->post['db_ssl_key'])) {
$output .= 'define(\'DB_SSL_KEY\', \'' . addslashes($this->request->post['db_ssl_key']) . '\');' . "\n";
} else {
$output .= 'define(\'DB_SSL_KEY\', \'\');' . "\n";
}

if (!empty($this->request->post['db_ssl_cert'])) {
$output .= 'define(\'DB_SSL_CERT\', \'' . addslashes($this->request->post['db_ssl_cert']) . '\');' . "\n";
} else {
$output .= 'define(\'DB_SSL_CERT\', \'\');' . "\n";
}

if (!empty($this->request->post['db_ssl_ca'])) {
$output .= 'define(\'DB_SSL_CA\', \'' . addslashes($this->request->post['db_ssl_ca']) . '\');' . "\n";
} else {
$output .= 'define(\'DB_SSL_CA\', \'\');' . "\n";
}

$output .= '// OpenCart API' . "\n";
$output .= 'define(\'OPENCART_SERVER\', \'https://www.opencart.com/\');' . "\n";

Expand Down Expand Up @@ -122,6 +140,10 @@ public function index(): void {
$data['entry_db_username'] = $this->language->get('entry_db_username');
$data['entry_db_password'] = $this->language->get('entry_db_password');
$data['entry_db_database'] = $this->language->get('entry_db_database');
$data['entry_db_ssl_key'] = $this->language->get('entry_db_ssl_key');
$data['entry_db_ssl_cert'] = $this->language->get('entry_db_ssl_cert');
$data['entry_db_ssl_ca'] = $this->language->get('entry_db_ssl_ca');
$data['entry_db_ssl_info'] = $this->language->get('entry_db_ssl_info');
$data['entry_db_port'] = $this->language->get('entry_db_port');
$data['entry_db_prefix'] = $this->language->get('entry_db_prefix');
$data['entry_username'] = $this->language->get('entry_username');
Expand Down Expand Up @@ -234,6 +256,24 @@ public function index(): void {
$data['db_password'] = '';
}

if (isset($this->request->post['db_ssl_key'])) {
$data['db_ssl_key'] = $this->request->post['db_ssl_key'];
} else {
$data['db_ssl_key'] = '';
}

if (isset($this->request->post['db_ssl_cert'])) {
$data['db_ssl_cert'] = $this->request->post['db_ssl_cert'];
} else {
$data['db_ssl_cert'] = '';
}

if (isset($this->request->post['db_ssl_ca'])) {
$data['db_ssl_ca'] = $this->request->post['db_ssl_ca'];
} else {
$data['db_ssl_ca'] = '';
}

if (isset($this->request->post['db_database'])) {
$data['db_database'] = $this->request->post['db_database'];
} else {
Expand Down
3 changes: 3 additions & 0 deletions upload/install/language/en-gb/install/step_3.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
$_['entry_db_database'] = 'Database';
$_['entry_db_port'] = 'Port';
$_['entry_db_prefix'] = 'Prefix';
$_['entry_db_ssl_key'] = 'SSL Key';
$_['entry_db_ssl_cert'] = 'SSL Cert';
$_['entry_db_ssl_ca'] = 'SSL CA';
$_['entry_username'] = 'Username';
$_['entry_password'] = 'Password';
$_['entry_email'] = 'E-Mail';
Expand Down
18 changes: 18 additions & 0 deletions upload/install/view/template/install/step_3.twig
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@
{% endif %}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-db-ssl-key">{{ entry_db_ssl_key }}</label>
<div class="col-sm-10">
<textarea name="value" rows="8" placeholder="{{ entry_db_ssl_key }}" class="form-control" id="input-db-ssl-key"/>{{ db_ssl_key }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-db-ssl-cert">{{ entry_db_ssl_cert }}</label>
<div class="col-sm-10">
<textarea name="value" rows="8" placeholder="{{ entry_db_ssl_cert }}" class="form-control" id="input-db-ssl-cert"/>{{ db_ssl_cert }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-db-ssl-ca">{{ entry_db_ssl_ca }}</label>
<div class="col-sm-10">
<textarea name="value" rows="8" placeholder="{{ entry_db_ssl_ca }}" class="form-control" id="input-db-ssl-ca"/>{{ db_ssl_ca }}</textarea>
</div>
</div>
</fieldset>
<p>{{ text_db_administration }}</p>
<fieldset>
Expand Down
4 changes: 2 additions & 2 deletions upload/system/storage/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'opencart/opencart-3',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '74231725eab5fd3f3fa4714b4bee15a42508c7e4',
'reference' => '2af712801e78f2a01b27c02805ff6a3586c1cae9',
'type' => 'project',
'install_path' => __DIR__ . '/../../../../../',
'aliases' => array(),
Expand Down Expand Up @@ -67,7 +67,7 @@
'opencart/opencart-3' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '74231725eab5fd3f3fa4714b4bee15a42508c7e4',
'reference' => '2af712801e78f2a01b27c02805ff6a3586c1cae9',
'type' => 'project',
'install_path' => __DIR__ . '/../../../../../',
'aliases' => array(),
Expand Down

0 comments on commit 4f04ec6

Please sign in to comment.