mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 08:40:24 +00:00
Some work on PostgreSQL support
This commit is contained in:
@@ -20,6 +20,7 @@ $access{'switch'} = 0 if (&is_readonly_mode());
|
||||
|
||||
# XXX test with postgresql
|
||||
# XXX LDAP support
|
||||
# XXX infinite loop on failure
|
||||
|
||||
=head2 list_users
|
||||
|
||||
@@ -1716,21 +1717,71 @@ sub userdb_table_sql
|
||||
{
|
||||
my ($str) = @_;
|
||||
my ($key, $auto, $idattrkey);
|
||||
if ($str =~ /^(mysql|postgresql):/) {
|
||||
$key = "primary key";
|
||||
}
|
||||
if ($str =~ /^mysql:/) {
|
||||
$auto = "auto_increment";
|
||||
$idattrkey = ", primary key(id, attr)";
|
||||
$idattrmodulekey = ", primary key(id, module, attr)";
|
||||
return ( "create table webmin_user ".
|
||||
"(id int(20) not null primary key auto_increment, ".
|
||||
"name varchar(255) not null, pass varchar(255))",
|
||||
"create table webmin_group ".
|
||||
"(id int(20) not null primary key auto_increment, ".
|
||||
"name varchar(255) not null, ".
|
||||
"description varchar(255))",
|
||||
"create table webmin_user_attr ".
|
||||
"(id int(20) not null, ".
|
||||
"attr varchar(32) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, attr))",
|
||||
"create table webmin_group_attr ".
|
||||
"(id int(20) not null, ".
|
||||
"attr varchar(32) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, attr))",
|
||||
"create table webmin_user_acl ".
|
||||
"(id int(20) not null, ".
|
||||
"module varchar(32) not null, ".
|
||||
"attr varchar(32) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, module, attr))",
|
||||
"create table webmin_group_acl ".
|
||||
"(id int(20) not null, ".
|
||||
"module varchar(32) not null, ".
|
||||
"attr varchar(32) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, module, attr))",
|
||||
);
|
||||
}
|
||||
elsif ($str =~ /^postgresql:/) {
|
||||
return ( "create table webmin_user ".
|
||||
"(id int8 not null primary key, ".
|
||||
"name varchar(255), ".
|
||||
"pass varchar(255))",
|
||||
"create table webmin_group ".
|
||||
"(id int8 not null primary key, ".
|
||||
"name varchar(255), ".
|
||||
"description varchar(255))",
|
||||
"create table webmin_user_attr ".
|
||||
"(id int8 not null, ".
|
||||
"attr varchar(255) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, attr))",
|
||||
"create table webmin_group_attr ".
|
||||
"(id int8 not null, ".
|
||||
"attr varchar(255) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, attr))",
|
||||
"create table webmin_user_acl ".
|
||||
"(id int8 not null, ".
|
||||
"module varchar(255) not null, ".
|
||||
"attr varchar(255) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, module, attr))",
|
||||
"create table webmin_group_acl ".
|
||||
"(id int8 not null, ".
|
||||
"module varchar(255) not null, ".
|
||||
"attr varchar(255) not null, ".
|
||||
"value varchar(255), ".
|
||||
"primary key(id, module, attr))",
|
||||
);
|
||||
}
|
||||
return ( "create table webmin_user (id int(20) not null $key $auto, name varchar(255) not null, pass varchar(255))",
|
||||
"create table webmin_group (id int(20) not null $key $auto, name varchar(255) not null, description varchar(255))",
|
||||
"create table webmin_user_attr (id int(20) not null, attr varchar(32) not null, value varchar(255) $idattrkey)",
|
||||
"create table webmin_group_attr (id int(20) not null, attr varchar(32) not null, value varchar(255) $idattrkey)",
|
||||
"create table webmin_user_acl (id int(20) not null, module varchar(32) not null, attr varchar(32) not null, value varchar(255) $idattrmodulekey)",
|
||||
"create table webmin_group_acl (id int(20) not null, module varchar(32) not null, attr varchar(32) not null, value varchar(255) $idattrmodulekey)",
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -414,7 +414,7 @@ sql_edb=Invalid database name (no spaces allowed)
|
||||
sql_eprefix=Missing or invalid base DN (no spaces allowed)
|
||||
sql_eprefix2=Invalid-looking base DN - should be like <tt>dc=mydomain,dc=com</tt>
|
||||
sql_title2=Create Missing Tables
|
||||
sql_tableerr=User and group database settings were successfully saved, but some tables needed by Webmin are missing : $1
|
||||
sql_tableerr=User and group database settings are valid, but some tables needed by Webmin are missing : $1
|
||||
sql_tableerr2=Click the <b>Create Tables</b> to have them created automatically, or manually run the SQL below.
|
||||
sql_make=Create Tables
|
||||
|
||||
@@ -423,4 +423,4 @@ make_err=Failed to create user and group tables
|
||||
make_exec=Executing SQL $1 ..
|
||||
make_failed=.. creation failed : $1
|
||||
make_done=.. done
|
||||
|
||||
make_still=Some problems were found even after table creation : $1
|
||||
|
||||
@@ -7,13 +7,13 @@ $access{'pass'} || &error($text{'sql_ecannot'});
|
||||
&ReadParse();
|
||||
&error_setup($text{'make_err'});
|
||||
|
||||
$str = $miniserv{'userdb'};
|
||||
$dbh = &connect_userdb($str);
|
||||
$dbh = &connect_userdb($in{'userdb'});
|
||||
ref($dbh) || &error($dbh);
|
||||
|
||||
&ui_print_unbuffered_header(undef, $text{'make_title'}, "");
|
||||
|
||||
foreach $sql (&userdb_table_sql($str)) {
|
||||
# Create the tables
|
||||
foreach $sql (&userdb_table_sql($in{'userdb'})) {
|
||||
print &text('make_exec', "<tt>".&html_escape($sql)."</tt>"),"<br>\n";
|
||||
$cmd = $dbh->prepare($sql);
|
||||
if (!$cmd || !$cmd->execute()) {
|
||||
@@ -24,5 +24,19 @@ foreach $sql (&userdb_table_sql($str)) {
|
||||
}
|
||||
}
|
||||
|
||||
# Check again if OK
|
||||
$err = &validate_userdb($in{'userdb'}, 0);
|
||||
if ($err) {
|
||||
print "<b>",&text('make_still', $err),"</b><p>\n";
|
||||
}
|
||||
else {
|
||||
&lock_file($ENV{'MINISERV_CONFIG'});
|
||||
$miniserv{'userdb'} = $in{'userdb'};
|
||||
$miniserv{'userdb_addto'} = $in{'addto'};
|
||||
&put_miniserv_config(\%miniserv);
|
||||
&unlock_file($ENV{'MINISERV_CONFIG'});
|
||||
&reload_miniserv();
|
||||
}
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
|
||||
@@ -37,22 +37,19 @@ if ($p) {
|
||||
&error($err) if ($err);
|
||||
}
|
||||
|
||||
&lock_file($ENV{'MINISERV_CONFIG'});
|
||||
$miniserv{'userdb'} = $str;
|
||||
$miniserv{'userdb_addto'} = $in{'addto'};
|
||||
&put_miniserv_config(\%miniserv);
|
||||
&unlock_file($ENV{'MINISERV_CONFIG'});
|
||||
&reload_miniserv();
|
||||
&webmin_log("sql");
|
||||
|
||||
# Make sure tables exist
|
||||
$err = &validate_userdb($str, 0);
|
||||
if ($err) {
|
||||
# Tables are missing, need to create first
|
||||
&ui_print_header(undef, $text{'sql_title2'}, "");
|
||||
|
||||
print &text('sql_tableerr', $err),"<p>\n";
|
||||
print $text{'sql_tableerr2'},"<p>\n";
|
||||
print &ui_form_start("maketables.cgi");
|
||||
print &ui_hidden("userdb", $str);
|
||||
print &ui_hidden("userdb_addto", $in{'addto'});
|
||||
print &ui_form_end([ [ undef, $text{'sql_make'} ] ]);
|
||||
|
||||
print &ui_table_start(undef, undef, 2);
|
||||
@@ -65,6 +62,13 @@ if ($err) {
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
}
|
||||
else {
|
||||
# Tables are OK, can save now
|
||||
&lock_file($ENV{'MINISERV_CONFIG'});
|
||||
$miniserv{'userdb'} = $str;
|
||||
$miniserv{'userdb_addto'} = $in{'addto'};
|
||||
&put_miniserv_config(\%miniserv);
|
||||
&unlock_file($ENV{'MINISERV_CONFIG'});
|
||||
&reload_miniserv();
|
||||
&redirect("");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user