Skip to content

Commit f3d0bbe

Browse files
committed
Implements #973 PostgreSQL client database support
1 parent 829498e commit f3d0bbe

File tree

129 files changed

+1141
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1141
-103
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
ALTER TABLE `web_database_user` ADD `database_password_sha2` varchar(70) DEFAULT NULL AFTER `database_password`;
2+
ALTER TABLE `web_database_user` ADD `database_password_postgres` varchar(255) DEFAULT NULL AFTER `database_password_mongo`;
3+
ALTER TABLE `client` ADD `limit_database_postgresql` INT NOT NULL DEFAULT '-1' AFTER `limit_database`;
4+
ALTER TABLE `client_template` ADD `limit_database_postgresql` INT NOT NULL DEFAULT '-1' AFTER `limit_database`;

install/sql/ispconfig3.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ CREATE TABLE `client` (
233233
`default_dbserver` int(11) NOT NULL DEFAULT '1',
234234
`dns_servers` text,
235235
`limit_database` int(11) NOT NULL DEFAULT '-1',
236+
`limit_database_postgresql` int(11) NOT NULL default '-1',
236237
`limit_database_user` int(11) NOT NULL DEFAULT '-1',
237238
`limit_database_quota` int(11) NOT NULL default '-1',
238239
`limit_cron` int(11) NOT NULL DEFAULT '0',
@@ -363,6 +364,7 @@ CREATE TABLE `client_template` (
363364
`limit_dns_record` int(11) NOT NULL default '-1',
364365
`db_servers` text,
365366
`limit_database` int(11) NOT NULL default '-1',
367+
`limit_database_postgresql` int(11) NOT NULL default '-1',
366368
`limit_database_user` int(11) NOT NULL DEFAULT '-1',
367369
`limit_database_quota` int(11) NOT NULL default '-1',
368370
`limit_cron` int(11) NOT NULL default '0',
@@ -1949,6 +1951,7 @@ CREATE TABLE IF NOT EXISTS `web_database_user` (
19491951
`database_password` varchar(64) DEFAULT NULL,
19501952
`database_password_sha2` varchar(70) DEFAULT NULL,
19511953
`database_password_mongo` varchar(32) DEFAULT NULL,
1954+
`database_password_postgres` varchar(255) DEFAULT NULL,
19521955
PRIMARY KEY (`database_user_id`)
19531956
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
19541957

install/tpl/system.ini.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ show_aps_menu=n
4040
client_protection=y
4141
ssh_authentication=
4242
le_caa_autocreate_options=y
43-
43+
postgresql_database=n
4444

4545
[tools]
4646

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2024, Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class crypt {
32+
33+
/**
34+
* Encode passwords for PostgreSQL with scram-sha-256
35+
*
36+
* @param mixed $password
37+
* @return string
38+
*/
39+
40+
public function postgres_scram_sha_256($password) {
41+
$salt = openssl_random_pseudo_bytes(16); // Salt size = 16
42+
$digest_key = hash_pbkdf2("sha256", $password, $salt, 4096, 32, true); // Rounds 4096 and Digest length = 32
43+
$client_key = hash_hmac("sha256", 'Client Key', $digest_key, true);
44+
$stored_key = hash("sha256", $client_key, true);
45+
$server_key = hash_hmac("sha256", 'Server Key', $digest_key, true);
46+
return sprintf('SCRAM-SHA-256$4096:%s$%s:%s', base64_encode($salt), base64_encode($stored_key), base64_encode($server_key));
47+
}
48+
49+
}

interface/lib/classes/tform_base.inc.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,10 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
13791379
} elseif (isset($field['encryption']) && $field['encryption'] == 'MYSQLSHA2') {
13801380
$record[$key] = $app->db->getPasswordHash($record[$key], 'caching_sha2_password');
13811381
$sql_insert_val .= "'".$app->db->quote($record[$key])."', ";
1382+
} elseif (isset($field['encryption']) && $field['encryption'] == 'POSTGRESHA256') {
1383+
$app->uses('crypt');
1384+
$record[$key] = $app->crypt->postgres_scram_sha_256($record[$key]);
1385+
$sql_insert_val .= "'".$app->db->quote($record[$key])."', ";
13821386
} else {
13831387
$record[$key] = md5(stripslashes($record[$key]));
13841388
$sql_insert_val .= "'".$app->db->quote($record[$key])."', ";
@@ -1413,6 +1417,10 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
14131417
} elseif (isset($field['encryption']) && $field['encryption'] == 'MYSQLSHA2') {
14141418
$record[$key] = $app->db->getPasswordHash($record[$key], 'caching_sha2_password');
14151419
$sql_update .= "`$key` = '".$app->db->quote($record[$key])."', ";
1420+
} elseif (isset($field['encryption']) && $field['encryption'] == 'POSTGRESHA256') {
1421+
$app->uses('crypt');
1422+
$record[$key] = $app->crypt->postgres_scram_sha_256($record[$key]);
1423+
$sql_update .= "`$key` = '".$app->db->quote($record[$key])."', ";
14161424
} else {
14171425
$record[$key] = md5(stripslashes($record[$key]));
14181426
$sql_update .= "`$key` = '".$app->db->quote($record[$key])."', ";

interface/web/admin/form/system_config.tform.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,16 @@
252252
'formtype' => 'CHECKBOX',
253253
'default' => 'y',
254254
'value' => array(0 => 'n', 1 => 'y')
255-
),
255+
),
256+
'postgresql_database' => array (
257+
'datatype' => 'VARCHAR',
258+
'formtype' => 'CHECKBOX',
259+
'default' => 'n',
260+
'value' => array (
261+
0 => 'n',
262+
1 => 'y'
263+
)
264+
),
256265
//#################################
257266
// END Datatable fields
258267
//#################################

interface/web/admin/lib/lang/ar_server_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,4 @@ $wb['soft_delete_keep_7_txt'] = 'Purge after 7 days';
358358
$wb['soft_delete_keep_30_txt'] = 'Purge after 30 days';
359359
$wb['soft_delete_keep_90_txt'] = 'Purge after 90 days';
360360
$wb['soft_delete_keep_365_txt'] = 'Purge after 365 days';
361+
$wb['postgresql_database_txt'] = 'PostgreSQL Database';

interface/web/admin/lib/lang/ar_system_config.lng

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ $wb['le_caa_autocreate_options_txt'] = 'Enable automatic creation of CAA record
110110
$wb['show_delete_on_forms_txt'] = 'Show delete button on edit forms';
111111
$wb['dns_external_slave_server_txt'] = 'External DNS servers (comma separated)';
112112
$wb['mailbox_show_last_access_txt'] = 'Show last access time for mail accounts';
113-
?>
113+
$wb['postgresql_database_txt'] = 'PostgreSQL Database';
114+

interface/web/admin/lib/lang/bg_server_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,4 @@ $wb['soft_delete_keep_7_txt'] = 'Purge after 7 days';
358358
$wb['soft_delete_keep_30_txt'] = 'Purge after 30 days';
359359
$wb['soft_delete_keep_90_txt'] = 'Purge after 90 days';
360360
$wb['soft_delete_keep_365_txt'] = 'Purge after 365 days';
361+
$wb['postgresql_database_txt'] = 'PostgreSQL Database';

interface/web/admin/lib/lang/bg_system_config.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ $wb['le_caa_autocreate_options_txt'] = 'Enable automatic creation of CAA record
110110
$wb['show_delete_on_forms_txt'] = 'Show delete button on edit forms';
111111
$wb['dns_external_slave_server_txt'] = 'External DNS servers (comma separated)';
112112
$wb['mailbox_show_last_access_txt'] = 'Show last access time for mail accounts';
113-
?>
113+
$wb['postgresql_database_txt'] = 'PostgreSQL Database';

0 commit comments

Comments
 (0)