Changeset 1151
- Timestamp:
- 05/13/08 18:25:02
(2 months ago)
- Author:
- rats
- Message:
* Fixed #1249: ispcp-dmn-mngr beautifying patch
* Updated Catalan
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1150 |
r1151 |
|
| 1 | 1 | ispCP ω 1.0.0 Changelog |
|---|
| 2 | 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 3 | |
|---|
| | 4 | 2008-05-13 Benedikt Heintel |
|---|
| | 5 | - ENGINE: |
|---|
| | 6 | * Fixed #1249: ispcp-dmn-mngr beautifying patch |
|---|
| | 7 | - LANGUAGES: |
|---|
| | 8 | * Updated Catalan |
|---|
| 3 | 9 | |
|---|
| 4 | 10 | 2008-05-12 Benedikt Heintel |
|---|
| r1135 |
r1151 |
|
| 1 | 1 | #!/usr/bin/perl |
|---|
| 2 | | |
|---|
| 3 | 2 | # ispCP ω (OMEGA) a Virtual Hosting Control Panel |
|---|
| 4 | 3 | # Copyright (c) 2001-2006 by moleSoftware GmbH |
|---|
| … | … | |
| 34 | 33 | use lib "$FindBin::Bin/"; |
|---|
| 35 | 34 | require 'ispcp_common_code.pl'; |
|---|
| 36 | | |
|---|
| 37 | 35 | use strict; |
|---|
| 38 | | |
|---|
| 39 | 36 | use warnings; |
|---|
| 40 | | |
|---|
| 41 | 37 | use Net::LibIDN ':all'; |
|---|
| 42 | | |
|---|
| 43 | 38 | $main::dmn_task_id = undef; |
|---|
| 44 | 39 | |
|---|
| … | … | |
| 49 | 44 | ## Start Up! |
|---|
| 50 | 45 | ## |
|---|
| 51 | | |
|---|
| 52 | 46 | sub dmn_mngr_start_up { |
|---|
| 53 | | |
|---|
| 54 | | my ($rs, $rdata) = (undef, undef); |
|---|
| 55 | | |
|---|
| 56 | | push_el(\@main::el, 'dmn_mngr_start_up()', 'Starting...'); |
|---|
| 57 | | |
|---|
| 58 | | # checking for master process; |
|---|
| 59 | | |
|---|
| 60 | | $rs = check_master(); |
|---|
| 61 | | |
|---|
| 62 | | return $rs if ($rs != 0); |
|---|
| 63 | | |
|---|
| 64 | | # Let's clear Execution Logs, if any. |
|---|
| 65 | | |
|---|
| 66 | | if (-e $main::ispcp_dmn_mngr_el) { |
|---|
| 67 | | |
|---|
| 68 | | $rs = del_file($main::ispcp_dmn_mngr_el); |
|---|
| 69 | | |
|---|
| 70 | | return $rs if ($rs != 0); |
|---|
| 71 | | |
|---|
| 72 | | } |
|---|
| 73 | | |
|---|
| 74 | | # config check; |
|---|
| 75 | | |
|---|
| 76 | | $rs = get_conf(); |
|---|
| 77 | | |
|---|
| 78 | | return $rs if ($rs != 0); |
|---|
| 79 | | |
|---|
| 80 | | # sql check; |
|---|
| 81 | | |
|---|
| 82 | | # |
|---|
| 83 | | # getting initial data also must be done here; |
|---|
| 84 | | # |
|---|
| 85 | | |
|---|
| 86 | | my $sql = "select admin_id from admin where admin_id = 1;"; |
|---|
| 87 | | |
|---|
| 88 | | ($rs, $rdata) = doSQL($sql); |
|---|
| 89 | | |
|---|
| 90 | | return $rs if ($rs != 0); |
|---|
| 91 | | |
|---|
| 92 | | # |
|---|
| 93 | | # getting task id and domain record id; |
|---|
| 94 | | # |
|---|
| 95 | | |
|---|
| 96 | | $main::dmn_task_id = $ARGV[0]; |
|---|
| 97 | | |
|---|
| 98 | | push_el(\@main::el, 'dmn_mngr_start_up()', 'Ending...'); |
|---|
| 99 | | |
|---|
| 100 | | return 0; |
|---|
| 101 | | |
|---|
| | 47 | my ($rs, $rdata) = (undef, undef); |
|---|
| | 48 | |
|---|
| | 49 | push_el(\@main::el, 'dmn_mngr_start_up()', 'Starting...'); |
|---|
| | 50 | |
|---|
| | 51 | # checking for master process; |
|---|
| | 52 | $rs = check_master(); |
|---|
| | 53 | return $rs if ($rs != 0); |
|---|
| | 54 | |
|---|
| | 55 | # Let's clear Execution Logs, if any. |
|---|
| | 56 | if (-e $main::ispcp_dmn_mngr_el) { |
|---|
| | 57 | $rs = del_file($main::ispcp_dmn_mngr_el); |
|---|
| | 58 | return $rs if ($rs != 0); |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | # config check; |
|---|
| | 62 | $rs = get_conf(); |
|---|
| | 63 | return $rs if ($rs != 0); |
|---|
| | 64 | |
|---|
| | 65 | # sql check; |
|---|
| | 66 | # |
|---|
| | 67 | # getting initial data also must be done here; |
|---|
| | 68 | # |
|---|
| | 69 | my $sql = "select admin_id from admin where admin_id = 1;"; |
|---|
| | 70 | ($rs, $rdata) = doSQL($sql); |
|---|
| | 71 | return $rs if ($rs != 0); |
|---|
| | 72 | |
|---|
| | 73 | # |
|---|
| | 74 | # getting task id and domain record id; |
|---|
| | 75 | # |
|---|
| | 76 | $main::dmn_task_id = $ARGV[0]; |
|---|
| | 77 | |
|---|
| | 78 | push_el(\@main::el, 'dmn_mngr_start_up()', 'Ending...'); |
|---|
| | 79 | return 0; |
|---|
| 102 | 80 | } |
|---|
| 103 | 81 | |
|---|
| … | … | |
| 106 | 84 | ## Shut Down! |
|---|
| 107 | 85 | ## |
|---|
| 108 | | |
|---|
| 109 | 86 | sub dmn_mngr_shut_down { |
|---|
| 110 | | |
|---|
| 111 | | my $rs = undef; |
|---|
| 112 | | |
|---|
| 113 | | push_el(\@main::el, 'dmn_mngr_shut_down()', 'Starting...'); |
|---|
| 114 | | |
|---|
| 115 | | push_el(\@main::el, 'dmn_mngr_shut_down()', 'Ending...'); |
|---|
| 116 | | |
|---|
| 117 | | return 0; |
|---|
| 118 | | |
|---|
| | 87 | push_el(\@main::el, 'dmn_mngr_shut_down()', 'Done...'); |
|---|
| | 88 | return 0; |
|---|
| 119 | 89 | } |
|---|
| 120 | 90 | |
|---|
| 121 | 91 | ###################################### DNS ##################################### |
|---|
| 122 | | |
|---|
| 123 | 92 | ################################################################################ |
|---|
| 124 | 93 | ## |
|---|
| 125 | 94 | ## Add DNS CFG Data |
|---|
| 126 | 95 | ## |
|---|
| 127 | | |
|---|
| 128 | 96 | sub dmn_add_named_cfg_data { |
|---|
| 129 | | |
|---|
| 130 | | my ($dmn_data) = @_; |
|---|
| 131 | | |
|---|
| 132 | | my ($rs, $rdata) = (undef, undef); |
|---|
| 133 | | |
|---|
| 134 | | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'Starting...'); |
|---|
| 135 | | |
|---|
| 136 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 137 | | |
|---|
| 138 | | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 139 | | |
|---|
| 140 | | return -1; |
|---|
| 141 | | |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | # |
|---|
| 145 | | # Initial data we need; |
|---|
| 146 | | # |
|---|
| 147 | | |
|---|
| 148 | | my $dmn_name = @$dmn_data[1]; |
|---|
| 149 | | |
|---|
| 150 | | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 151 | | |
|---|
| 152 | | my $sys_cfg = $main::cfg{'BIND_CONF_FILE'}; |
|---|
| 153 | | |
|---|
| 154 | | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 155 | | |
|---|
| 156 | | |
|---|
| 157 | | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 158 | | |
|---|
| 159 | | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 160 | | |
|---|
| 161 | | my $working_dir = "$conf_dir/bind/working"; |
|---|
| 162 | | |
|---|
| 163 | | |
|---|
| 164 | | my $timestamp = time; |
|---|
| 165 | | |
|---|
| 166 | | my $backup_cfg = "$backup_dir/named.conf.$timestamp"; |
|---|
| 167 | | |
|---|
| 168 | | my $working_cfg = "$working_dir/named.conf"; |
|---|
| 169 | | |
|---|
| 170 | | # |
|---|
| 171 | | # BEGIN/END tags, and templates needed for this config; |
|---|
| 172 | | # |
|---|
| 173 | | |
|---|
| 174 | | my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', ''); |
|---|
| 175 | | |
|---|
| 176 | | ( |
|---|
| 177 | | $rs, |
|---|
| 178 | | $dta_b, |
|---|
| 179 | | $dta_e, |
|---|
| 180 | | $entry_b, |
|---|
| 181 | | $entry_e, |
|---|
| 182 | | $entry |
|---|
| 183 | | ) = get_tpl( |
|---|
| 184 | | $tpl_dir, |
|---|
| 185 | | 'cfg_dta_b.tpl', |
|---|
| 186 | | 'cfg_dta_e.tpl', |
|---|
| 187 | | 'cfg_entry_b.tpl', |
|---|
| 188 | | 'cfg_entry_e.tpl', |
|---|
| 189 | | 'cfg_entry.tpl' |
|---|
| 190 | | ); |
|---|
| 191 | | |
|---|
| 192 | | return $rs if ($rs != 0); |
|---|
| 193 | | |
|---|
| 194 | | # |
|---|
| 195 | | # Let's construct nedded tags and entries; |
|---|
| 196 | | # |
|---|
| 197 | | |
|---|
| 198 | | my %tag_hash = ( |
|---|
| 199 | | '{DMN_NAME}' => $dmn_name, |
|---|
| 200 | | '{DB_DIR}' => $named_db_dir |
|---|
| 201 | | ); |
|---|
| 202 | | |
|---|
| 203 | | my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', ''); |
|---|
| 204 | | |
|---|
| 205 | | ( |
|---|
| 206 | | $rs, |
|---|
| 207 | | $entry_b_val, |
|---|
| 208 | | $entry_e_val, |
|---|
| 209 | | $entry_val |
|---|
| 210 | | ) = prep_tpl( |
|---|
| 211 | | \%tag_hash, |
|---|
| 212 | | $entry_b, |
|---|
| 213 | | $entry_e, |
|---|
| 214 | | $entry |
|---|
| 215 | | ); |
|---|
| 216 | | |
|---|
| 217 | | return $rs if ($rs != 0); |
|---|
| 218 | | |
|---|
| 219 | | # |
|---|
| 220 | | # Let's get Sytem and Workind config files; |
|---|
| 221 | | # |
|---|
| 222 | | |
|---|
| 223 | | my ($sys, $working) = ('', ''); |
|---|
| 224 | | |
|---|
| 225 | | |
|---|
| 226 | | ($rs, $sys) = get_file($sys_cfg); |
|---|
| 227 | | |
|---|
| 228 | | return $rs if ($rs != 0); |
|---|
| 229 | | |
|---|
| 230 | | ($rs, $working) = get_file($working_cfg); |
|---|
| 231 | | |
|---|
| 232 | | return $rs if ($rs != 0); |
|---|
| 233 | | |
|---|
| 234 | | ($rs, $rdata) = get_tag($dta_b, $dta_e, $working); |
|---|
| 235 | | |
|---|
| 236 | | return $rs if ($rs != 0); |
|---|
| 237 | | |
|---|
| 238 | | # |
|---|
| 239 | | # Is the new domain entry exists ? |
|---|
| 240 | | # |
|---|
| 241 | | |
|---|
| 242 | | ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working); |
|---|
| 243 | | |
|---|
| 244 | | if ($rs == 0) { |
|---|
| 245 | | |
|---|
| 246 | | # Yes it exists ! Then we must delete it ! |
|---|
| 247 | | |
|---|
| 248 | | ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working); |
|---|
| 249 | | |
|---|
| 250 | | return $rs if ($rs != 0); |
|---|
| 251 | | |
|---|
| 252 | | } |
|---|
| 253 | | |
|---|
| 254 | | ($rs, $rdata) = get_tag($entry_b, $entry_e, $working); |
|---|
| 255 | | |
|---|
| 256 | | return $rs if ($rs != 0); |
|---|
| 257 | | |
|---|
| 258 | | # |
|---|
| 259 | | # Let's contruct the replacement and do it; |
|---|
| 260 | | # |
|---|
| 261 | | |
|---|
| 262 | | my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e"; |
|---|
| 263 | | |
|---|
| 264 | | ($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl, "dmn_add_named_cfg_data"); |
|---|
| 265 | | |
|---|
| 266 | | return $rs if ($rs != 0); |
|---|
| 267 | | |
|---|
| 268 | | # |
|---|
| 269 | | # Here we'll backup production config file; |
|---|
| 270 | | # |
|---|
| 271 | | |
|---|
| 272 | | $rs = sys_command("$main::cfg{'CMD_CP'} -p $sys_cfg $backup_cfg"); |
|---|
| 273 | | |
|---|
| 274 | | return $rs if ($rs != 0); |
|---|
| 275 | | |
|---|
| 276 | | # |
|---|
| 277 | | # Let's save working copy; |
|---|
| 278 | | # |
|---|
| 279 | | |
|---|
| 280 | | $rs = store_file($working_cfg, $working, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 281 | | |
|---|
| 282 | | return $rs if ($rs != 0); |
|---|
| 283 | | |
|---|
| 284 | | # |
|---|
| 285 | | # Here we'll replace data in production config file with data in working |
|---|
| 286 | | # confing file. A little workaround will be done. If working copy data does not exist |
|---|
| 287 | | # in production config then we will add it; |
|---|
| 288 | | # |
|---|
| 289 | | |
|---|
| 290 | | ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys); |
|---|
| 291 | | |
|---|
| 292 | | if ($rs == 0) { # YES ! Data is here ! /in production config file/; |
|---|
| 293 | | |
|---|
| 294 | | ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working, "dmn_add_named_cfg_data"); |
|---|
| 295 | | |
|---|
| 296 | | return $rs if ($rs != 0); |
|---|
| 297 | | |
|---|
| 298 | | } elsif ($rs == -5) { |
|---|
| 299 | | |
|---|
| 300 | | $sys .= $working; |
|---|
| 301 | | |
|---|
| 302 | | } else { |
|---|
| 303 | | |
|---|
| 304 | | return $rs; |
|---|
| 305 | | |
|---|
| 306 | | } |
|---|
| 307 | | |
|---|
| 308 | | $rs = store_file($sys_cfg, $sys, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 309 | | |
|---|
| 310 | | return $rs if ($rs != 0); |
|---|
| 311 | | |
|---|
| 312 | | |
|---|
| 313 | | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'Ending...'); |
|---|
| 314 | | |
|---|
| 315 | | return 0; |
|---|
| | 97 | my ($dmn_data) = @_; |
|---|
| | 98 | my ($rs, $rdata) = (undef, undef); |
|---|
| | 99 | |
|---|
| | 100 | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'Starting...'); |
|---|
| | 101 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| | 102 | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| | 103 | return -1; |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | # |
|---|
| | 107 | # Initial data we need; |
|---|
| | 108 | # |
|---|
| | 109 | my $dmn_name = @$dmn_data[1]; |
|---|
| | 110 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| | 111 | my $sys_cfg = $main::cfg{'BIND_CONF_FILE'}; |
|---|
| | 112 | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| | 113 | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| | 114 | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| | 115 | my $working_dir = "$conf_dir/bind/working"; |
|---|
| | 116 | my $timestamp = time; |
|---|
| | 117 | my $backup_cfg = "$backup_dir/named.conf.$timestamp"; |
|---|
| | 118 | my $working_cfg = "$working_dir/named.conf"; |
|---|
| | 119 | |
|---|
| | 120 | # |
|---|
| | 121 | # BEGIN/END tags, and templates needed for this config; |
|---|
| | 122 | # |
|---|
| | 123 | my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', ''); |
|---|
| | 124 | ( |
|---|
| | 125 | $rs, |
|---|
| | 126 | $dta_b, |
|---|
| | 127 | $dta_e, |
|---|
| | 128 | $entry_b, |
|---|
| | 129 | $entry_e, |
|---|
| | 130 | $entry |
|---|
| | 131 | ) = get_tpl( |
|---|
| | 132 | $tpl_dir, |
|---|
| | 133 | 'cfg_dta_b.tpl', |
|---|
| | 134 | 'cfg_dta_e.tpl', |
|---|
| | 135 | 'cfg_entry_b.tpl', |
|---|
| | 136 | 'cfg_entry_e.tpl', |
|---|
| | 137 | 'cfg_entry.tpl' |
|---|
| | 138 | ); |
|---|
| | 139 | return $rs if ($rs != 0); |
|---|
| | 140 | |
|---|
| | 141 | # |
|---|
| | 142 | # Let's construct nedded tags and entries; |
|---|
| | 143 | # |
|---|
| | 144 | my %tag_hash = ( |
|---|
| | 145 | '{DMN_NAME}' => $dmn_name, |
|---|
| | 146 | '{DB_DIR}' => $named_db_dir |
|---|
| | 147 | ); |
|---|
| | 148 | my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', ''); |
|---|
| | 149 | ( |
|---|
| | 150 | $rs, |
|---|
| | 151 | $entry_b_val, |
|---|
| | 152 | $entry_e_val, |
|---|
| | 153 | $entry_val |
|---|
| | 154 | ) = prep_tpl( |
|---|
| | 155 | \%tag_hash, |
|---|
| | 156 | $entry_b, |
|---|
| | 157 | $entry_e, |
|---|
| | 158 | $entry |
|---|
| | 159 | ); |
|---|
| | 160 | return $rs if ($rs != 0); |
|---|
| | 161 | |
|---|
| | 162 | # |
|---|
| | 163 | # Let's get Sytem and Workind config files; |
|---|
| | 164 | # |
|---|
| | 165 | my ($sys, $working) = ('', ''); |
|---|
| | 166 | |
|---|
| | 167 | ($rs, $sys) = get_file($sys_cfg); |
|---|
| | 168 | return $rs if ($rs != 0); |
|---|
| | 169 | |
|---|
| | 170 | ($rs, $working) = get_file($working_cfg); |
|---|
| | 171 | return $rs if ($rs != 0); |
|---|
| | 172 | |
|---|
| | 173 | ($rs, $rdata) = get_tag($dta_b, $dta_e, $working); |
|---|
| | 174 | return $rs if ($rs != 0); |
|---|
| | 175 | |
|---|
| | 176 | # |
|---|
| | 177 | # Is the new domain entry exists ? |
|---|
| | 178 | # |
|---|
| | 179 | ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working); |
|---|
| | 180 | if ($rs == 0) { |
|---|
| | 181 | # Yes it exists ! Then we must delete it ! |
|---|
| | 182 | ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working); |
|---|
| | 183 | return $rs if ($rs != 0); |
|---|
| | 184 | } |
|---|
| | 185 | ($rs, $rdata) = get_tag($entry_b, $entry_e, $working); |
|---|
| | 186 | return $rs if ($rs != 0); |
|---|
| | 187 | |
|---|
| | 188 | # |
|---|
| | 189 | # Let's contruct the replacement and do it; |
|---|
| | 190 | # |
|---|
| | 191 | my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e"; |
|---|
| | 192 | ($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl, "dmn_add_named_cfg_data"); |
|---|
| | 193 | return $rs if ($rs != 0); |
|---|
| | 194 | |
|---|
| | 195 | # |
|---|
| | 196 | # Here we'll backup production config file; |
|---|
| | 197 | # |
|---|
| | 198 | $rs = sys_command("$main::cfg{'CMD_CP'} -p $sys_cfg $backup_cfg"); |
|---|
| | 199 | return $rs if ($rs != 0); |
|---|
| | 200 | |
|---|
| | 201 | # |
|---|
| | 202 | # Let's save working copy; |
|---|
| | 203 | # |
|---|
| | 204 | $rs = store_file($working_cfg, $working, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 205 | return $rs if ($rs != 0); |
|---|
| | 206 | |
|---|
| | 207 | # |
|---|
| | 208 | # Here we'll replace data in production config file with data in working |
|---|
| | 209 | # confing file. A little workaround will be done. If working copy data does not exist |
|---|
| | 210 | # in production config then we will add it; |
|---|
| | 211 | # |
|---|
| | 212 | ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys); |
|---|
| | 213 | if ($rs == 0) { # YES ! Data is here ! /in production config file/; |
|---|
| | 214 | ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working, "dmn_add_named_cfg_data"); |
|---|
| | 215 | return $rs if ($rs != 0); |
|---|
| | 216 | } elsif ($rs == -5) { |
|---|
| | 217 | $sys .= $working; |
|---|
| | 218 | } else { |
|---|
| | 219 | return $rs; |
|---|
| | 220 | } |
|---|
| | 221 | $rs = store_file($sys_cfg, $sys, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 222 | return $rs if ($rs != 0); |
|---|
| | 223 | |
|---|
| | 224 | push_el(\@main::el, 'dmn_add_named_cfg_data()', 'Ending...'); |
|---|
| | 225 | return 0; |
|---|
| 316 | 226 | } |
|---|
| 317 | 227 | |
|---|
| … | … | |
| 320 | 230 | ## Delete DNS CFG Data |
|---|
| 321 | 231 | ## |
|---|
| 322 | | |
|---|
| 323 | 232 | sub dmn_del_named_cfg_data { |
|---|
| 324 | | |
|---|
| 325 | | my ($dmn_data) = @_; |
|---|
| 326 | | |
|---|
| 327 | | my ($rs, $rdata) = (undef, undef); |
|---|
| 328 | | |
|---|
| 329 | | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'Starting...'); |
|---|
| 330 | | |
|---|
| 331 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 332 | | |
|---|
| 333 | | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 334 | | |
|---|
| 335 | | return -1; |
|---|
| 336 | | |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | # |
|---|
| 340 | | # Initial data we need; |
|---|
| 341 | | # |
|---|
| 342 | | |
|---|
| 343 | | my $dmn_name = @$dmn_data[1]; |
|---|
| 344 | | |
|---|
| 345 | | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 346 | | |
|---|
| 347 | | my $sys_cfg = $main::cfg{'BIND_CONF_FILE'}; |
|---|
| 348 | | |
|---|
| 349 | | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 350 | | |
|---|
| 351 | | |
|---|
| 352 | | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 353 | | |
|---|
| 354 | | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 355 | | |
|---|
| 356 | | my $working_dir = "$conf_dir/bind/working"; |
|---|
| 357 | | |
|---|
| 358 | | |
|---|
| 359 | | my $timestamp = time; |
|---|
| 360 | | |
|---|
| 361 | | my $backup_cfg = "$backup_dir/named.conf.$timestamp"; |
|---|
| 362 | | |
|---|
| 363 | | my $working_cfg = "$working_dir/named.conf"; |
|---|
| 364 | | |
|---|
| 365 | | # |
|---|
| 366 | | # BEGIN/END tags, and templates needed for this config; |
|---|
| 367 | | # |
|---|
| 368 | | |
|---|
| 369 | | my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', ''); |
|---|
| 370 | | |
|---|
| 371 | | ( |
|---|
| 372 | | $rs, |
|---|
| 373 | | $dta_b, |
|---|
| 374 | | $dta_e, |
|---|
| 375 | | $entry_b, |
|---|
| 376 | | $entry_e, |
|---|
| 377 | | $entry |
|---|
| 378 | | ) = get_tpl( |
|---|
| 379 | | $tpl_dir, |
|---|
| 380 | | 'cfg_dta_b.tpl', |
|---|
| 381 | | 'cfg_dta_e.tpl', |
|---|
| 382 | | 'cfg_entry_b.tpl', |
|---|
| 383 | | 'cfg_entry_e.tpl', |
|---|
| 384 | | 'cfg_entry.tpl' |
|---|
| 385 | | ); |
|---|
| 386 | | |
|---|
| 387 | | return $rs if ($rs != 0); |
|---|
| 388 | | |
|---|
| 389 | | # |
|---|
| 390 | | # Let's construct nedded tags and entries; |
|---|
| 391 | | # |
|---|
| 392 | | |
|---|
| 393 | | my %tag_hash = ( |
|---|
| 394 | | '{DMN_NAME}' => $dmn_name, |
|---|
| 395 | | '{DB_DIR}' => $named_db_dir |
|---|
| 396 | | ); |
|---|
| 397 | | |
|---|
| 398 | | my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', ''); |
|---|
| 399 | | |
|---|
| 400 | | ( |
|---|
| 401 | | $rs, |
|---|
| 402 | | $entry_b_val, |
|---|
| 403 | | $entry_e_val, |
|---|
| 404 | | $entry_val |
|---|
| 405 | | ) = prep_tpl( |
|---|
| 406 | | \%tag_hash, |
|---|
| 407 | | $entry_b, |
|---|
| 408 | | $entry_e, |
|---|
| 409 | | $entry |
|---|
| 410 | | ); |
|---|
| 411 | | |
|---|
| 412 | | return $rs if ($rs != 0); |
|---|
| 413 | | |
|---|
| 414 | | # |
|---|
| 415 | | # Let's get Sytem and Workind config files; |
|---|
| 416 | | # |
|---|
| 417 | | |
|---|
| 418 | | my ($sys, $working) = ('', ''); |
|---|
| 419 | | |
|---|
| 420 | | |
|---|
| 421 | | ($rs, $sys) = get_file($sys_cfg); |
|---|
| 422 | | |
|---|
| 423 | | return $rs if ($rs != 0); |
|---|
| 424 | | |
|---|
| 425 | | ($rs, $working) = get_file($working_cfg); |
|---|
| 426 | | |
|---|
| 427 | | return $rs if ($rs != 0); |
|---|
| 428 | | |
|---|
| 429 | | ($rs, $rdata) = get_tag($dta_b, $dta_e, $working); |
|---|
| 430 | | |
|---|
| 431 | | return $rs if ($rs != 0); |
|---|
| 432 | | |
|---|
| 433 | | # |
|---|
| 434 | | # Is the new domain entry exists ? |
|---|
| 435 | | # |
|---|
| 436 | | |
|---|
| 437 | | ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working); |
|---|
| 438 | | |
|---|
| 439 | | if ($rs == 0) { |
|---|
| 440 | | |
|---|
| 441 | | # Yes it exists ! Then we must delete it ! |
|---|
| 442 | | |
|---|
| 443 | | ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working); |
|---|
| 444 | | |
|---|
| 445 | | return $rs if ($rs != 0); |
|---|
| 446 | | |
|---|
| 447 | | } |
|---|
| 448 | | |
|---|
| 449 | | ($rs, $rdata) = get_tag($entry_b, $entry_e, $working); |
|---|
| 450 | | |
|---|
| 451 | | return $rs if ($rs != 0); |
|---|
| 452 | | |
|---|
| 453 | | # |
|---|
| 454 | | # Let's contruct the replacement and do it; |
|---|
| 455 | | # |
|---|
| 456 | | # |
|---|
| 457 | | #my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e"; |
|---|
| 458 | | # |
|---|
| 459 | | #($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl); |
|---|
| 460 | | # |
|---|
| 461 | | #return $rs if ($rs != 0); |
|---|
| 462 | | # |
|---|
| 463 | | |
|---|
| 464 | | # |
|---|
| 465 | | # Here we'll backup production config file; |
|---|
| 466 | | # |
|---|
| 467 | | |
|---|
| 468 | | $rs = sys_command("$main::cfg{'CMD_CP'} -p $sys_cfg $backup_cfg"); |
|---|
| 469 | | |
|---|
| 470 | | return $rs if ($rs != 0); |
|---|
| 471 | | |
|---|
| 472 | | # |
|---|
| 473 | | # Let's save working copy; |
|---|
| 474 | | # |
|---|
| 475 | | |
|---|
| 476 | | $rs = store_file($working_cfg, $working, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 477 | | |
|---|
| 478 | | return $rs if ($rs != 0); |
|---|
| 479 | | |
|---|
| 480 | | # |
|---|
| 481 | | # Here we'll replace data in production config file with data in working |
|---|
| 482 | | # confing file. A little workaround will be done. If working copy data does not exist |
|---|
| 483 | | # in production config then we will add it; |
|---|
| 484 | | # |
|---|
| 485 | | |
|---|
| 486 | | ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys); |
|---|
| 487 | | |
|---|
| 488 | | if ($rs == 0) { # YES ! Data is here ! /in production config file/; |
|---|
| 489 | | |
|---|
| 490 | | ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working, "dmn_del_named_cfg_data"); |
|---|
| 491 | | |
|---|
| 492 | | return $rs if ($rs != 0); |
|---|
| 493 | | |
|---|
| 494 | | } elsif ($rs == -5) { |
|---|
| 495 | | |
|---|
| 496 | | $sys .= $working; |
|---|
| 497 | | |
|---|
| 498 | | } else { |
|---|
| 499 | | |
|---|
| 500 | | return $rs; |
|---|
| 501 | | |
|---|
| 502 | | } |
|---|
| 503 | | |
|---|
| 504 | | $rs = store_file($sys_cfg, $sys, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 505 | | |
|---|
| 506 | | return $rs if ($rs != 0); |
|---|
| 507 | | |
|---|
| 508 | | |
|---|
| 509 | | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'Ending...'); |
|---|
| 510 | | |
|---|
| 511 | | return 0; |
|---|
| | 233 | my ($dmn_data) = @_; |
|---|
| | 234 | my ($rs, $rdata) = (undef, undef); |
|---|
| | 235 | |
|---|
| | 236 | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'Starting...'); |
|---|
| | 237 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| | 238 | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| | 239 | return -1; |
|---|
| | 240 | } |
|---|
| | 241 | |
|---|
| | 242 | # |
|---|
| | 243 | # Initial data we need; |
|---|
| | 244 | # |
|---|
| | 245 | my $dmn_name = @$dmn_data[1]; |
|---|
| | 246 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| | 247 | my $sys_cfg = $main::cfg{'BIND_CONF_FILE'}; |
|---|
| | 248 | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| | 249 | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| | 250 | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| | 251 | my $working_dir = "$conf_dir/bind/working"; |
|---|
| | 252 | my $timestamp = time; |
|---|
| | 253 | my $backup_cfg = "$backup_dir/named.conf.$timestamp"; |
|---|
| | 254 | my $working_cfg = "$working_dir/named.conf"; |
|---|
| | 255 | |
|---|
| | 256 | # |
|---|
| | 257 | # BEGIN/END tags, and templates needed for this config; |
|---|
| | 258 | # |
|---|
| | 259 | my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', ''); |
|---|
| | 260 | ( |
|---|
| | 261 | $rs, |
|---|
| | 262 | $dta_b, |
|---|
| | 263 | $dta_e, |
|---|
| | 264 | $entry_b, |
|---|
| | 265 | $entry_e, |
|---|
| | 266 | $entry |
|---|
| | 267 | ) = get_tpl( |
|---|
| | 268 | $tpl_dir, |
|---|
| | 269 | 'cfg_dta_b.tpl', |
|---|
| | 270 | 'cfg_dta_e.tpl', |
|---|
| | 271 | 'cfg_entry_b.tpl', |
|---|
| | 272 | 'cfg_entry_e.tpl', |
|---|
| | 273 | 'cfg_entry.tpl' |
|---|
| | 274 | ); |
|---|
| | 275 | return $rs if ($rs != 0); |
|---|
| | 276 | |
|---|
| | 277 | # |
|---|
| | 278 | # Let's construct nedded tags and entries; |
|---|
| | 279 | # |
|---|
| | 280 | my %tag_hash = ( |
|---|
| | 281 | '{DMN_NAME}' => $dmn_name, |
|---|
| | 282 | '{DB_DIR}' => $named_db_dir |
|---|
| | 283 | ); |
|---|
| | 284 | my ($entry_b_val, $entry_e_val, $entry_val) = ('', '', ''); |
|---|
| | 285 | ( |
|---|
| | 286 | $rs, |
|---|
| | 287 | $entry_b_val, |
|---|
| | 288 | $entry_e_val, |
|---|
| | 289 | $entry_val |
|---|
| | 290 | ) = prep_tpl( |
|---|
| | 291 | \%tag_hash, |
|---|
| | 292 | $entry_b, |
|---|
| | 293 | $entry_e, |
|---|
| | 294 | $entry |
|---|
| | 295 | ); |
|---|
| | 296 | return $rs if ($rs != 0); |
|---|
| | 297 | |
|---|
| | 298 | # |
|---|
| | 299 | # Let's get Sytem and Workind config files; |
|---|
| | 300 | # |
|---|
| | 301 | my ($sys, $working) = ('', ''); |
|---|
| | 302 | |
|---|
| | 303 | ($rs, $sys) = get_file($sys_cfg); |
|---|
| | 304 | return $rs if ($rs != 0); |
|---|
| | 305 | |
|---|
| | 306 | ($rs, $working) = get_file($working_cfg); |
|---|
| | 307 | return $rs if ($rs != 0); |
|---|
| | 308 | |
|---|
| | 309 | ($rs, $rdata) = get_tag($dta_b, $dta_e, $working); |
|---|
| | 310 | return $rs if ($rs != 0); |
|---|
| | 311 | |
|---|
| | 312 | # |
|---|
| | 313 | # Is the new domain entry exists ? |
|---|
| | 314 | # |
|---|
| | 315 | ($rs, $rdata) = get_tag($entry_b_val, $entry_e_val, $working); |
|---|
| | 316 | if ($rs == 0) { |
|---|
| | 317 | # Yes it exists ! Then we must delete it ! |
|---|
| | 318 | ($rs, $working) = del_tag($entry_b_val, "$entry_e_val\n", $working); |
|---|
| | 319 | return $rs if ($rs != 0); |
|---|
| | 320 | } |
|---|
| | 321 | ($rs, $rdata) = get_tag($entry_b, $entry_e, $working); |
|---|
| | 322 | return $rs if ($rs != 0); |
|---|
| | 323 | |
|---|
| | 324 | # |
|---|
| | 325 | # Let's contruct the replacement and do it; |
|---|
| | 326 | # |
|---|
| | 327 | # |
|---|
| | 328 | #my $entry_repl = "$entry_b_val$entry_val$entry_e_val\n$entry_b$entry_e"; |
|---|
| | 329 | # |
|---|
| | 330 | #($rs, $working) = repl_tag($entry_b, $entry_e, $working, $entry_repl); |
|---|
| | 331 | # |
|---|
| | 332 | #return $rs if ($rs != 0); |
|---|
| | 333 | # |
|---|
| | 334 | # |
|---|
| | 335 | # Here we'll backup production config file; |
|---|
| | 336 | # |
|---|
| | 337 | $rs = sys_command("$main::cfg{'CMD_CP'} -p $sys_cfg $backup_cfg"); |
|---|
| | 338 | return $rs if ($rs != 0); |
|---|
| | 339 | |
|---|
| | 340 | # |
|---|
| | 341 | # Let's save working copy; |
|---|
| | 342 | # |
|---|
| | 343 | $rs = store_file($working_cfg, $working, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 344 | return $rs if ($rs != 0); |
|---|
| | 345 | |
|---|
| | 346 | # |
|---|
| | 347 | # Here we'll replace data in production config file with data in working |
|---|
| | 348 | # confing file. A little workaround will be done. If working copy data does not exist |
|---|
| | 349 | # in production config then we will add it; |
|---|
| | 350 | # |
|---|
| | 351 | ($rs, $rdata) = get_tag($dta_b, $dta_e, $sys); |
|---|
| | 352 | if ($rs == 0) { # YES ! Data is here ! /in production config file/; |
|---|
| | 353 | ($rs, $sys) = repl_tag($dta_b, $dta_e, $sys, $working, "dmn_del_named_cfg_data"); |
|---|
| | 354 | return $rs if ($rs != 0); |
|---|
| | 355 | } elsif ($rs == -5) { |
|---|
| | 356 | $sys .= $working; |
|---|
| | 357 | } else { |
|---|
| | 358 | return $rs; |
|---|
| | 359 | } |
|---|
| | 360 | $rs = store_file($sys_cfg, $sys, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 361 | return $rs if ($rs != 0); |
|---|
| | 362 | |
|---|
| | 363 | push_el(\@main::el, 'dmn_del_named_cfg_data()', 'Ending...'); |
|---|
| | 364 | return 0; |
|---|
| 512 | 365 | } |
|---|
| 513 | 366 | |
|---|
| … | … | |
| 516 | 369 | ## Add DNS DB Data |
|---|
| 517 | 370 | ## |
|---|
| 518 | | |
|---|
| 519 | 371 | sub dmn_add_named_db_data { |
|---|
| 520 | | |
|---|
| 521 | | my ($dmn_data) = @_; |
|---|
| 522 | | |
|---|
| 523 | | my ($rs, $rdata) = (undef, undef); |
|---|
| 524 | | |
|---|
| 525 | | push_el(\@main::el, 'dmn_add_named_db_data()', 'Starting...'); |
|---|
| 526 | | |
|---|
| 527 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 528 | | |
|---|
| 529 | | push_el(\@main::el, 'dmn_add_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 530 | | |
|---|
| 531 | | return -1; |
|---|
| 532 | | |
|---|
| 533 | | } |
|---|
| 534 | | |
|---|
| 535 | | # |
|---|
| 536 | | # Initial data we need; |
|---|
| 537 | | # |
|---|
| 538 | | |
|---|
| 539 | | my $dmn_name = @$dmn_data[1]; |
|---|
| 540 | | |
|---|
| 541 | | my $dmn_ip = @$dmn_data[21]; |
|---|
| 542 | | |
|---|
| 543 | | |
|---|
| 544 | | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 545 | | |
|---|
| 546 | | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 547 | | |
|---|
| 548 | | my $base_svr_ip = $main::cfg{'BASE_SERVER_IP'}; |
|---|
| 549 | | |
|---|
| 550 | | my $sec_dns_ip = $main::cfg{'SECONDARY_DNS'}; |
|---|
| 551 | | |
|---|
| 552 | | # |
|---|
| 553 | | # Any secondary DNS defined; |
|---|
| 554 | | # |
|---|
| 555 | | |
|---|
| | 372 | my ($dmn_data) = @_; |
|---|
| | 373 | my ($rs, $rdata) = (undef, undef); |
|---|
| | 374 | |
|---|
| | 375 | push_el(\@main::el, 'dmn_add_named_db_data()', 'Starting...'); |
|---|
| | 376 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| | 377 | push_el(\@main::el, 'dmn_add_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| | 378 | return -1; |
|---|
| | 379 | } |
|---|
| | 380 | |
|---|
| | 381 | # |
|---|
| | 382 | # Initial data we need; |
|---|
| | 383 | # |
|---|
| | 384 | my $dmn_name = @$dmn_data[1]; |
|---|
| | 385 | my $dmn_ip = @$dmn_data[21]; |
|---|
| | 386 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| | 387 | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| | 388 | my $base_svr_ip = $main::cfg{'BASE_SERVER_IP'}; |
|---|
| | 389 | my $sec_dns_ip = $main::cfg{'SECONDARY_DNS'}; |
|---|
| | 390 | |
|---|
| | 391 | # |
|---|
| | 392 | # Any secondary DNS defined; |
|---|
| | 393 | # |
|---|
| 556 | 394 | if (!$sec_dns_ip) { |
|---|
| 557 | 395 | $sec_dns_ip = $base_svr_ip; |
|---|
| 558 | 396 | } |
|---|
| 559 | 397 | |
|---|
| 560 | | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 561 | | |
|---|
| 562 | | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 563 | | |
|---|
| 564 | | my $working_dir = "$conf_dir/bind/working"; |
|---|
| 565 | | |
|---|
| 566 | | |
|---|
| 567 | | my $db_fname = "$dmn_name.db"; |
|---|
| 568 | | |
|---|
| 569 | | |
|---|
| 570 | | my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| 571 | | |
|---|
| 572 | | my $working_cfg = "$working_dir/$db_fname"; |
|---|
| 573 | | |
|---|
| 574 | | # |
|---|
| 575 | | # Let's get needed tags and templates; |
|---|
| 576 | | # |
|---|
| 577 | | |
|---|
| 578 | | my ($entry, $dns2_b, $dns2_e) = ('', '', ''); |
|---|
| 579 | | |
|---|
| 580 | | ($rs, $entry, $dns2_b, $dns2_e) = get_tpl( |
|---|
| 581 | | $tpl_dir, |
|---|
| 582 | | 'db_e.tpl', |
|---|
| 583 | | 'db_dns2_b.tpl', |
|---|
| 584 | | 'db_dns2_e.tpl' |
|---|
| 585 | | ); |
|---|
| 586 | | |
|---|
| 587 | | return $rs if ($rs != 0); |
|---|
| | 398 | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| | 399 | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| | 400 | my $working_dir = "$conf_dir/bind/working"; |
|---|
| | 401 | my $db_fname = "$dmn_name.db"; |
|---|
| | 402 | my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| | 403 | my $working_cfg = "$working_dir/$db_fname"; |
|---|
| | 404 | |
|---|
| | 405 | # |
|---|
| | 406 | # Let's get needed tags and templates; |
|---|
| | 407 | # |
|---|
| | 408 | my ($entry, $dns2_b, $dns2_e) = ('', '', ''); |
|---|
| | 409 | ($rs, $entry, $dns2_b, $dns2_e) = get_tpl( |
|---|
| | 410 | $tpl_dir, |
|---|
| | 411 | 'db_e.tpl', |
|---|
| | 412 | 'db_dns2_b.tpl', |
|---|
| | 413 | 'db_dns2_e.tpl' |
|---|
| | 414 | ); |
|---|
| | 415 | return $rs if ($rs != 0); |
|---|
| 588 | 416 | |
|---|
| 589 | 417 | my $seq = 0; |
|---|
| … | … | |
| 592 | 420 | # RFC 1912 |
|---|
| 593 | 421 | # |
|---|
| 594 | | |
|---|
| 595 | 422 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
|---|
| 596 | | |
|---|
| 597 | 423 | my $time2 = sprintf "%4d%02d%02d00",$year+1900,$mon+1,$mday,$seq; |
|---|
| 598 | 424 | |
|---|
| 599 | | # |
|---|
| 600 | | # Let's prepare them; |
|---|
| 601 | | # |
|---|
| 602 | | |
|---|
| 603 | | my %tag_hash = ( |
|---|
| 604 | | '{DMN_NAME}' => $dmn_name, |
|---|
| 605 | | '{DMN_IP}' => $dmn_ip, |
|---|
| 606 | | '{BASE_SERVER_IP}' => $base_svr_ip, |
|---|
| 607 | | '{SECONDARY_DNS_IP}' => $sec_dns_ip, |
|---|
| 608 | | '{TIMESTAMP}' => $time2 |
|---|
| 609 | | ); |
|---|
| 610 | | |
|---|
| 611 | | ($rs, $entry, $dns2_b, $dns2_e) = prep_tpl( |
|---|
| 612 | | \%tag_hash, |
|---|
| 613 | | $entry, |
|---|
| 614 | | $dns2_b, |
|---|
| 615 | | $dns2_e |
|---|
| 616 | | ); |
|---|
| 617 | | |
|---|
| 618 | | return $rs if ($rs != 0); |
|---|
| 619 | | |
|---|
| 620 | | #if ($main::cfg{'SECONDARY_DNS'}) { |
|---|
| 621 | | |
|---|
| 622 | | # my $dns2 = undef; |
|---|
| 623 | | |
|---|
| 624 | | # $dns2 = "\t\t \t NS \t $main::cfg{'SECONDARY_DNS'}.\n"; |
|---|
| 625 | | |
|---|
| 626 | | # $dns2 = "$dns2_b$dns2$dns2_e"; |
|---|
| 627 | | |
|---|
| 628 | | # ($rs, $entry) = repl_tag($dns2_b, $dns2_e, $entry, $dns2); |
|---|
| 629 | | |
|---|
| 630 | | # return $rs if ($rs != 0); |
|---|
| 631 | | |
|---|
| 632 | | #} else { |
|---|
| 633 | | |
|---|
| 634 | | # ($rs, $entry) = del_tag($dns2_b, $dns2_e, $entry); |
|---|
| 635 | | |
|---|
| 636 | | # return $rs if ($rs != 0); |
|---|
| 637 | | |
|---|
| 638 | | #} |
|---|
| 639 | | |
|---|
| 640 | | # |
|---|
| 641 | | # Let's store generated data; |
|---|
| 642 | | # |
|---|
| 643 | | |
|---|
| 644 | | $rs = store_file($working_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 645 | | |
|---|
| 646 | | return $rs if ($rs != 0); |
|---|
| 647 | | |
|---|
| 648 | | $rs = store_file($sys_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 649 | | |
|---|
| 650 | | return $rs if ($rs != 0); |
|---|
| 651 | | |
|---|
| 652 | | push_el(\@main::el, 'dmn_add_named_db_data()', 'Ending...'); |
|---|
| 653 | | |
|---|
| 654 | | |
|---|
| 655 | | return 0; |
|---|
| | 425 | # |
|---|
| | 426 | # Let's prepare them; |
|---|
| | 427 | # |
|---|
| | 428 | my %tag_hash = ( |
|---|
| | 429 | '{DMN_NAME}' => $dmn_name, |
|---|
| | 430 | '{DMN_IP}' => $dmn_ip, |
|---|
| | 431 | '{BASE_SERVER_IP}' => $base_svr_ip, |
|---|
| | 432 | '{SECONDARY_DNS_IP}' => $sec_dns_ip, |
|---|
| | 433 | '{TIMESTAMP}' => $time2 |
|---|
| | 434 | ); |
|---|
| | 435 | ($rs, $entry, $dns2_b, $dns2_e) = prep_tpl( |
|---|
| | 436 | \%tag_hash, |
|---|
| | 437 | $entry, |
|---|
| | 438 | $dns2_b, |
|---|
| | 439 | $dns2_e |
|---|
| | 440 | ); |
|---|
| | 441 | return $rs if ($rs != 0); |
|---|
| | 442 | |
|---|
| | 443 | #if ($main::cfg{'SECONDARY_DNS'}) { |
|---|
| | 444 | # my $dns2 = undef; |
|---|
| | 445 | # $dns2 = "\t\t \t NS \t $main::cfg{'SECONDARY_DNS'}.\n"; |
|---|
| | 446 | # $dns2 = "$dns2_b$dns2$dns2_e"; |
|---|
| | 447 | # ($rs, $entry) = repl_tag($dns2_b, $dns2_e, $entry, $dns2); |
|---|
| | 448 | # return $rs if ($rs != 0); |
|---|
| | 449 | #} else { |
|---|
| | 450 | # ($rs, $entry) = del_tag($dns2_b, $dns2_e, $entry); |
|---|
| | 451 | # return $rs if ($rs != 0); |
|---|
| | 452 | #} |
|---|
| | 453 | # |
|---|
| | 454 | # Let's store generated data; |
|---|
| | 455 | # |
|---|
| | 456 | $rs = store_file($working_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 457 | return $rs if ($rs != 0); |
|---|
| | 458 | |
|---|
| | 459 | $rs = store_file($sys_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| | 460 | return $rs if ($rs != 0); |
|---|
| | 461 | |
|---|
| | 462 | push_el(\@main::el, 'dmn_add_named_db_data()', 'Ending...'); |
|---|
| | 463 | return 0; |
|---|
| 656 | 464 | } |
|---|
| 657 | 465 | |
|---|
| … | … | |
| 660 | 468 | ## Delte DNS DB Data |
|---|
| 661 | 469 | ## |
|---|
| 662 | | |
|---|
| 663 | 470 | sub dmn_del_named_db_data { |
|---|
| 664 | | |
|---|
| 665 | | my ($dmn_data) = @_; |
|---|
| 666 | | |
|---|
| 667 | | my ($rs, $rdata) = (undef, undef); |
|---|
| 668 | | |
|---|
| 669 | | push_el(\@main::el, 'dmn_del_named_db_data()', 'Starting...'); |
|---|
| 670 | | |
|---|
| 671 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 672 | | |
|---|
| 673 | | push_el(\@main::el, 'dmn_del_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 674 | | |
|---|
| 675 | | return -1; |
|---|
| 676 | | |
|---|
| 677 | | } |
|---|
| 678 | | |
|---|
| 679 | | # |
|---|
| 680 | | # Initial data we need; |
|---|
| 681 | | # |
|---|
| 682 | | |
|---|
| 683 | | my $dmn_name = @$dmn_data[1]; |
|---|
| 684 | | |
|---|
| 685 | | my $dmn_ip = @$dmn_data[21]; |
|---|
| 686 | | |
|---|
| 687 | | |
|---|
| 688 | | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 689 | | |
|---|
| 690 | | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 691 | | |
|---|
| 692 | | |
|---|
| 693 | | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 694 | | |
|---|
| 695 | | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 696 | | |
|---|
| 697 | | my $working_dir = "$conf_dir/bind/working"; |
|---|
| 698 | | |
|---|
| 699 | | |
|---|
| 700 | | my $db_fname = "$dmn_name.db"; |
|---|
| 701 | | |
|---|
| 702 | | |
|---|
| 703 | | my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| 704 | | |
|---|
| 705 | | my $working_cfg = "$working_dir/$db_fname"; |
|---|
| 706 | | |
|---|
| 707 | | # |
|---|
| 708 | | # Let's remove .db files for this domain; |
|---|
| 709 | | # |
|---|
| 710 | | |
|---|
| 711 | | $rs = del_file($working_cfg); |
|---|
| 712 | | |
|---|
| 713 | | return $rs if ($rs != 0); |
|---|
| 714 | | |
|---|
| 715 | | $rs = del_file($sys_cfg); |
|---|
| 716 | | |
|---|
| 717 | | return $rs if ($rs != 0); |
|---|
| 718 | | |
|---|
| 719 | | push_el(\@main::el, 'dmn_del_named_db_data()', 'Ending...'); |
|---|
| 720 | | |
|---|
| 721 | | |
|---|
| 722 | | return 0; |
|---|
| | 471 | my ($dmn_data) = @_; |
|---|
| | 472 | my ($rs, $rdata) = (undef, undef); |
|---|
| | 473 | |
|---|
| | 474 | push_el(\@main::el, 'dmn_del_named_db_data()', 'Starting...'); |
|---|
| | 475 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| | 476 | push_el(\@main::el, 'dmn_del_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| | 477 | return -1; |
|---|
| | 478 | } |
|---|
| | 479 | |
|---|
| | 480 | # |
|---|
| | 481 | # Initial data we need; |
|---|
| | 482 | # |
|---|
| | 483 | my $dmn_name = @$dmn_data[1]; |
|---|
| | 484 | my $dmn_ip = @$dmn_data[21]; |
|---|
| | 485 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| | 486 | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| | 487 | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| | 488 | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| | 489 | my $working_dir = "$conf_dir/bind/working"; |
|---|
| | 490 | my $db_fname = "$dmn_name.db"; |
|---|
| | 491 | my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| | 492 | my $working_cfg = "$working_dir/$db_fname"; |
|---|
| | 493 | |
|---|
| | 494 | # |
|---|
| | 495 | # Let's remove .db files for this domain; |
|---|
| | 496 | # |
|---|
| | 497 | $rs = del_file($working_cfg); |
|---|
| | 498 | return $rs if ($rs != 0); |
|---|
| | 499 | |
|---|
| | 500 | $rs = del_file($sys_cfg); |
|---|
| | 501 | return $rs if ($rs != 0); |
|---|
| | 502 | |
|---|
| | 503 | push_el(\@main::el, 'dmn_del_named_db_data()', 'Ending...'); |
|---|
| | 504 | return 0; |
|---|
| 723 | 505 | } |
|---|
| 724 | 506 | |
|---|
| … | … | |
| 727 | 509 | ## Add DNS Data |
|---|
| 728 | 510 | ## |
|---|
| 729 | | |
|---|
| 730 | 511 | sub dmn_add_named_data { |
|---|
| 731 | | |
|---|
| 732 | | my ($dmn_data) = @_; |
|---|
| 733 | | |
|---|
| 734 | | my $rs = undef; |
|---|
| 735 | | |
|---|
| 736 | | push_el(\@main::el, 'dmn_add_named_data()', 'Starting...'); |
|---|
| 737 | | |
|---|
| 738 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 739 | | |
|---|
| 740 | | push_el(\@main::el, 'dmn_add_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 741 | | |
|---|
| 742 | | return -1; |
|---|
| 743 | | |
|---|
| 744 | | } |
|---|
| 745 | | |
|---|
| 746 | | return 0 if ($main::cfg{'CMD_NAMED'} eq 'no'); |
|---|
| 747 | | |
|---|
| 748 | | $rs = dmn_add_named_cfg_data($dmn_data); |
|---|
| 749 | | |
|---|
| 750 | | return $rs if ($rs != 0); |
|---|
| 751 | | |
|---|
| 752 | | $rs = dmn_add_named_db_data($dmn_data); |
|---|
| 753 | | |
|---|
| 754 | | return $rs if ($rs != 0); |
|---|
| 755 | | |
|---|
| 756 | | push_el(\@main::el, 'dmn_add_named_data()', 'Ending...'); |
|---|
| 757 | | |
|---|
| 758 | | return 0; |
|---|
| | 512 | my ($dmn_data) = @_; |
|---|
| | 513 | my $rs = undef; |
|---|
| | 514 | |
|---|
| | 515 | push_el(\@main::el, 'dmn_add_named_data()', 'Starting...'); |
|---|
| | 516 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| | 517 | push_el(\@main::el, 'dmn_add_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| | 518 | return -1; |
|---|
| | 519 | } |
|---|
| | 520 | return 0 if ($main::cfg{'CMD_NAMED'} eq 'no'); |
|---|
| | 521 | |
|---|
| | 522 | $rs = dmn_add_named_cfg_data($dmn_data); |
|---|
| | 523 | return $rs if ($rs != 0); |
|---|
| | 524 | |
|---|
| | 525 | $rs = dmn_add_named_db_data($dmn_data); |
|---|
| | 526 | return $rs if ($rs != 0); |
|---|
| | 527 | |
|---|
| | 528 | push_el(\@main::el, 'dmn_add_named_data()', 'Ending...'); |
|---|
| | 529 | return 0; |
|---|
| 759 | 530 | } |
|---|
| 760 | 531 | |
|---|
| … | … | |
| 763 | 534 | ## Change DNS Data |
|---|
| 764 | 535 | ## |
|---|
| 765 | | |
|---|
| 766 | 536 | sub dmn_change_named_data { |
|---|
| 767 | | |
|---|
| 768 | | my ($dmn_data) = @_; |
|---|
| 769 | | |
|---|
| 770 | | my $rs = undef; |
|---|
| 771 | | |
|---|
| 772 | | push_el(\@main::el, 'dmn_change_named_data()', 'Starting...'); |
|---|
| 773 | | |
|---|
| 774 | | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 775 | | |
|---|
| 776 | | push_el(\@main::el, 'dmn_change_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 777 | | |
|---|
| 778 | | return -1; |
|---|
| 779 | | |
|---|
| 780 | | } |
|---|
| 781 | | |
|---|
| 782 | | $rs = dmn_add_named_data($dmn_data); |
|---|
| 783 | | |
|---|
| 784 | | return $rs if ($rs != 0); |
|---|
| 785 | | |
|---|
| 786 | | push_el(\@main::el, 'dmn_change_named_data()', 'Ending...'); |
|---|
| 787 | | |
|---|
| 788 | | return 0; |
|---|
|