- Timestamp:
- 09/21/11 18:13:16 (13 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r123 r128 28 28 &initPermissions &getPermissions &changePermissions &comparePermissions 29 29 &changeGroup 30 & connectDB &finish30 &loadConfig &connectDB &finish 31 31 &addDomain &delDomain &domainName &domainID 32 32 &addGroup &delGroup &getChildren &groupName … … 38 38 &domStatus &importAXFR 39 39 &export 40 %typemap %reverse_typemap 40 %typemap %reverse_typemap %config 41 41 %permissions @permtypes $permlist 42 42 ); … … 47 47 &initPermissions &getPermissions &changePermissions &comparePermissions 48 48 &changeGroup 49 & connectDB &finish49 &loadConfig &connectDB &finish 50 50 &addDomain &delDomain &domainName &domainID 51 51 &addGroup &delGroup &getChildren &groupName … … 57 57 &domStatus &importAXFR 58 58 &export 59 %typemap %reverse_typemap 59 %typemap %reverse_typemap %config 60 60 %permissions @permtypes $permlist 61 61 )] … … 97 97 our %permissions; 98 98 99 # Prepopulate a basic config. Note some of these *will* cause errors if left unset. 100 our %config = ( 101 # Database connection info 102 dbname => 'dnsdb', 103 dbuser => 'dnsdb', 104 dbpass => 'secret', 105 dbhost => '', 106 107 # Email notice settings 108 mailhost => 'smtp.example.com', 109 mailsender => 'dnsdb@example.com', 110 mailname => 'DNS Administration', 111 112 # Template directory 113 templatedir => 'templates/', 114 # fmeh. this is a real web path, not a logical internal one. hm.. 115 # cssdir => 'templates/'; 116 ); 117 118 99 119 ## 100 120 ## Initialization and cleanup subs 101 121 ## 122 123 124 ## DNSDB::loadConfig() 125 # Load the minimum required initial state (DB connect info) from a config file 126 # Load misc other bits while we're at it. 127 # Takes an optional basename and config path to look for 128 # Populates the %config and %def hashes 129 sub loadConfig { 130 my $basename = shift || ''; # this will work OK 131 132 my $deferr = ''; # place to put error from default config file in case we can't find either one 133 134 my $configroot = '/etc/dnsdb'; 135 $configroot = '' if $basename =~ m|^/|; 136 $basename .= ".conf" if $basename !~ /\.conf$/; 137 my $defconfig = "$configroot/dnsdb.conf"; 138 my $siteconfig = "$configroot/$basename"; 139 140 # System defaults 141 __cfgload("$configroot/dnsdb.conf") or $deferr = $errstr; 142 143 # Per-site-ish settings 144 unless (__cfgload("$configroot/$basename")) { 145 $errstr = ($deferr ? "Error opening default config file $defconfig: $deferr\n" : ''). 146 "Error opening site config file $siteconfig"; 147 return; 148 } 149 150 # All good, clear the error and go home. 151 $errstr = ''; 152 return 1; 153 } # end loadConfig() 154 155 156 ## DNSDB::__cfgload() 157 # Private sub to parse a config file and load it into %config 158 # Takes a file handle on an open config file 159 sub __cfgload { 160 $errstr = ''; 161 my $cfgfile = shift; 162 if (open CFG, "<$cfgfile") { 163 # my $mode = ''; 164 while (<CFG>) { 165 chomp; 166 s/^\s*//; 167 next if /^#/; 168 next if /^$/; 169 # hmm. more complex bits in this file might require [heading] headers, maybe? 170 # $mode = $1 if /^\[(a-z)+]/; 171 # DB connect info 172 $config{dbname} = $1 if /^dbname\s*=\s*([a-z0-9_.-]+)/i; 173 $config{dbuser} = $1 if /^dbuser\s*=\s*([a-z0-9_.-]+)/i; 174 $config{dbpass} = $1 if /^dbpass\s*=\s*([a-z0-9_.-]+)/i; 175 $config{dbhost} = $1 if /^dbhost\s*=\s*([a-z0-9_.-]+)/i; 176 # SOA defaults 177 $def{contact} = $1 if /^contact\s*=\s*([a-z0-9_.-]+)/i; 178 $def{prins} = $1 if /^prins\s*=\s*([a-z0-9_.-]+)/i; 179 $def{soattl} = $1 if /^soattl\s*=\s*([a-z0-9_.-]+)/i; 180 $def{refresh} = $1 if /^refresh\s*=\s*([a-z0-9_.-]+)/i; 181 $def{retry} = $1 if /^retry\s*=\s*([a-z0-9_.-]+)/i; 182 $def{expire} = $1 if /^expire\s*=\s*([a-z0-9_.-]+)/i; 183 $def{minttl} = $1 if /^minttl\s*=\s*([a-z0-9_.-]+)/i; 184 $def{ttl} = $1 if /^ttl\s*=\s*([a-z0-9_.-]+)/i; 185 # Mail settings 186 $config{mailhost} = $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i; 187 $config{mailsender} = $1 if /^mailsender\s*=\s*([a-z0-9_.@-]+)/i; 188 $config{mailname} = $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i; 189 } 190 close CFG; 191 } else { 192 $errstr = $!; 193 return; 194 } 195 return 1; 196 } # end __cfgload() 102 197 103 198 -
trunk/dns.cgi
r126 r128 130 130 my $sortorder = "ASC"; 131 131 132 #my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","newdbhost"); 132 # now load some local system defaults (mainly DB connect info) 133 # note this is not *absolutely* fatal, since there's a default dbname/user/pass in DNSDB.pm 134 # we'll catch a bad DB connect string a little further down. 135 if (!loadConfig()) { 136 warn "Using default configuration; unable to load custom settings: $DNSDB::errstr"; 137 } 138 139 ##fixme: quit throwing the database handle around, and put all the SQL and direct DB fiddling into DNSDB.pm 133 140 # dbname, user, pass, host (optional) 134 my ($dbh,$msg) = connectDB("dnsdb", "dnsdb", "secret", "dnsdbhost"); 135 #my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret", 136 # { AutoCommit => 0 }) or die $DBI::errstr; 137 138 ##fixme. PLEASE! <G> 139 print $msg if !$dbh; 140 141 # fiddle hardcoded "defaults" as per system/user (?) prefs 141 my ($dbh,$msg) = connectDB($config{dbname}, $config{dbuser}, $config{dbpass}, $config{dbhost}); 142 143 if (!$dbh) { 144 print "Content-type: text/html\n\n"; 145 print $header->output; 146 my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl"); 147 $errpage->param(errmsg => $msg); 148 print $errpage->output; 149 print $footer->output; 150 exit; 151 } 152 153 # Load config pieces from the database. Ideally all but the DB user/pass/etc should be loaded here. 142 154 initGlobals($dbh); 143 155 -
trunk/templates/dns.css
r117 r128 181 181 text-align: center; 182 182 } 183 /* not sure this really does what I think it does. is it really not 184 possible to center an arbitrary <blah> in some other arbitrary <foo>? */ 185 .loccenter { 186 margin-left: 10%; 187 margin-right: 10%; 188 } 183 189 .maintitle { 184 190 font-size: 1.3em;
Note:
See TracChangeset
for help on using the changeset viewer.