diff --git a/acl/acl-lib.pl b/acl/acl-lib.pl index 1e09660b6..3ddd3f692 100755 --- a/acl/acl-lib.pl +++ b/acl/acl-lib.pl @@ -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; diff --git a/acl/lang/en b/acl/lang/en index f85a85457..fcf3bfb1d 100644 --- a/acl/lang/en +++ b/acl/lang/en @@ -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 dc=mydomain,dc=com 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 Create Tables 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 diff --git a/acl/maketables.cgi b/acl/maketables.cgi index 488f264db..8e6b61a00 100755 --- a/acl/maketables.cgi +++ b/acl/maketables.cgi @@ -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', "".&html_escape($sql).""),"
\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 "",&text('make_still', $err),"

\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'}); diff --git a/acl/save_sql.cgi b/acl/save_sql.cgi index 62b94b596..3a747a994 100755 --- a/acl/save_sql.cgi +++ b/acl/save_sql.cgi @@ -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),"

\n"; print $text{'sql_tableerr2'},"

\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(""); }