| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # ispCP ω (OMEGA) a Virtual Hosting Control Panel |
|---|
| 4 | # Copyright (c) 2001-2006 by moleSoftware GmbH |
|---|
| 5 | # http://www.molesoftware.com |
|---|
| 6 | # Copyright (c) 2006-2008 by isp Control Panel |
|---|
| 7 | # http://isp-control.net |
|---|
| 8 | # |
|---|
| 9 | # |
|---|
| 10 | # License: |
|---|
| 11 | # This program is free software; you can redistribute it and/or |
|---|
| 12 | # modify it under the terms of the MPL Mozilla Public License |
|---|
| 13 | # as published by the Free Software Foundation; either version 1.1 |
|---|
| 14 | # of the License, or (at your option) any later version. |
|---|
| 15 | # |
|---|
| 16 | # This program is distributed in the hope that it will be useful, |
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | # MPL Mozilla Public License for more details. |
|---|
| 20 | # |
|---|
| 21 | # You may have received a copy of the MPL Mozilla Public License |
|---|
| 22 | # along with this program. |
|---|
| 23 | # |
|---|
| 24 | # An on-line copy of the MPL Mozilla Public License can be found |
|---|
| 25 | # http://www.mozilla.org/MPL/MPL-1.1.html |
|---|
| 26 | # |
|---|
| 27 | # |
|---|
| 28 | # The ISPCP ω Home Page is at: |
|---|
| 29 | # |
|---|
| 30 | # http://isp-control.net |
|---|
| 31 | # |
|---|
| 32 | |
|---|
| 33 | use FindBin; |
|---|
| 34 | use lib "$FindBin::Bin/"; |
|---|
| 35 | require 'ispcp_common_code.pl'; |
|---|
| 36 | |
|---|
| 37 | use strict; |
|---|
| 38 | |
|---|
| 39 | use warnings; |
|---|
| 40 | |
|---|
| 41 | use Net::LibIDN ':all'; |
|---|
| 42 | |
|---|
| 43 | $main::dmn_task_id = undef; |
|---|
| 44 | |
|---|
| 45 | ################################################################################ |
|---|
| 46 | ## SUBROUTINES ## |
|---|
| 47 | ################################################################################ |
|---|
| 48 | ## |
|---|
| 49 | ## Start Up! |
|---|
| 50 | ## |
|---|
| 51 | |
|---|
| 52 | 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 | |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | ################################################################################ |
|---|
| 105 | ## |
|---|
| 106 | ## Shut Down! |
|---|
| 107 | ## |
|---|
| 108 | |
|---|
| 109 | 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 | |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | ###################################### DNS ##################################### |
|---|
| 122 | |
|---|
| 123 | ################################################################################ |
|---|
| 124 | ## |
|---|
| 125 | ## Add DNS CFG Data |
|---|
| 126 | ## |
|---|
| 127 | |
|---|
| 128 | 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; |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | ################################################################################ |
|---|
| 319 | ## |
|---|
| 320 | ## Delete DNS CFG Data |
|---|
| 321 | ## |
|---|
| 322 | |
|---|
| 323 | 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; |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | ################################################################################ |
|---|
| 515 | ## |
|---|
| 516 | ## Add DNS DB Data |
|---|
| 517 | ## |
|---|
| 518 | |
|---|
| 519 | 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 | |
|---|
| 556 | if (!$sec_dns_ip) { |
|---|
| 557 | $sec_dns_ip = $base_svr_ip; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 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); |
|---|
| 588 | |
|---|
| 589 | # |
|---|
| 590 | # RFC 1912 |
|---|
| 591 | # |
|---|
| 592 | |
|---|
| 593 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
|---|
| 594 | |
|---|
| 595 | my $time2 = sprintf "%4d%02d%02d00",$year+1900,$mon+1,$mday; |
|---|
| 596 | |
|---|
| 597 | # |
|---|
| 598 | # Let's prepare them; |
|---|
| 599 | # |
|---|
| 600 | |
|---|
| 601 | my %tag_hash = ( |
|---|
| 602 | '{DMN_NAME}' => $dmn_name, |
|---|
| 603 | '{DMN_IP}' => $dmn_ip, |
|---|
| 604 | '{BASE_SERVER_IP}' => $base_svr_ip, |
|---|
| 605 | '{SECONDARY_DNS_IP}' => $sec_dns_ip, |
|---|
| 606 | '{TIMESTAMP}' => $time2 |
|---|
| 607 | ); |
|---|
| 608 | |
|---|
| 609 | ($rs, $entry, $dns2_b, $dns2_e) = prep_tpl( |
|---|
| 610 | \%tag_hash, |
|---|
| 611 | $entry, |
|---|
| 612 | $dns2_b, |
|---|
| 613 | $dns2_e |
|---|
| 614 | ); |
|---|
| 615 | |
|---|
| 616 | return $rs if ($rs != 0); |
|---|
| 617 | |
|---|
| 618 | #if ($main::cfg{'SECONDARY_DNS'}) { |
|---|
| 619 | |
|---|
| 620 | # my $dns2 = undef; |
|---|
| 621 | |
|---|
| 622 | # $dns2 = "\t\t \t NS \t $main::cfg{'SECONDARY_DNS'}.\n"; |
|---|
| 623 | |
|---|
| 624 | # $dns2 = "$dns2_b$dns2$dns2_e"; |
|---|
| 625 | |
|---|
| 626 | # ($rs, $entry) = repl_tag($dns2_b, $dns2_e, $entry, $dns2); |
|---|
| 627 | |
|---|
| 628 | # return $rs if ($rs != 0); |
|---|
| 629 | |
|---|
| 630 | #} else { |
|---|
| 631 | |
|---|
| 632 | # ($rs, $entry) = del_tag($dns2_b, $dns2_e, $entry); |
|---|
| 633 | |
|---|
| 634 | # return $rs if ($rs != 0); |
|---|
| 635 | |
|---|
| 636 | #} |
|---|
| 637 | |
|---|
| 638 | # |
|---|
| 639 | # Let's store generated data; |
|---|
| 640 | # |
|---|
| 641 | |
|---|
| 642 | $rs = store_file($working_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 643 | |
|---|
| 644 | return $rs if ($rs != 0); |
|---|
| 645 | |
|---|
| 646 | $rs = store_file($sys_cfg, $entry, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 647 | |
|---|
| 648 | return $rs if ($rs != 0); |
|---|
| 649 | |
|---|
| 650 | push_el(\@main::el, 'dmn_add_named_db_data()', 'Ending...'); |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | return 0; |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | ################################################################################ |
|---|
| 657 | ## |
|---|
| 658 | ## Delte DNS DB Data |
|---|
| 659 | ## |
|---|
| 660 | |
|---|
| 661 | sub dmn_del_named_db_data { |
|---|
| 662 | |
|---|
| 663 | my ($dmn_data) = @_; |
|---|
| 664 | |
|---|
| 665 | my ($rs, $rdata) = (undef, undef); |
|---|
| 666 | |
|---|
| 667 | push_el(\@main::el, 'dmn_del_named_db_data()', 'Starting...'); |
|---|
| 668 | |
|---|
| 669 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 670 | |
|---|
| 671 | push_el(\@main::el, 'dmn_del_named_db_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 672 | |
|---|
| 673 | return -1; |
|---|
| 674 | |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | # |
|---|
| 678 | # Initial data we need; |
|---|
| 679 | # |
|---|
| 680 | |
|---|
| 681 | my $dmn_name = @$dmn_data[1]; |
|---|
| 682 | |
|---|
| 683 | my $dmn_ip = @$dmn_data[21]; |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 687 | |
|---|
| 688 | my $named_db_dir = $main::cfg{'BIND_DB_DIR'}; |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | my $tpl_dir = "$conf_dir/bind/parts"; |
|---|
| 692 | |
|---|
| 693 | my $backup_dir = "$conf_dir/bind/backup"; |
|---|
| 694 | |
|---|
| 695 | my $working_dir = "$conf_dir/bind/working"; |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | my $db_fname = "$dmn_name.db"; |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | my $sys_cfg = "$named_db_dir/$db_fname"; |
|---|
| 702 | |
|---|
| 703 | my $working_cfg = "$working_dir/$db_fname"; |
|---|
| 704 | |
|---|
| 705 | # |
|---|
| 706 | # Let's remove .db files for this domain; |
|---|
| 707 | # |
|---|
| 708 | |
|---|
| 709 | $rs = del_file($working_cfg); |
|---|
| 710 | |
|---|
| 711 | return $rs if ($rs != 0); |
|---|
| 712 | |
|---|
| 713 | $rs = del_file($sys_cfg); |
|---|
| 714 | |
|---|
| 715 | return $rs if ($rs != 0); |
|---|
| 716 | |
|---|
| 717 | push_el(\@main::el, 'dmn_del_named_db_data()', 'Ending...'); |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | return 0; |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | ################################################################################ |
|---|
| 724 | ## |
|---|
| 725 | ## Add DNS Data |
|---|
| 726 | ## |
|---|
| 727 | |
|---|
| 728 | sub dmn_add_named_data { |
|---|
| 729 | |
|---|
| 730 | my ($dmn_data) = @_; |
|---|
| 731 | |
|---|
| 732 | my $rs = undef; |
|---|
| 733 | |
|---|
| 734 | push_el(\@main::el, 'dmn_add_named_data()', 'Starting...'); |
|---|
| 735 | |
|---|
| 736 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 737 | |
|---|
| 738 | push_el(\@main::el, 'dmn_add_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 739 | |
|---|
| 740 | return -1; |
|---|
| 741 | |
|---|
| 742 | } |
|---|
| 743 | |
|---|
| 744 | return 0 if ($main::cfg{'CMD_NAMED'} eq 'no'); |
|---|
| 745 | |
|---|
| 746 | $rs = dmn_add_named_cfg_data($dmn_data); |
|---|
| 747 | |
|---|
| 748 | return $rs if ($rs != 0); |
|---|
| 749 | |
|---|
| 750 | $rs = dmn_add_named_db_data($dmn_data); |
|---|
| 751 | |
|---|
| 752 | return $rs if ($rs != 0); |
|---|
| 753 | |
|---|
| 754 | push_el(\@main::el, 'dmn_add_named_data()', 'Ending...'); |
|---|
| 755 | |
|---|
| 756 | return 0; |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | ################################################################################ |
|---|
| 760 | ## |
|---|
| 761 | ## Change DNS Data |
|---|
| 762 | ## |
|---|
| 763 | |
|---|
| 764 | sub dmn_change_named_data { |
|---|
| 765 | |
|---|
| 766 | my ($dmn_data) = @_; |
|---|
| 767 | |
|---|
| 768 | my $rs = undef; |
|---|
| 769 | |
|---|
| 770 | push_el(\@main::el, 'dmn_change_named_data()', 'Starting...'); |
|---|
| 771 | |
|---|
| 772 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 773 | |
|---|
| 774 | push_el(\@main::el, 'dmn_change_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 775 | |
|---|
| 776 | return -1; |
|---|
| 777 | |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | $rs = dmn_add_named_data($dmn_data); |
|---|
| 781 | |
|---|
| 782 | return $rs if ($rs != 0); |
|---|
| 783 | |
|---|
| 784 | push_el(\@main::el, 'dmn_change_named_data()', 'Ending...'); |
|---|
| 785 | |
|---|
| 786 | return 0; |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | ################################################################################ |
|---|
| 790 | ## |
|---|
| 791 | ## Delete DNS Data |
|---|
| 792 | ## |
|---|
| 793 | |
|---|
| 794 | sub dmn_del_named_data { |
|---|
| 795 | |
|---|
| 796 | my ($dmn_data) = @_; |
|---|
| 797 | |
|---|
| 798 | my $rs = undef; |
|---|
| 799 | |
|---|
| 800 | push_el(\@main::el, 'dmn_del_named_data()', 'Starting...'); |
|---|
| 801 | |
|---|
| 802 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 803 | |
|---|
| 804 | push_el(\@main::el, 'dmn_del_named_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 805 | |
|---|
| 806 | return -1; |
|---|
| 807 | |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | return 0 if ($main::cfg{'CMD_NAMED'} eq 'no'); |
|---|
| 811 | |
|---|
| 812 | $rs = dmn_del_named_cfg_data($dmn_data); |
|---|
| 813 | |
|---|
| 814 | return $rs if ($rs != 0); |
|---|
| 815 | |
|---|
| 816 | $rs = dmn_del_named_db_data($dmn_data); |
|---|
| 817 | |
|---|
| 818 | return $rs if ($rs != 0); |
|---|
| 819 | |
|---|
| 820 | push_el(\@main::el, 'dmn_del_named_data()', 'Ending...'); |
|---|
| 821 | |
|---|
| 822 | return 0; |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | ##################################### HTTPd #################################### |
|---|
| 826 | |
|---|
| 827 | ################################################################################ |
|---|
| 828 | ## |
|---|
| 829 | ## Generate Auto Number |
|---|
| 830 | ## |
|---|
| 831 | |
|---|
| 832 | sub get_auto_num { |
|---|
| 833 | |
|---|
| 834 | my ($rs, $num, $rdata) = (undef, undef, undef); |
|---|
| 835 | |
|---|
| 836 | push_el(\@main::el, 'get_auto_num()', 'Starting...'); |
|---|
| 837 | |
|---|
| 838 | my $sql = "insert into auto_num (msg) values ('auto-num')"; |
|---|
| 839 | |
|---|
| 840 | ($rs, $rdata) = doSQL($sql); |
|---|
| 841 | |
|---|
| 842 | return $rs if ($rs != 0); |
|---|
| 843 | |
|---|
| 844 | $num = $main::db -> {'mysql_insertid'}; |
|---|
| 845 | |
|---|
| 846 | push_el(\@main::el, 'get_auto_num()', 'Ending...'); |
|---|
| 847 | |
|---|
| 848 | return $num; |
|---|
| 849 | |
|---|
| 850 | close('db'); |
|---|
| 851 | |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | ################################################################################ |
|---|
| 855 | ## |
|---|
| 856 | ## Generate HTTPd Domain Group Entry |
|---|
| 857 | ## |
|---|
| 858 | |
|---|
| 859 | sub gen_httpd_dmn_group_entry { |
|---|
| 860 | |
|---|
| 861 | my ($dmn_data) = @_; |
|---|
| 862 | |
|---|
| 863 | push_el(\@main::el, 'gen_httpd_dmn_group_entry()', 'Starting...'); |
|---|
| 864 | |
|---|
| 865 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 866 | push_el(\@main::el, 'gen_httpd_dmn_group_entry()', "ERORR: Undefined input data..."); |
|---|
| 867 | return (-1, ''); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | my ($rs, $rdata) = (undef, undef); |
|---|
| 871 | |
|---|
| 872 | my $dmn_id = @$dmn_data[0]; |
|---|
| 873 | |
|---|
| 874 | my $dmn_name = @$dmn_data[1]; |
|---|
| 875 | |
|---|
| 876 | my $dmn_grp = $dmn_name; |
|---|
| 877 | |
|---|
| 878 | my $dmn_ip = @$dmn_data[21]; |
|---|
| 879 | |
|---|
| 880 | my $dmn_traffic_limit = @$dmn_data[10]; |
|---|
| 881 | |
|---|
| 882 | my ($dmn_php, $dmn_cgi) = (@$dmn_data[19], @$dmn_data[20]); |
|---|
| 883 | |
|---|
| 884 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 885 | |
|---|
| 886 | my $tpl_dir = "$conf_dir/apache/parts"; |
|---|
| 887 | |
|---|
| 888 | my $bw_disabled = ''; |
|---|
| 889 | |
|---|
| 890 | if ($dmn_traffic_limit eq 0) { |
|---|
| 891 | $bw_disabled = '#'; |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | my ( |
|---|
| 895 | $dg_b, |
|---|
| 896 | $dg_entry, |
|---|
| 897 | $dg_e, |
|---|
| 898 | $dmn_b, |
|---|
| 899 | $dmn_entry, |
|---|
| 900 | $dmn_e, |
|---|
| 901 | $dmn_cgi_b, |
|---|
| 902 | $dmn_cgi_entry, |
|---|
| 903 | $dmn_cgi_e, |
|---|
| 904 | $dmn_php_b, |
|---|
| 905 | $dmn_php_entry, |
|---|
| 906 | $dmn_php_e, |
|---|
| 907 | $dmn_php2_b, |
|---|
| 908 | $dmn_php2_entry, |
|---|
| 909 | $dmn_php2_e, |
|---|
| 910 | $dmn_awstats_b, |
|---|
| 911 | $dmn_awstats_dynamic_entry, |
|---|
| 912 | $dmn_awstats_static_entry, |
|---|
| 913 | $dmn_awstats_e, |
|---|
| 914 | $dmn_custom |
|---|
| 915 | ) = ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); |
|---|
| 916 | |
|---|
| 917 | ( |
|---|
| 918 | $rs, |
|---|
| 919 | $dg_b, |
|---|
| 920 | $dg_entry, |
|---|
| 921 | $dg_e, |
|---|
| 922 | $dmn_b, |
|---|
| 923 | $dmn_entry, |
|---|
| 924 | $dmn_e, |
|---|
| 925 | $dmn_cgi_b, |
|---|
| 926 | $dmn_cgi_entry, |
|---|
| 927 | $dmn_cgi_e, |
|---|
| 928 | $dmn_php_b, |
|---|
| 929 | $dmn_php_entry, |
|---|
| 930 | $dmn_php_e, |
|---|
| 931 | $dmn_php2_b, |
|---|
| 932 | $dmn_php2_entry, |
|---|
| 933 | $dmn_php2_e, |
|---|
| 934 | $dmn_awstats_b, |
|---|
| 935 | $dmn_awstats_dynamic_entry, |
|---|
| 936 | $dmn_awstats_static_entry, |
|---|
| 937 | $dmn_awstats_e, |
|---|
| 938 | $dmn_custom |
|---|
| 939 | ) = get_tpl ( |
|---|
| 940 | $tpl_dir, |
|---|
| 941 | 'dg_b.tpl', |
|---|
| 942 | 'dg_entry.tpl', |
|---|
| 943 | 'dg_e.tpl', |
|---|
| 944 | 'dmn_b.tpl', |
|---|
| 945 | 'dmn_entry.tpl', |
|---|
| 946 | 'dmn_e.tpl', |
|---|
| 947 | 'dmn_cgi_b.tpl', |
|---|
| 948 | 'dmn_cgi_entry.tpl', |
|---|
| 949 | 'dmn_cgi_e.tpl', |
|---|
| 950 | 'dmn_php_b.tpl', |
|---|
| 951 | 'dmn_php_entry.tpl', |
|---|
| 952 | 'dmn_php_e.tpl', |
|---|
| 953 | 'dmn_php2_b.tpl', |
|---|
| 954 | 'dmn_php2_entry.tpl', |
|---|
| 955 | 'dmn_php2_e.tpl', |
|---|
| 956 | 'dmn_awstats_b.tpl', |
|---|
| 957 | 'dmn_awstats_dynamic_entry.tpl', |
|---|
| 958 | 'dmn_awstats_static_entry.tpl', |
|---|
| 959 | 'dmn_awstats_e.tpl', |
|---|
| 960 | 'custom.conf.tpl' |
|---|
| 961 | ); |
|---|
| 962 | |
|---|
| 963 | return ($rs, '') if ($rs != 0); |
|---|
| 964 | |
|---|
| 965 | my ($suexec_uid, $suexec_gid) = get_dmn_suexec_user($dmn_id); |
|---|
| 966 | |
|---|
| 967 | my $suexec_user_pref = $main::cfg{'APACHE_SUEXEC_USER_PREF'}; |
|---|
| 968 | |
|---|
| 969 | my ($suexec_user, $suexec_group) = ("$suexec_user_pref$suexec_uid", "$suexec_user_pref$suexec_gid"); |
|---|
| 970 | |
|---|
| 971 | my %tag_hash = |
|---|
| 972 | ( |
|---|
| 973 | '{DMN_GRP}' => $dmn_grp, |
|---|
| 974 | '{DMN_NAME}' => $dmn_name, |
|---|
| 975 | '{SELF}' => $dmn_name, |
|---|
| 976 | '{DMN_IP}' => $dmn_ip, |
|---|
| 977 | '{BASE_SERVER_VHOST}' => $main::cfg{'BASE_SERVER_VHOST'}, |
|---|
| 978 | '{WWW_DIR}' => $main::cfg{'APACHE_WWW_DIR'}, |
|---|
| 979 | '{STARTER_DIR}' => $main::cfg{'PHP_STARTER_DIR'}, |
|---|
| 980 | '{PHP_VERSION}' => $main::cfg{'PHP_VERSION'}, |
|---|
| 981 | '{APACHE_LOG_DIR}' => $main::cfg{'APACHE_LOG_DIR'}, |
|---|
| 982 | '{GUI_ROOT_DIR}' => $main::cfg{'GUI_ROOT_DIR'}, |
|---|
| 983 | '{SCOREBOARDS_DIR}' => $main::cfg{'SCOREBOARDS_DIR'}, |
|---|
| 984 | '{PEAR_DIR}' => $main::cfg{'PEAR_DIR'}, |
|---|
| 985 | '{APACHE_USERS_LOG_DIR}' => $main::cfg{'APACHE_USERS_LOG_DIR'}, |
|---|
| 986 | '{CUSTOM_SITES_CONFIG_DIR}' => $main::cfg{'APACHE_CUSTOM_SITES_CONFIG_DIR'}, |
|---|
| 987 | '{SUEXEC_USER}' => $suexec_user, |
|---|
| 988 | '{SUEXEC_GROUP}' => $suexec_group, |
|---|
| 989 | '{BWLIMIT}' => $dmn_traffic_limit, |
|---|
| 990 | '{BWLIMIT_DISABLED}' => $bw_disabled, |
|---|
| 991 | '##TEMPLATE' => '' #Used to prevent apache from parsing commands which are part of the template |
|---|
| 992 | ); |
|---|
| 993 | |
|---|
| 994 | ( |
|---|
| 995 | $rs, |
|---|
| 996 | $dg_b, |
|---|
| 997 | $dg_entry, |
|---|
| 998 | $dg_e, |
|---|
| 999 | $dmn_b, |
|---|
| 1000 | $dmn_entry, |
|---|
| 1001 | $dmn_e, |
|---|
| 1002 | $dmn_cgi_b, |
|---|
| 1003 | $dmn_cgi_entry, |
|---|
| 1004 | $dmn_cgi_e, |
|---|
| 1005 | $dmn_php_b, |
|---|
| 1006 | $dmn_php_entry, |
|---|
| 1007 | $dmn_php_e, |
|---|
| 1008 | $dmn_php2_entry, |
|---|
| 1009 | $dmn_awstats_dynamic_entry, |
|---|
| 1010 | $dmn_awstats_static_entry, |
|---|
| 1011 | $dmn_custom |
|---|
| 1012 | ) = prep_tpl( |
|---|
| 1013 | \%tag_hash, |
|---|
| 1014 | $dg_b, |
|---|
| 1015 | $dg_entry, |
|---|
| 1016 | $dg_e, |
|---|
| 1017 | $dmn_b, |
|---|
| 1018 | $dmn_entry, |
|---|
| 1019 | $dmn_e, |
|---|
| 1020 | $dmn_cgi_b, |
|---|
| 1021 | $dmn_cgi_entry, |
|---|
| 1022 | $dmn_cgi_e, |
|---|
| 1023 | $dmn_php_b, |
|---|
| 1024 | $dmn_php_entry, |
|---|
| 1025 | $dmn_php_e, |
|---|
| 1026 | $dmn_php2_entry, |
|---|
| 1027 | $dmn_awstats_dynamic_entry, |
|---|
| 1028 | $dmn_awstats_static_entry, |
|---|
| 1029 | $dmn_custom |
|---|
| 1030 | ); |
|---|
| 1031 | |
|---|
| 1032 | return ($rs, '') if ($rs != 0); |
|---|
| 1033 | |
|---|
| 1034 | # |
|---|
| 1035 | # Add AWStats data |
|---|
| 1036 | # |
|---|
| 1037 | |
|---|
| 1038 | my $awstats_entry = undef; |
|---|
| 1039 | |
|---|
| 1040 | # AWStats Dynamic |
|---|
| 1041 | if ($main::cfg{'AWSTATS_ACTIVE'} eq 'yes' && $main::cfg{'AWSTATS_MODE'} eq 0) { |
|---|
| 1042 | $awstats_entry = "$dmn_awstats_b\n$dmn_awstats_dynamic_entry\n$dmn_awstats_e"; |
|---|
| 1043 | } |
|---|
| 1044 | # AWStats Static |
|---|
| 1045 | elsif ($main::cfg{'AWSTATS_ACTIVE'} eq 'yes' && $main::cfg{'AWSTATS_MODE'} eq 1) { |
|---|
| 1046 | $awstats_entry = "$dmn_awstats_b\n$dmn_awstats_static_entry\n$dmn_awstats_e"; |
|---|
| 1047 | } |
|---|
| 1048 | # No AWStats |
|---|
| 1049 | else { |
|---|
| 1050 | $awstats_entry = "$dmn_awstats_b\n$dmn_awstats_e"; |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | ($rs, $dmn_entry) = repl_tag( |
|---|
| 1054 | $dmn_awstats_b, |
|---|
| 1055 | $dmn_awstats_e, |
|---|
| 1056 | $dmn_entry, |
|---|
| 1057 | $awstats_entry, |
|---|
| 1058 | "gen_httpd_dmn_group_entry" |
|---|
| 1059 | ); |
|---|
| 1060 | |
|---|
| 1061 | return ($rs, '') if ($rs != 0); |
|---|
| 1062 | |
|---|
| 1063 | my $cgi_entry = undef; |
|---|
| 1064 | |
|---|
| 1065 | if ($dmn_cgi eq 'yes') { |
|---|
| 1066 | |
|---|
| 1067 | $cgi_entry = "$dmn_cgi_b$dmn_cgi_entry$dmn_cgi_e"; |
|---|
| 1068 | |
|---|
| 1069 | } else { |
|---|
| 1070 | |
|---|
| 1071 | $cgi_entry = "$dmn_cgi_b$dmn_cgi_e"; |
|---|
| 1072 | |
|---|
| 1073 | } |
|---|
| 1074 | |
|---|
| 1075 | ($rs, $dmn_entry) = repl_tag( |
|---|
| 1076 | $dmn_cgi_b, |
|---|
| 1077 | $dmn_cgi_e, |
|---|
| 1078 | $dmn_entry, |
|---|
| 1079 | $cgi_entry, |
|---|
| 1080 | "gen_httpd_dmn_group_entry" |
|---|
| 1081 | ); |
|---|
| 1082 | |
|---|
| 1083 | return ($rs, '') if ($rs != 0); |
|---|
| 1084 | |
|---|
| 1085 | my $php_entry = undef; |
|---|
| 1086 | |
|---|
| 1087 | if ($dmn_php eq 'no') { |
|---|
| 1088 | |
|---|
| 1089 | $php_entry = "$dmn_php_b$dmn_php_entry$dmn_php_e"; |
|---|
| 1090 | |
|---|
| 1091 | |
|---|
| 1092 | } else { |
|---|
| 1093 | |
|---|
| 1094 | $php_entry = "$dmn_php_b$dmn_php_e"; |
|---|
| 1095 | |
|---|
| 1096 | my $php2_entry = "$dmn_php2_b$dmn_php2_entry$dmn_php2_e"; |
|---|
| 1097 | |
|---|
| 1098 | ($rs, $dmn_entry) = repl_tag( |
|---|
| 1099 | $dmn_php2_b, |
|---|
| 1100 | $dmn_php2_e, |
|---|
| 1101 | $dmn_entry, |
|---|
| 1102 | $php2_entry, |
|---|
| 1103 | "gen_httpd_dmn_group_entry" |
|---|
| 1104 | ); |
|---|
| 1105 | |
|---|
| 1106 | return ($rs, '') if ($rs != 0); |
|---|
| 1107 | |
|---|
| 1108 | } |
|---|
| 1109 | |
|---|
| 1110 | ($rs, $dmn_entry) = repl_tag( |
|---|
| 1111 | $dmn_php_b, |
|---|
| 1112 | $dmn_php_e, |
|---|
| 1113 | $dmn_entry, |
|---|
| 1114 | $php_entry, |
|---|
| 1115 | "gen_httpd_dmn_group_entry" |
|---|
| 1116 | ); |
|---|
| 1117 | |
|---|
| 1118 | return ($rs, '') if ($rs != 0); |
|---|
| 1119 | |
|---|
| 1120 | push_el(\@main::el, 'gen_httpd_dmn_group_entry()', "dmn_entry:\n$dmn_entry"); |
|---|
| 1121 | |
|---|
| 1122 | my $dmn_group_entry = "$dmn_b$dmn_entry$dmn_e"; |
|---|
| 1123 | |
|---|
| 1124 | ($rs, $dg_entry) = repl_tag( |
|---|
| 1125 | $dmn_b, |
|---|
| 1126 | $dmn_e, |
|---|
| 1127 | $dg_entry, |
|---|
| 1128 | $dmn_group_entry, |
|---|
| 1129 | "gen_httpd_dmn_group_entry" |
|---|
| 1130 | ); |
|---|
| 1131 | |
|---|
| 1132 | # |
|---|
| 1133 | # Create mod_cband scoreboard for domain group |
|---|
| 1134 | # |
|---|
| 1135 | |
|---|
| 1136 | my $scoreboard_file = "$main::cfg{'SCOREBOARDS_DIR'}/$dmn_grp"; |
|---|
| 1137 | |
|---|
| 1138 | $rs = sys_command_rs("$main::cfg{'CMD_TOUCH'} $scoreboard_file"); |
|---|
| 1139 | |
|---|
| 1140 | return $rs if ($rs != 0); |
|---|
| 1141 | |
|---|
| 1142 | $rs = sys_command_rs("$main::cfg{'CMD_CHOWN'} $main::cfg{'APACHE_USER'}:$main::cfg{'APACHE_GROUP'} $scoreboard_file"); |
|---|
| 1143 | |
|---|
| 1144 | return $rs if ($rs != 0); |
|---|
| 1145 | |
|---|
| 1146 | # |
|---|
| 1147 | # Custom domain config file |
|---|
| 1148 | # |
|---|
| 1149 | |
|---|
| 1150 | if ( ! -e "$main::cfg{'APACHE_CUSTOM_SITES_CONFIG_DIR'}/$dmn_name.conf" ){ |
|---|
| 1151 | |
|---|
| 1152 | $rs = store_file("$main::cfg{'APACHE_CUSTOM_SITES_CONFIG_DIR'}/$dmn_name.conf", $dmn_custom, $main::cfg{'ROOT_USER'}, $main::cfg{'ROOT_GROUP'}, 0644); |
|---|
| 1153 | |
|---|
| 1154 | return $rs if ($rs != 0); |
|---|
| 1155 | } |
|---|
| 1156 | |
|---|
| 1157 | push_el(\@main::el, 'gen_httpd_dmn_group_entry()', "\n$dg_entry"); |
|---|
| 1158 | |
|---|
| 1159 | return (0, $dg_entry); |
|---|
| 1160 | |
|---|
| 1161 | } |
|---|
| 1162 | |
|---|
| 1163 | ################################################################################ |
|---|
| 1164 | ## |
|---|
| 1165 | ## Add HTTPd CFG Data |
|---|
| 1166 | ## |
|---|
| 1167 | |
|---|
| 1168 | sub dmn_add_httpd_cfg_data { |
|---|
| 1169 | |
|---|
| 1170 | my ($dmn_data) = @_; |
|---|
| 1171 | |
|---|
| 1172 | my ($rs, $rdata) = (undef, undef); |
|---|
| 1173 | |
|---|
| 1174 | push_el(\@main::el, 'dmn_add_httpd_cfg_data()', 'Starting...'); |
|---|
| 1175 | |
|---|
| 1176 | if (!defined($dmn_data) || $dmn_data eq '') { |
|---|
| 1177 | |
|---|
| 1178 | push_el(\@main::el, 'dmn_add_httpd_cfg_data()', 'ERROR: Undefined Input Data...'); |
|---|
| 1179 | |
|---|
| 1180 | return -1; |
|---|
| 1181 | |
|---|
| 1182 | } |
|---|
| 1183 | |
|---|
| 1184 | my $dmn_name = @$dmn_data[1]; |
|---|
| 1185 | |
|---|
| 1186 | my $dmn_grp = $dmn_name; |
|---|
| 1187 | |
|---|
| 1188 | my $dmn_id = @$dmn_data[0]; |
|---|
| 1189 | |
|---|
| 1190 | my $dmn_ip = @$dmn_data[21]; |
|---|
| 1191 | |
|---|
| 1192 | |
|---|
| 1193 | my $conf_dir = $main::cfg{'CONF_DIR'}; |
|---|
| 1194 | |
|---|
| 1195 | |
|---|
| 1196 | my $tpl_dir = "$conf_dir/apache/parts"; |
|---|
| 1197 | |
|---|
| 1198 | my $working_dir = "$conf_dir/apache/working"; |
|---|
| 1199 | |
|---|
| 1200 | my $backup_dir = "$conf_dir/apache/backup"; |
|---|
| 1201 | |
|---|
| 1202 | |
|---|
| 1203 | my $sys_cfg = "$main::cfg{'APACHE_SITES_DIR'}/ispcp.conf"; |
|---|
| 1204 | |
|---|
| 1205 | my $working_cfg = "$working_dir/ispcp.conf"; |
|---|
| 1206 | |
|---|
| 1207 | |
|---|
| 1208 | if (!(-e $working_cfg)) { |
|---|
| 1209 | |
|---|
| 1210 | my $ispcp_base_tpl; |
|---|
| 1211 | |
|---|
| 1212 | ($rs, $ispcp_base_tpl) = get_file($tpl_dir."/ispcp_base.tpl"); |
|---|
| 1213 | |
|---|
| 1214 | return $rs if ($rs != 0); |
|---|
| 1215 | |
|---|
| 1216 | ($rs, $rdata) = store_file( |
|---|
| 1217 | $working_cfg, |
|---|
| 1218 | $ispcp_base_tpl, |
|---|
| 1219 | "root", |
|---|
| 1220 | "root", |
|---|
| 1221 | 0600 |
|---|
| 1222 | ); |
|---|
| 1223 | |
|---|
| 1224 | return $rs if ($rs != 0); |
|---|
| 1225 | |
|---|
| 1226 | } |
|---|
| 1227 | |
|---|
| 1228 | |
|---|
| 1229 | my $timestamp = time; |
|---|
| 1230 | |
|---|
| 1231 | my $backup_cfg = "$backup_dir/httpd.conf.$timestamp"; |
|---|
| 1232 | |
|---|
| 1233 | # |
|---|
| 1234 | # Getting needed templates; |
|---|
| 1235 | # |
|---|
| 1236 | |
|---|
| 1237 | my ( |
|---|
| 1238 | $cfg_b, |
|---|
| 1239 | $cfg_e, |
|---|
| 1240 | $vh_b, |
|---|
| 1241 | $vh_entry, |
|---|
| 1242 | $vh_e, |
|---|
| 1243 | $dg_b, |
|---|
| 1244 | $dg_e |
|---|
| 1245 | ) = ('', '', '', '', '', '', ''); |
|---|
| 1246 | |
|---|
| 1247 | ( |
|---|
| 1248 | $rs, |
|---|
| 1249 | $cfg_b, |
|---|
| 1250 | $cfg_e, |
|---|
| 1251 | $vh_b, |
|---|
| 1252 | $vh_entry, |
|---|
| 1253 | $vh_e, |
|---|
| 1254 | $dg_b, |
|---|
| 1255 | $dg_e |
|---|
| 1256 | ) = get_tpl ( |
|---|
| 1257 | $tpl_dir, |
|---|
| 1258 | 'cfg_b.tpl', |
|---|
| 1259 | 'cfg_e.tpl', |
|---|
| 1260 | 'vh_b.tpl', |
|---|
| 1261 | 'vh_entry.tpl', |
|---|
| 1262 | 'vh_e.tpl', |
|---|
| 1263 | 'dg_b.tpl', |
|---|
| 1264 | 'dg_e.tpl' |
|---|
| 1265 | ); |
|---|
| 1266 | |
|---|
| 1267 | return $rs if ($rs != 0); |
|---|
| 1268 | |
|---|
| 1269 | |
|---|
| 1270 | # |
|---|
| 1271 | # Create apache suexec user for this domain. |
|---|
| 1272 | # |
|---|
| 1273 | |
|---|
| 1274 | $rs = add_dmn_suexec_user($dmn_data); |
|---|
| 1275 | |
|---|
| 1276 | return $rs if ($rs != 0); |
|---|
| 1277 | |
|---|
| 1278 | # |
|---|
| 1279 | # Preparing templates; |
|---|
| 1280 | # |
|---|
| 1281 | |
|---|
| 1282 | my ( |
|---|
| 1283 | $vh_b_val, |
|---|
| 1284 | $vh_entry_val, |
|---|
| 1285 | $vh_e_val, |
|---|
| 1286 | $dg_b_val, |
|---|
| 1287 | $dg_e_val |
|---|
| 1288 | ) = ('', '', '', '', ''); |
|---|
| 1289 | |
|---|
| 1290 | my %tag_hash = ('{IP}' => $dmn_ip); |
|---|
| 1291 | |
|---|
| 1292 | ($rs, $vh_entry_val) = prep_tpl (\%tag_hash, $vh_entry); |
|---|
| 1293 | |
|---|
| 1294 | return $rs if ($rs != 0); |
|---|
| 1295 | |
|---|
| 1296 | %tag_hash = ( |
|---|
| 1297 | '{IP}' => $dmn_ip, |
|---|
| 1298 | '{DMN_GRP}' => $dmn_grp |
|---|
| 1299 | ); |
|---|
| 1300 | |
|---|
| 1301 | ( |
|---|
| 1302 | $rs, |
|---|
| 1303 | $vh_b_val, |
|---|
| 1304 | $vh_e_val, |
|---|
| 1305 | $dg_b_val, |
|---|
| 1306 | $dg_e_val |
|---|
| 1307 | ) = prep_tpl ( |
|---|
| 1308 | \%tag_hash, |
|---|
| 1309 | $vh_b, |
|---|
| 1310 | $vh_e, |
|---|
| 1311 | $dg_b, |
|---|
| 1312 | $dg_e |
|---|
| 1313 | ); |
|---|
| 1314 | |
|---|
| 1315 | return $rs if ($rs != 0); |
|---|
| 1316 | |
|---|
| 1317 | # |
|---|
| 1318 | # Let's get some configs; |
|---|
| 1319 | # |
|---|
| 1320 | |
|---|
| 1321 | my ($sys, $working) = ('', ''); |
|---|
| 1322 | |
|---|
| 1323 | |
|---|
| 1324 | ($rs, $sys) = get_file($sys_cfg); |
|---|
| 1325 | |
|---|
| 1326 | return $rs if ($rs != 0); |
|---|
| 1327 | |
|---|
| 1328 | |
|---|
| 1329 | ($rs, $working) = get_file($working_cfg); |
|---|
| 1330 | |
|---|
| 1331 | return $rs if ($rs != 0); |
|---|
| 1332 | |
|---|
| 1333 | # |
|---|
| 1334 | # Check for $cfg_b, $cfg_e in working config; |
|---|
| 1335 | # |
|---|
| 1336 | |
|---|
| 1337 | ($rs, $rdata) = get_tag($cfg_b, $cfg_e, $working); |
|---|
| 1338 | |
|---|
| 1339 | return $rs if ($rs != 0); |
|---|
| 1340 | |
|---|
| 1341 | # |
|---|
| 1342 | # Check for $vh_b_val, $vh_e_val in working config; Have we such Virtual Host Entry in working config; |
|---|
| 1343 | # |
|---|
| 1344 | |
|---|
| 1345 | ($rs, $rdata) = get_tag($vh_b_val, $vh_e_val, $working); |
|---|
| 1346 | |
|---|
| 1347 | if ($rs == -5) { # No, we have not! We must add it here ! |
|---|
| 1348 | |
|---|
| 1349 | my $repl = undef; |
|---|
| 1350 | |
|---|
| 1351 | $repl = "$vh_b_val$vh_entry_val$vh_e_val\n"; |
|---|
| 1352 | |
|---|
| 1353 | $repl .= "$vh_b$vh_e"; |
|---|
| 1354 | |
|---|
| 1355 | ($rs, $working) = repl_tag( |
|---|
| 1356 | $vh_b, |
|---|
| 1357 | $vh_e, |
|---|
| 1358 | $working, |
|---|
| 1359 | $repl, |
|---|
| 1360 | "dmn_add_httpd_cfg_data" |
|---|
| 1361 | ); |
|---|
| 1362 | |
|---|
| 1363 | return $rs if ($rs != 0); |
|---|
| 1364 | |
|---|
| 1365 | ($rs, $rdata) = get_tag($vh_b_val, $vh_e_val, $working); |
|---|
| 1366 | |
|---|
| 1367 | return $rs if ($rs != 0); |
|---|
| 1368 | |
|---|
| 1369 | push_el(\@main::el, 'dmn_add_httpd_cfg_data()', "working:\n$working"); |
|---|
| 1370 | |
|---|
| 1371 | } elsif ($rs != 0) { |
|---|
| 1372 | |
|---|
| 1373 | return $rs; |
|---|
| 1374 | |
|---|
| 1375 | } |
|---|
| 1376 | |
|---|
| 1377 | # |
|---|
| 1378 | # Let's edit Virtual Host Entry; |
|---|
| 1379 | # |
|---|
| 1380 | |
|---|
| 1381 | my $vh_entry_contents = $rdata; |
|---|
| 1382 | |
|---|
| 1383 | # |
|---|
| 1384 | # Check for valued Domain Group Entry in this Virtual Host Entry; |
|---|
| 1385 | # |
|---|
| 1386 | |
|---|
| 1387 | ($rs, $rdata) = get_tag( |
|---|
| 1388 | $dg_b_val, |
|---|
| 1389 | $dg_e_val, |
|---|
| 1390 | $vh_entry_contents |
|---|
| 1391 | ); |
|---|
| 1392 | |
|---|
| 1393 | if ($rs == 0) { |
|---|
| 1394 | |
|---|
| 1395 | |
|---|
| 1396 | # We have one ! We must delete it because of possible future changes in this Domain Group Entry; |
|---|
| 1397 | |
|---|
| 1398 | |
|---|
| 1399 | ($rs, $vh_entry_contents) = del_tag( |
|---|
| 1400 | $dg_b_val, |
|---|
| 1401 | "$dg_e_val\n", |
|---|
| 1402 | $vh_entry_contents |
|---|
| 1403 | ); |
|---|
| 1404 | |
|---|
| 1405 | return $rs if ($rs != 0); |
|---|
| 1406 | |
|---|
| 1407 | } |
|---|
| 1408 | |
|---|
| 1409 | # |
|---|
| 1410 | # Check for extension ($dg_b, $dg_e) Domain Group Entry in this Virtual Host Entry; |
|---|
| 1411 | # |
|---|
| 1412 | |
|---|
| 1413 | ($rs, $rdata) = get_tag($dg_b, $dg_e, $vh_entry_contents); |
|---|
| 1414 | |
|---|
| 1415 | return $rs if ($rs != 0); |
|---|
| 1416 | |
|---|
| 1417 | # |
|---|
| 1418 | # Let's construct Domain Group Entry and Domain Group valued (with extension tags) Entry; |
|---|
| 1419 | # |
|---|
| 1420 | |
|---|
| 1421 | my ($dg_entry, $dg_entry_val) = ('', ''); |
|---|
| 1422 | |
|---|
| 1423 | |
|---|
| 1424 | ($rs, $dg_entry) = gen_httpd_dmn_group_entry($dmn_data); |
|---|
| 1425 | |
|---|
| 1426 | return $rs if ($rs != 0); |
|---|
| 1427 | |
|---|
| 1428 | $dg_entry_val = "$dg_b$dg_e"; |
|---|
| 1429 | |
|---|
| 1430 | $dg_entry_val .= "$dg_b_val$dg_entry$dg_e_val\n"; |
|---|
| 1431 | |
|---|
| 1432 | # |
|---|
| 1433 | # Constructing NEW Virtual Host Entry; |
|---|
| 1434 | # |
|---|
| 1435 | |
|---|
| 1436 | ($rs, $vh_entry_contents) = repl_tag($dg_b, $dg_e, $vh_entry_contents, $dg_entry_val, "dmn_add_httpd_cfg_data"); |
|---|
| 1437 | |
|---|
| 1438 | return $rs if ($rs != 0); |
|---|
| 1439 | |
|---|
| 1440 | # |
|---|
| 1441 | # Putting NEW Virtual Host Entry in working config; |
|---|
| 1442 | # |
|---|
| 1443 | |
|---|
| 1444 | ($rs, $working) = repl_tag( |
|---|
| 1445 | $vh_b_val, |
|---|
| 1446 | $vh_e_val, |
|---|