Handle hostnames with upper-case letters
[webmin.git] / postgresql / newdb.cgi
1 #!/usr/local/bin/perl
2 # newdb.cgi
3 # Create a new database with one optional table
4
5 require './postgresql-lib.pl';
6 &ReadParse();
7 $access{'create'} || &error($text{'newdb_ecannot'});
8 &error_setup($text{'newdb_err'});
9
10 # Make sure maximum databases limit has not been exceeded
11 @alldbs = &list_databases();
12 @titles = grep { &can_edit_db($_) } @alldbs;
13 if ($access{'create'} == 2 && @titles >= $access{'max'}) {
14         &error($text{'newdb_ecannot2'});
15         }
16
17 $in{'db'} =~ /^[A-z0-9\.\-]+$/ || &error($text{'newdb_edb'});
18 $cmd = "create database $in{'db'}";
19 if (!$in{'path_def'}) {
20         $in{'path'} =~ /\S/ || &error($text{'newdb_epath'});
21         $cmd .= " with location = '$in{'path'}'";
22         }
23 if (!$in{'user_def'}) {
24         $cmd .= " with owner=\"$in{'user'}\"";
25         }
26 if (!$in{'encoding_def'} && &get_postgresql_version() >= 8) {
27         $in{'encoding'} =~ /\S/ || &error($text{'newdb_eencoding'});
28         $cmd .= " encoding = '$in{'encoding'}'";
29         }
30 if ($in{'template'}) {
31         $cmd .= " template = $in{'template'}";
32         }
33 &execute_sql_logged($config{'basedb'}, $cmd);
34 &webmin_log("create", "db", $in{'db'});
35 if ($access{'dbs'} ne '*') {
36         $access{'dbs'} .= " " if ($access{'dbs'});
37         $access{'dbs'} .= $in{'db'};
38         &save_module_acl(\%access);
39         }
40 &redirect("");
41